#15: stored function for cash-based stock replenishment transaction

This commit is contained in:
TMA 2025-04-21 18:23:11 +02:00
parent ad832fc71b
commit 629b35655d
2 changed files with 91 additions and 5 deletions

View file

@ -119,13 +119,17 @@ class Shop:
#self.withdraw_credit(amount, userfrom)
def buy_for_cash(self, item, amount = 1):
cost = self.db.execute_and_fetch(
"SELECT public.buy_for_cash(%s, %s, %s, %s, %s)",
[self.cash.id, item.id, amount, self.currency.id, item.name]
)[0]
# Buy: Currency conversion from item currency to shop currency
(buy, sell) = item.currency.rates(self.currency)
cost = amount * buy
#(buy, sell) = item.currency.rates(self.currency)
#cost = amount * buy
transaction = self._transaction(description = "BrmBar stock replenishment of {}x {} for cash".format(amount, item.name))
item.debit(transaction, amount, "Cash")
self.cash.credit(transaction, cost, item.name)
#transaction = self._transaction(description = "BrmBar stock replenishment of {}x {} for cash".format(amount, item.name))
#item.debit(transaction, amount, "Cash")
#self.cash.credit(transaction, cost, item.name)
self.db.commit()
return cost