#19: stored function for "consolidation" transaction

This commit is contained in:
TMA 2025-04-21 19:49:07 +02:00
parent aad79dafa6
commit 96027ca66a
3 changed files with 124 additions and 17 deletions

View file

@ -46,11 +46,16 @@ class Account:
return cls(db, name = name, id = id, currency = currency, acctype = acctype)
def balance(self):
debit = self.db.execute_and_fetch("SELECT SUM(amount) FROM transaction_splits WHERE account = %s AND side = %s", [self.id, 'debit'])
debit = debit[0] or 0
credit = self.db.execute_and_fetch("SELECT SUM(amount) FROM transaction_splits WHERE account = %s AND side = %s", [self.id, 'credit'])
credit = credit[0] or 0
return debit - credit
bal = self.db.execute_and_fetch(
"SELECT public.compute_account_balance(%s)",
[self.id]
)[0]
return bal
#debit = self.db.execute_and_fetch("SELECT SUM(amount) FROM transaction_splits WHERE account = %s AND side = %s", [self.id, 'debit'])
#debit = debit[0] or 0
#credit = self.db.execute_and_fetch("SELECT SUM(amount) FROM transaction_splits WHERE account = %s AND side = %s", [self.id, 'credit'])
#credit = credit[0] or 0
#return debit - credit
def balance_str(self):
return self.currency.str(self.balance())