Added caching of credit balance to accounts and replacing view account_balances.

This commit is contained in:
niekt0 2015-01-31 02:39:07 +01:00
parent 4604cd36c3
commit 15bb03e5fe
3 changed files with 21 additions and 21 deletions

View file

@ -105,16 +105,12 @@ class Shop:
def credit_balance(self):
# We assume all debt accounts share a currency
sumselect = """
SELECT SUM(ts.amount)
FROM accounts AS a
LEFT JOIN transaction_splits AS ts ON a.id = ts.account
WHERE a.acctype = %s AND ts.side = %s
SELECT SUM(crbalance)
FROM accounts WHERE acctype = %s AND
"""
cur = self.db.execute_and_fetch(sumselect, ["debt", 'debit'])
debit = cur[0] or 0
credit = self.db.execute_and_fetch(sumselect, ["debt", 'credit'])
credit = credit[0] or 0
return debit - credit
cur = self.db.execute_and_fetch(sumselect, ["debt"])
cur = cur[0] or 0
return cur
def credit_negbalance_str(self):
return self.currency.str(-self.credit_balance())