forked from brmlab/brmbar-github
		
	Added logic for fixing inventory status
This commit is contained in:
		
							parent
							
								
									32f76b290c
								
							
						
					
					
						commit
						0706054e81
					
				
					 3 changed files with 39 additions and 19 deletions
				
			
		|  | @ -41,6 +41,8 @@ CREATE TABLE accounts ( | ||||||
| ); | ); | ||||||
| INSERT INTO accounts (name, currency, acctype) VALUES ('BrmBar Cash', (SELECT id FROM currencies WHERE name='Kč'), 'cash'); | INSERT INTO accounts (name, currency, acctype) VALUES ('BrmBar Cash', (SELECT id FROM currencies WHERE name='Kč'), 'cash'); | ||||||
| INSERT INTO accounts (name, currency, acctype) VALUES ('BrmBar Profits', (SELECT id FROM currencies WHERE name='Kč'), 'income'); | INSERT INTO accounts (name, currency, acctype) VALUES ('BrmBar Profits', (SELECT id FROM currencies WHERE name='Kč'), 'income'); | ||||||
|  | INSERT INTO accounts (name, currency, acctype) VALUES ('BrmBar Excess', (SELECT id FROM currencies WHERE name='Kč'), 'income'); | ||||||
|  | INSERT INTO accounts (name, currency, acctype) VALUES ('BrmBar Deficit', (SELECT id FROM currencies WHERE name='Kč'), 'expense'); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| CREATE SEQUENCE barcodes_id_seq START WITH 1 INCREMENT BY 1; | CREATE SEQUENCE barcodes_id_seq START WITH 1 INCREMENT BY 1; | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ import brmbar | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def help(): | def help(): | ||||||
|     print("""BrmBar v3 (c) Petr Baudis <pasky@ucw.cz> 2012 |     print("""BrmBar v3 (c) Petr Baudis <pasky@ucw.cz> 2012-2013 | ||||||
| 
 | 
 | ||||||
| Usage: brmbar-cli.py COMMAND ARGS... | Usage: brmbar-cli.py COMMAND ARGS... | ||||||
| 
 | 
 | ||||||
|  | @ -30,22 +30,8 @@ Usage: brmbar-cli.py COMMAND ARGS... | ||||||
| 		screen of the GUI. | 		screen of the GUI. | ||||||
| 	adduser USER | 	adduser USER | ||||||
| 		Add user (debt) account with given username. | 		Add user (debt) account with given username. | ||||||
| !   inventory ITEM1 NEW_AMOUNT1 ITEM2 NEW_AMOUNT2 ... |     inventory NEW_AMOUNT1 ITEM1 NEW_AMOUNT2 ITEM2 | ||||||
|     Create a special inventory recounting |         Inventory recounting (fixing the number of items) | ||||||
| 
 |  | ||||||
|     mensi pocet [item] == prevedu na ucet manko (deficiency) BEZ marginu |  | ||||||
|     vetsi pocet [item] == prevedu z uctu primnozky (excess) |  | ||||||
|     stejny pocet [item] == prazdny prevod mezi item a item |  | ||||||
| 		Create a custom transaction that will change balance |  | ||||||
| 		of a variety of items at once, and either deduce |  | ||||||
| 		buy price (+amt) or add sell price (-amt) to the |  | ||||||
| 		cash balance for all of these items. This is useful |  | ||||||
| 		e.g. after events where stock is sold offline or when |  | ||||||
| 		doing an inventory recount. |  | ||||||
| 		If cash balance discrepancy is discovered as well |  | ||||||
| 		during the inventory recounting, first do changestock, |  | ||||||
| 		then compare actual and nominal cash balance again, |  | ||||||
| 		then issue changecash command if necessary. |  | ||||||
| !	changecash +-AMT | !	changecash +-AMT | ||||||
| 		Create a custom transaction that updates nominal cash | 		Create a custom transaction that updates nominal cash | ||||||
| 		balance based on the actual cash balance counted | 		balance based on the actual cash balance counted | ||||||
|  | @ -159,5 +145,15 @@ elif sys.argv[1] == "adduser": | ||||||
|     acct.add_barcode(sys.argv[2]) # will commit |     acct.add_barcode(sys.argv[2]) # will commit | ||||||
|     print("{}: id {}".format(acct.name, acct.id)); |     print("{}: id {}".format(acct.name, acct.id)); | ||||||
| 
 | 
 | ||||||
|  | elif sys.argv[1] == "inventory": | ||||||
|  |     if (len(sys.argv) % 2 != 0 or len(sys.argv) < 4): | ||||||
|  |         print ("Invalid number of parameters, count your parameters.") | ||||||
|  |     else: | ||||||
|  |         iamt = int(sys.argv[2]) | ||||||
|  |         iacct = load_item(sys.argv[3]) #TODO:use barcodes later | ||||||
|  |         print("Current state {} (id {}): {} pcs".format(iacct.name, iacct.id, iacct.balance())) | ||||||
|  |         shop.fix_inventory(item = iacct, amount = iamt) | ||||||
|  |         print("New state {} (id {}): {} pcs".format(iacct.name, iacct.id, iacct.balance())) | ||||||
|  | 
 | ||||||
| else: | else: | ||||||
|     help() |     help() | ||||||
|  |  | ||||||
|  | @ -7,18 +7,22 @@ class Shop: | ||||||
| 
 | 
 | ||||||
|     Business logic so that only interaction is left in the hands |     Business logic so that only interaction is left in the hands | ||||||
|     of the frontend scripts. """ |     of the frontend scripts. """ | ||||||
|     def __init__(self, db, currency, profits, cash): |     def __init__(self, db, currency, profits, cash, excess, deficit): | ||||||
|         self.db = db |         self.db = db | ||||||
|         self.currency = currency # brmbar.Currency |         self.currency = currency # brmbar.Currency | ||||||
|         self.profits = profits # income brmbar.Account for brmbar profit margins on items |         self.profits = profits # income brmbar.Account for brmbar profit margins on items | ||||||
|         self.cash = cash # our operational ("wallet") cash account |         self.cash = cash # our operational ("wallet") cash account | ||||||
|  |         self.excess = excess # account from which is deducted cash during inventory item fixing (when system contains less items than is the reality) | ||||||
|  |         self.deficit = deficit # account where is put cash during inventory item fixing (when system contains more items than is the reality) | ||||||
| 
 | 
 | ||||||
|     @classmethod |     @classmethod | ||||||
|     def new_with_defaults(cls, db): |     def new_with_defaults(cls, db): | ||||||
|         return cls(db, |         return cls(db, | ||||||
|             currency = Currency.default(db), |             currency = Currency.default(db), | ||||||
|             profits = Account.load(db, name = "BrmBar Profits"), |             profits = Account.load(db, name = "BrmBar Profits"), | ||||||
|             cash = Account.load(db, name = "BrmBar Cash")) |             cash = Account.load(db, name = "BrmBar Cash"), | ||||||
|  |             excess = Account.load(db, name = "BrmBar Excess"), | ||||||
|  |             deficit = Account.load(db, name = "BrmBar Deficit")) | ||||||
| 
 | 
 | ||||||
|     def sell(self, item, user, amount = 1): |     def sell(self, item, user, amount = 1): | ||||||
|         # Sale: Currency conversion from item currency to shop currency |         # Sale: Currency conversion from item currency to shop currency | ||||||
|  | @ -139,3 +143,21 @@ class Shop: | ||||||
|         for inventory in cur: |         for inventory in cur: | ||||||
|             accts += [ Account.load(self.db, id = inventory[0]) ] |             accts += [ Account.load(self.db, id = inventory[0]) ] | ||||||
|         return accts |         return accts | ||||||
|  | 
 | ||||||
|  |     def fix_inventory(self, item, amount): | ||||||
|  |         amount_in_reality = amount | ||||||
|  |         amount_in_system = item.balance() | ||||||
|  |         (buy, sell) = item.currency.rates(self.currency) | ||||||
|  | 
 | ||||||
|  |         diff = abs(amount_in_reality - amount_in_system) | ||||||
|  |         buy_total = buy * diff | ||||||
|  |         if amount_in_reality > amount_in_system: | ||||||
|  |             transaction = self._transaction(description = "BrmBar inventory fix of {}pcs {} in system to {}pcs in reality".format(amount_in_system, item.name,amount_in_reality)) | ||||||
|  |             item.debit(transaction, diff, "Inventory fix excess") | ||||||
|  |             self.excess.credit(transaction, buy_total, "Inventory fix excess " + item.name) | ||||||
|  |             self.db.commit() | ||||||
|  |         elif amount_in_reality < amount_in_system: | ||||||
|  |             transaction = self._transaction(description = "BrmBar inventory fix of {}pcs {} in system to {}pcs in reality".format(amount_in_system, item.name,amount_in_reality)) | ||||||
|  |             item.credit(transaction, diff, "Inventory fix deficit") | ||||||
|  |             self.deficit.credit(transaction, buy_total, "Inventory fix deficit " + item.name) | ||||||
|  |             self.db.commit() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 b00lean
						b00lean