forked from brmlab/brmbar-github
brmbar-cli undo: New feature
This commit is contained in:
parent
feec2c9ac4
commit
3ea61f01d7
2 changed files with 22 additions and 0 deletions
|
@ -31,6 +31,9 @@ Usage: brmbar-cli.py COMMAND ARGS...
|
|||
screen of the GUI.
|
||||
adduser USER
|
||||
Add user (debt) account with given username.
|
||||
undo TRANSID
|
||||
Commit a transaction that reverses all splits of a transaction with
|
||||
a given id (to find out that id: select * from transaction_cashsums;)
|
||||
|
||||
3. Inventorization
|
||||
|
||||
|
@ -152,6 +155,10 @@ elif sys.argv[1] == "adduser":
|
|||
acct.add_barcode(sys.argv[2]) # will commit
|
||||
print("{}: id {}".format(acct.name, acct.id));
|
||||
|
||||
elif sys.argv[1] == "undo":
|
||||
newtid = shop.undo(int(sys.argv[2]))
|
||||
print("Transaction %d undone by reverse transaction %d" % (int(sys.argv[2]), newtid))
|
||||
|
||||
elif sys.argv[1] == "inventory":
|
||||
if (len(sys.argv) % 2 != 0 or len(sys.argv) < 4):
|
||||
print ("Invalid number of parameters, count your parameters.")
|
||||
|
|
|
@ -177,6 +177,7 @@ class Shop:
|
|||
item.credit(transaction, 0, "Inventory fix - amount was correct")
|
||||
self.db.commit()
|
||||
return False
|
||||
|
||||
def fix_cash(self, amount):
|
||||
amount_in_reality = amount
|
||||
amount_in_system = self.cash.balance()
|
||||
|
@ -196,6 +197,7 @@ class Shop:
|
|||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def consolidate(self):
|
||||
transaction = self._transaction(description = "BrmBar inventory consolidation")
|
||||
|
||||
|
@ -210,3 +212,16 @@ class Shop:
|
|||
self.deficit.credit(transaction, deficit_balance, "Deficit balance removed from profit.")
|
||||
self.profits.credit(transaction, deficit_balance, "Deficit balance removed from profit.")
|
||||
self.db.commit()
|
||||
|
||||
def undo(self, oldtid):
|
||||
description = self.db.execute_and_fetch("SELECT description FROM transactions WHERE id = %s", [oldtid])[0]
|
||||
description = 'undo %d (%s)' % (oldtid, description)
|
||||
|
||||
transaction = self._transaction(description=description)
|
||||
for split in self.db.execute_and_fetchall("SELECT id, side, account, amount, memo FROM transaction_splits WHERE transaction = %s", [oldtid]):
|
||||
splitid, side, account, amount, memo = split
|
||||
memo = 'undo %d (%s)' % (splitid, memo)
|
||||
amount = -amount
|
||||
self.db.execute("INSERT INTO transaction_splits (transaction, side, account, amount, memo) VALUES (%s, %s, %s, %s, %s)", [transaction, side, account, amount, memo])
|
||||
self.db.commit()
|
||||
return transaction
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue