mirror of
				https://github.com/brmlab/brmbar.git
				synced 2025-10-30 23:14:02 +01:00 
			
		
		
		
	#15: stored function for cash-based stock replenishment transaction
This commit is contained in:
		
							parent
							
								
									ad832fc71b
								
							
						
					
					
						commit
						629b35655d
					
				
					 2 changed files with 91 additions and 5 deletions
				
			
		|  | @ -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 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue