brmbar.Shop.buy_for_cash(): New method for stock replenishment from the money box

This commit is contained in:
Petr Baudis 2012-09-28 22:37:02 +02:00
parent fedd1ecd50
commit 6e7cdf0bad
2 changed files with 13 additions and 0 deletions

View file

@ -29,6 +29,7 @@
- Forbid negative credit
- Stock management
- Group quantity changes in a single transaction (for single receipt, many stock)
- Support for directly paying for stocked items from user credit
- Statistics
- Users with debt
- Pretty chart

View file

@ -63,6 +63,18 @@ class Shop:
user.debit(transaction, credit, "Credit withdrawal")
self.db.commit()
def buy_for_cash(self, item, amount = 1):
# Buy: Currency conversion from item currency to shop currency
(buy, sell) = item.currency.rates(self.currency)
cost = amount * buy
transaction = self._transaction(description = "BrmBar stock replenishment of {}x {} for cash".format(amount, item.name))
item.debit(transaction, amount, "Cash")
self.cash.credit(transaction, cost, item.name)
self.db.commit()
return cost
def _transaction(self, responsible = None, description = None):
with closing(self.db.cursor()) as cur:
cur.execute("INSERT INTO transactions (responsible, description) VALUES (%s, %s) RETURNING id",