From 6e7cdf0badac558ddf0bbb59022a6724b59c4d4d Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Fri, 28 Sep 2012 22:37:02 +0200 Subject: [PATCH] brmbar.Shop.buy_for_cash(): New method for stock replenishment from the money box --- brmbar3/TODO | 1 + brmbar3/brmbar/Shop.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) 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",