mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-07 21:04:00 +02:00
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
|
||||
- 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
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue