brmbar-cli stats: Separate credit and overflow

This commit is contained in:
brmbar 2016-01-07 05:06:37 +01:00
parent 9a70088591
commit 2bfd1796d0
2 changed files with 8 additions and 5 deletions

View file

@ -162,9 +162,10 @@ elif sys.argv[1] == "listitems":
elif sys.argv[1] == "stats":
print("Cash: {}".format(shop.cash.balance_str()))
print("Profit: {}".format(shop.profits.balance_str()))
print("Credit: {}".format(shop.credit_negbalance_str()))
print("Overflow: {}".format(shop.currency.str(shop.credit_balance(overflow='only'))))
print("Inventory: {}".format(shop.inventory_balance_str()))
print("Credit: {}".format(shop.credit_negbalance_str(overflow='exclude')))
print("Profit: {}".format(shop.profits.balance_str()))
print("Excess: {}".format(shop.excess.negbalance_str()))
print("Deficit: {}".format(shop.deficit.balance_str()))

View file

@ -106,7 +106,7 @@ class Shop:
transaction = transaction[0]
return transaction
def credit_balance(self):
def credit_balance(self, overflow=None):
# We assume all debt accounts share a currency
sumselect = """
SELECT SUM(ts.amount)
@ -114,13 +114,15 @@ class Shop:
LEFT JOIN transaction_splits AS ts ON a.id = ts.account
WHERE a.acctype = %s AND ts.side = %s
"""
if overflow is not None:
sumselect += ' AND a.name ' + ('NOT ' if overflow == 'exclude' else '') + ' LIKE \'%%-overflow\''
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
def credit_negbalance_str(self):
return self.currency.str(-self.credit_balance())
def credit_negbalance_str(self, overflow=None):
return self.currency.str(-self.credit_balance(overflow=overflow))
# XXX causing extra heavy delay ( thousands of extra SQL queries ), disabled
def inventory_balance(self):