mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-09 22:04:01 +02:00
#19: stored function for "consolidation" transaction
This commit is contained in:
parent
aad79dafa6
commit
96027ca66a
3 changed files with 124 additions and 17 deletions
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue