diff --git a/brmbar3/brmbar/Shop.py b/brmbar3/brmbar/Shop.py index 4100592..4c32973 100644 --- a/brmbar3/brmbar/Shop.py +++ b/brmbar3/brmbar/Shop.py @@ -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)"""