From eda6eaf9e40ce5c51387ea481bfd9081dbc6c499 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 24 Sep 2012 04:39:30 +0200 Subject: [PATCH] brmbar.Shop.withdraw_credit(): New method analogous to add_credit() --- brmbar3/brmbar/Shop.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/brmbar3/brmbar/Shop.py b/brmbar3/brmbar/Shop.py index 2716a11..8a05313 100644 --- a/brmbar3/brmbar/Shop.py +++ b/brmbar3/brmbar/Shop.py @@ -57,6 +57,12 @@ class Shop: user.credit(transaction, credit, "Credit replenishment") self.db.commit() + def withdraw_credit(self, credit, user): + transaction = self._transaction(responsible = user, description = "BrmBar credit withdrawal for " + user.name) + self.cash.credit(transaction, credit, user.name) + user.debit(transaction, credit, "Credit withdrawal") + self.db.commit() + 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",