mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-10 22:34:11 +02:00
#18: stored function for "fixing cash" transaction
This commit is contained in:
parent
c21b394b42
commit
f0058aad68
2 changed files with 84 additions and 17 deletions
|
@ -235,24 +235,31 @@ class Shop:
|
|||
# return False
|
||||
|
||||
def fix_cash(self, amount):
|
||||
amount_in_reality = amount
|
||||
amount_in_system = self.cash.balance()
|
||||
rv = self.db.execute_and_fetch(
|
||||
"SELECT public.fix_cash(%s, %s, %s, %s)",
|
||||
[self.excess.id, self.deficit.id, self.currency.id, amount]
|
||||
)[0]
|
||||
|
||||
diff = abs(amount_in_reality - amount_in_system)
|
||||
if amount_in_reality > amount_in_system:
|
||||
transaction = self._transaction(description = "BrmBar cash inventory fix of {} in system to {} in reality".format(amount_in_system, amount_in_reality))
|
||||
self.cash.debit(transaction, diff, "Inventory fix excess")
|
||||
self.excess.credit(transaction, diff, "Inventory cash fix excess.")
|
||||
self.db.commit()
|
||||
return True
|
||||
elif amount_in_reality < amount_in_system:
|
||||
transaction = self._transaction(description = "BrmBar cash inventory fix of {} in system to {} in reality".format(amount_in_system, amount_in_reality))
|
||||
self.cash.credit(transaction, diff, "Inventory fix deficit")
|
||||
self.deficit.debit(transaction, diff, "Inventory fix deficit.")
|
||||
self.db.commit()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
self.db.commit()
|
||||
return rv
|
||||
#amount_in_reality = amount
|
||||
#amount_in_system = self.cash.balance()
|
||||
|
||||
#diff = abs(amount_in_reality - amount_in_system)
|
||||
#if amount_in_reality > amount_in_system:
|
||||
# transaction = self._transaction(description = "BrmBar cash inventory fix of {} in system to {} in reality".format(amount_in_system, amount_in_reality))
|
||||
# self.cash.debit(transaction, diff, "Inventory fix excess")
|
||||
# self.excess.credit(transaction, diff, "Inventory cash fix excess.")
|
||||
# self.db.commit()
|
||||
# return True
|
||||
#elif amount_in_reality < amount_in_system:
|
||||
# transaction = self._transaction(description = "BrmBar cash inventory fix of {} in system to {} in reality".format(amount_in_system, amount_in_reality))
|
||||
# self.cash.credit(transaction, diff, "Inventory fix deficit")
|
||||
# self.deficit.debit(transaction, diff, "Inventory fix deficit.")
|
||||
# self.db.commit()
|
||||
# return True
|
||||
#else:
|
||||
# return False
|
||||
|
||||
def consolidate(self):
|
||||
msg = self.db.execute_and_fetch(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue