diff --git a/brmbar3/brmbar/Account.py b/brmbar3/brmbar/Account.py index d474e6c..3186dcc 100644 --- a/brmbar3/brmbar/Account.py +++ b/brmbar3/brmbar/Account.py @@ -45,7 +45,7 @@ class Account: return cls(db, name = name, id = id, currency = currency, acctype = acctype) def balance(self): - crbalance = self.db.execute_and_fetch("SELECT crbalance FROM accounts WHERE account = %s", [self.id]) + crbalance = self.db.execute_and_fetch("SELECT crbalance FROM accounts WHERE id = %s", [self.id]) crbalance = crbalance[0] or 0 return crbalance @@ -66,7 +66,7 @@ class Account: """ Common part of credit() and debit(). """ self.db.execute("INSERT INTO transaction_splits (transaction, side, account, amount, memo) VALUES (%s, %s, %s, %s, %s)", [transaction, side, self.id, amount, memo]) - self.db.execute("UPDATE accounts set crbalance = crbalance - (CASE WHEN %s = 'credit' THEN -amount ELSE amount END)", [side]) + self.db.execute("UPDATE accounts set crbalance = crbalance + (CASE WHEN %s = 'credit' THEN -amount ELSE amount END)", [side]) def add_barcode(self, barcode): self.db.execute("INSERT INTO barcodes (account, barcode) VALUES (%s, %s)", [self.id, barcode]) diff --git a/brmbar3/brmbar/Shop.py b/brmbar3/brmbar/Shop.py index a170fcd..b5c61dc 100644 --- a/brmbar3/brmbar/Shop.py +++ b/brmbar3/brmbar/Shop.py @@ -106,7 +106,7 @@ class Shop: # We assume all debt accounts share a currency sumselect = """ SELECT SUM(crbalance) - FROM accounts WHERE acctype = %s AND + FROM accounts WHERE acctype = %s """ cur = self.db.execute_and_fetch(sumselect, ["debt"]) cur = cur[0] or 0