brmbar.Shop.receipt_to_credit(): New method for converting receipts to credit

This commit is contained in:
Petr Baudis 2012-09-29 00:22:32 +02:00
parent 325033231b
commit 9c1c8d381b

View file

@ -75,6 +75,12 @@ class Shop:
return cost
def receipt_to_credit(self, user, credit, description):
transaction = self._transaction(responsible = user, description = "Receipt: " + description)
self.profits.credit(transaction, credit, user.name)
user.credit(transaction, credit, "Credit from receipt: " + description)
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",