Add initial support for 'costing' mode for purchase batches
This commit is contained in:
		
							parent
							
								
									4592c96fb5
								
							
						
					
					
						commit
						d96d22ab68
					
				
					 2 changed files with 35 additions and 13 deletions
				
			
		|  | @ -41,10 +41,12 @@ class PurchaseBatchHandler(BatchHandler): | |||
| 
 | ||||
|     def requires_prefill(self, batch): | ||||
|         # TODO: this probably should change soon, for now this works.. | ||||
|         return batch.mode == self.enum.PURCHASE_BATCH_MODE_RECEIVING and batch.purchase | ||||
|         return batch.purchase and batch.mode in (self.enum.PURCHASE_BATCH_MODE_RECEIVING, | ||||
|                                                  self.enum.PURCHASE_BATCH_MODE_COSTING) | ||||
| 
 | ||||
|     def make_initial_rows(self, batch, progress=None): | ||||
|         assert batch.mode == self.enum.PURCHASE_BATCH_MODE_RECEIVING and batch.purchase | ||||
|         assert batch.purchase and batch.mode in (self.enum.PURCHASE_BATCH_MODE_RECEIVING, | ||||
|                                                  self.enum.PURCHASE_BATCH_MODE_COSTING) | ||||
| 
 | ||||
|         def append(item, i): | ||||
|             row = model.PurchaseBatchRow() | ||||
|  | @ -52,8 +54,13 @@ class PurchaseBatchHandler(BatchHandler): | |||
|             row.product = item.product | ||||
|             row.cases_ordered = item.cases_ordered or None | ||||
|             row.units_ordered = item.units_ordered or None | ||||
|             row.cases_received = item.cases_received or None | ||||
|             row.units_received = item.units_received or None | ||||
|             row.po_unit_cost = item.po_unit_cost | ||||
|             row.po_total = item.po_total | ||||
|             if batch.mode == self.enum.PURCHASE_BATCH_MODE_COSTING: | ||||
|                 row.invoice_unit_cost = item.invoice_unit_cost | ||||
|                 row.invoice_total = item.invoice_total | ||||
|             batch.add_row(row) | ||||
|             self.refresh_row(row) | ||||
| 
 | ||||
|  | @ -63,7 +70,8 @@ class PurchaseBatchHandler(BatchHandler): | |||
|     def refresh(self, batch, progress=None): | ||||
|         if batch.mode == self.enum.PURCHASE_BATCH_MODE_NEW: | ||||
|             batch.po_total = 0 | ||||
|         elif batch.mode == self.enum.PURCHASE_BATCH_MODE_RECEIVING: | ||||
|         elif batch.mode in (self.enum.PURCHASE_BATCH_MODE_RECEIVING, | ||||
|                             self.enum.PURCHASE_BATCH_MODE_COSTING): | ||||
|             batch.invoice_total = 0 | ||||
|         return super(PurchaseBatchHandler, self).refresh(batch, progress=progress) | ||||
| 
 | ||||
|  | @ -96,7 +104,8 @@ class PurchaseBatchHandler(BatchHandler): | |||
|             row.po_total = (row.po_unit_cost * (row.units_ordered or 0)) + ( | ||||
|                 row.po_unit_cost * (row.cases_ordered or 0) * row.case_quantity) | ||||
|             batch.po_total = (batch.po_total or 0) + row.po_total | ||||
|         elif batch.mode == self.enum.PURCHASE_BATCH_MODE_RECEIVING: | ||||
|         elif batch.mode in (self.enum.PURCHASE_BATCH_MODE_RECEIVING, | ||||
|                             self.enum.PURCHASE_BATCH_MODE_COSTING): | ||||
|             row.invoice_unit_cost = cost.unit_cost | ||||
|             row.invoice_total = (row.invoice_unit_cost * (row.units_received or 0)) + ( | ||||
|                 row.invoice_unit_cost * (row.cases_received or 0) * row.case_quantity) | ||||
|  | @ -105,7 +114,8 @@ class PurchaseBatchHandler(BatchHandler): | |||
|         if batch.mode == self.enum.PURCHASE_BATCH_MODE_NEW: | ||||
|             row.status_code = row.STATUS_OK | ||||
| 
 | ||||
|         elif batch.mode == self.enum.PURCHASE_BATCH_MODE_RECEIVING: | ||||
|         elif batch.mode in (self.enum.PURCHASE_BATCH_MODE_RECEIVING, | ||||
|                             self.enum.PURCHASE_BATCH_MODE_COSTING): | ||||
|             if row.cases_received is None and row.units_received is None: | ||||
|                 row.status_code = row.STATUS_INCOMPLETE | ||||
|             elif row.cases_received != row.cases_ordered or row.units_received != row.units_ordered: | ||||
|  | @ -118,12 +128,24 @@ class PurchaseBatchHandler(BatchHandler): | |||
|         Default behavior for executing a purchase batch will create a new | ||||
|         purchase, by invoking :meth:`make_purchase()`. | ||||
|         """ | ||||
|         session = orm.object_session(batch) | ||||
| 
 | ||||
|         if batch.mode == self.enum.PURCHASE_BATCH_MODE_NEW: | ||||
|             return self.make_purchase(batch, user, progress=progress) | ||||
| 
 | ||||
|         elif batch.mode == self.enum.PURCHASE_BATCH_MODE_RECEIVING: | ||||
|             session = orm.object_session(batch) | ||||
|             with session.no_autoflush: | ||||
|                 return self.receive_purchase(batch, progress=progress) | ||||
| 
 | ||||
|         elif batch.mode == self.enum.PURCHASE_BATCH_MODE_COSTING: | ||||
|             # TODO: finish this... | ||||
|             # with session.no_autoflush: | ||||
|             #     return self.cost_purchase(batch, progress=progress) | ||||
|             purchase = batch.purchase | ||||
|             purchase.invoice_date = batch.invoice_date | ||||
|             purchase.status = self.enum.PURCHASE_STATUS_COSTED | ||||
|             return purchase | ||||
| 
 | ||||
|         assert False | ||||
| 
 | ||||
|     def make_purchase(self, batch, user, progress=None): | ||||
|  |  | |||
|  | @ -144,14 +144,14 @@ PRICE_TYPE = { | |||
|     } | ||||
| 
 | ||||
| 
 | ||||
| PURCHASE_BATCH_MODE_NEW         = 10 | ||||
| PURCHASE_BATCH_MODE_RECEIVING   = 20 | ||||
| PURCHASE_BATCH_MODE_COSTING     = 30 | ||||
| PURCHASE_BATCH_MODE_NEW                 = 10 | ||||
| PURCHASE_BATCH_MODE_RECEIVING           = 20 | ||||
| PURCHASE_BATCH_MODE_COSTING             = 30 | ||||
| 
 | ||||
| PURCHASE_BATCH_MODE = { | ||||
|     PURCHASE_BATCH_MODE_NEW     : "create/new", | ||||
|     PURCHASE_BATCH_MODE_RECEIVING : "receiving", | ||||
|     PURCHASE_BATCH_MODE_COSTING : "costing", | ||||
|     PURCHASE_BATCH_MODE_NEW             : "ordering", | ||||
|     PURCHASE_BATCH_MODE_RECEIVING       : "receiving", | ||||
|     PURCHASE_BATCH_MODE_COSTING         : "invoicing", | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | @ -165,7 +165,7 @@ PURCHASE_STATUS = { | |||
|     PURCHASE_STATUS_NEW         : "new/pending", | ||||
|     PURCHASE_STATUS_ORDERED     : "ordered", | ||||
|     PURCHASE_STATUS_RECEIVED    : "received", | ||||
|     PURCHASE_STATUS_COSTED      : "costed", | ||||
|     PURCHASE_STATUS_COSTED      : "invoiced", | ||||
|     PURCHASE_STATUS_PAID        : "paid", | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar