Use inventory_balance.

This commit is contained in:
Dominik Pantůček 2025-07-21 16:56:50 +02:00
parent 2e328e4fb3
commit 39fe8d97fd

View file

@ -185,31 +185,11 @@ class Shop:
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):
balance = 0
# Each inventory account has its own currency,
# so we just do this ugly iteration
cur = self.db.execute_and_fetchall(
"SELECT id FROM accounts WHERE acctype = %s", ["inventory"]
)
for inventory in cur:
invid = inventory[0]
inv = Account.load(self.db, id=invid)
# FIXME: This is not correct as each instance of inventory
# might have been bought for a different price! Therefore,
# we need to replace the command below with a complex SQL
# statement that will... ugh, accounting is hard!
b = inv.balance() * inv.currency.rates(self.currency)[0]
# if b != 0:
# print(str(b) + ',' + inv.name)
balance += b
return balance
return self.db.execute_and_fetch("SELECT public.inventory_balance()")
# XXX bypass hack
def inventory_balance_str(self):
# return self.currency.str(self.inventory_balance())
return "XXX"
return self.currency.str(self.inventory_balance())
def account_list(self, acctype, like_str="%%"):
"""list all accounts (people or items, as per acctype)"""