From 39fe8d97fdab56ab8e0ec3c6253bc9c10a40d4f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Mon, 21 Jul 2025 16:56:50 +0200 Subject: [PATCH] Use inventory_balance. --- brmbar3/brmbar/Shop.py | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) 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)"""