diff --git a/brmbar3/TODO b/brmbar3/TODO index 21c8b57..0fb1e8f 100644 --- a/brmbar3/TODO +++ b/brmbar3/TODO @@ -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 diff --git a/brmbar3/brmbar/Shop.py b/brmbar3/brmbar/Shop.py index 6087b66..f57e4c6 100644 --- a/brmbar3/brmbar/Shop.py +++ b/brmbar3/brmbar/Shop.py @@ -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",