forked from brmlab/brmbar-github
brmbar.Shop.buy_for_cash(): New method for stock replenishment from the money box
This commit is contained in:
parent
fedd1ecd50
commit
6e7cdf0bad
2 changed files with 13 additions and 0 deletions
|
@ -29,6 +29,7 @@
|
||||||
- Forbid negative credit
|
- Forbid negative credit
|
||||||
- Stock management
|
- Stock management
|
||||||
- Group quantity changes in a single transaction (for single receipt, many stock)
|
- Group quantity changes in a single transaction (for single receipt, many stock)
|
||||||
|
- Support for directly paying for stocked items from user credit
|
||||||
- Statistics
|
- Statistics
|
||||||
- Users with debt
|
- Users with debt
|
||||||
- Pretty chart
|
- Pretty chart
|
||||||
|
|
|
@ -63,6 +63,18 @@ class Shop:
|
||||||
user.debit(transaction, credit, "Credit withdrawal")
|
user.debit(transaction, credit, "Credit withdrawal")
|
||||||
self.db.commit()
|
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):
|
def _transaction(self, responsible = None, description = None):
|
||||||
with closing(self.db.cursor()) as cur:
|
with closing(self.db.cursor()) as cur:
|
||||||
cur.execute("INSERT INTO transactions (responsible, description) VALUES (%s, %s) RETURNING id",
|
cur.execute("INSERT INTO transactions (responsible, description) VALUES (%s, %s) RETURNING id",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue