fix: FG Item incorrect qty in the work order (#39200) (cherry picked from commit 466625213b6355b53b7af3ee1682cee6fc8649a4) Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
		
							parent
							
								
									3caf462c6b
								
							
						
					
					
						commit
						abc99f84e9
					
				| @ -646,6 +646,10 @@ class ProductionPlan(Document): | |||||||
| 				"project": self.project, | 				"project": self.project, | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
|  | 			key = (d.item_code, d.sales_order, d.warehouse) | ||||||
|  | 			if not d.sales_order: | ||||||
|  | 				key = (d.name, d.item_code, d.warehouse) | ||||||
|  | 
 | ||||||
| 			if not item_details["project"] and d.sales_order: | 			if not item_details["project"] and d.sales_order: | ||||||
| 				item_details["project"] = frappe.get_cached_value("Sales Order", d.sales_order, "project") | 				item_details["project"] = frappe.get_cached_value("Sales Order", d.sales_order, "project") | ||||||
| 
 | 
 | ||||||
| @ -654,12 +658,9 @@ class ProductionPlan(Document): | |||||||
| 				item_dict[(d.item_code, d.material_request_item, d.warehouse)] = item_details | 				item_dict[(d.item_code, d.material_request_item, d.warehouse)] = item_details | ||||||
| 			else: | 			else: | ||||||
| 				item_details.update( | 				item_details.update( | ||||||
| 					{ | 					{"qty": flt(item_dict.get(key, {}).get("qty")) + (flt(d.planned_qty) - flt(d.ordered_qty))} | ||||||
| 						"qty": flt(item_dict.get((d.item_code, d.sales_order, d.warehouse), {}).get("qty")) |  | ||||||
| 						+ (flt(d.planned_qty) - flt(d.ordered_qty)) |  | ||||||
| 					} |  | ||||||
| 				) | 				) | ||||||
| 				item_dict[(d.item_code, d.sales_order, d.warehouse)] = item_details | 				item_dict[key] = item_details | ||||||
| 
 | 
 | ||||||
| 		return item_dict | 		return item_dict | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -672,7 +672,7 @@ class TestProductionPlan(FrappeTestCase): | |||||||
| 			items_data = pln.get_production_items() | 			items_data = pln.get_production_items() | ||||||
| 
 | 
 | ||||||
| 			# Update qty | 			# Update qty | ||||||
| 			items_data[(item, None, None)]["qty"] = qty | 			items_data[(pln.po_items[0].name, item, None)]["qty"] = qty | ||||||
| 
 | 
 | ||||||
| 			# Create and Submit Work Order for each item in items_data | 			# Create and Submit Work Order for each item in items_data | ||||||
| 			for key, item in items_data.items(): | 			for key, item in items_data.items(): | ||||||
| @ -1522,6 +1522,45 @@ class TestProductionPlan(FrappeTestCase): | |||||||
| 		for d in mr_items: | 		for d in mr_items: | ||||||
| 			self.assertEqual(d.get("quantity"), 1000.0) | 			self.assertEqual(d.get("quantity"), 1000.0) | ||||||
| 
 | 
 | ||||||
|  | 	def test_fg_item_quantity(self): | ||||||
|  | 		from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse | ||||||
|  | 		from erpnext.stock.utils import get_or_make_bin | ||||||
|  | 
 | ||||||
|  | 		fg_item = make_item(properties={"is_stock_item": 1}).name | ||||||
|  | 		rm_item = make_item(properties={"is_stock_item": 1}).name | ||||||
|  | 
 | ||||||
|  | 		make_bom(item=fg_item, raw_materials=[rm_item], source_warehouse="_Test Warehouse - _TC") | ||||||
|  | 
 | ||||||
|  | 		pln = create_production_plan(item_code=fg_item, planned_qty=10, do_not_submit=1) | ||||||
|  | 
 | ||||||
|  | 		pln.append( | ||||||
|  | 			"po_items", | ||||||
|  | 			{ | ||||||
|  | 				"item_code": rm_item, | ||||||
|  | 				"planned_qty": 20, | ||||||
|  | 				"bom_no": pln.po_items[0].bom_no, | ||||||
|  | 				"warehouse": pln.po_items[0].warehouse, | ||||||
|  | 				"planned_start_date": add_to_date(nowdate(), days=1), | ||||||
|  | 			}, | ||||||
|  | 		) | ||||||
|  | 		pln.submit() | ||||||
|  | 		wo_qty = {} | ||||||
|  | 
 | ||||||
|  | 		for row in pln.po_items: | ||||||
|  | 			wo_qty[row.name] = row.planned_qty | ||||||
|  | 
 | ||||||
|  | 		pln.make_work_order() | ||||||
|  | 
 | ||||||
|  | 		work_orders = frappe.get_all( | ||||||
|  | 			"Work Order", | ||||||
|  | 			fields=["qty", "production_plan_item as name"], | ||||||
|  | 			filters={"production_plan": pln.name}, | ||||||
|  | 		) | ||||||
|  | 		self.assertEqual(len(work_orders), 2) | ||||||
|  | 
 | ||||||
|  | 		for row in work_orders: | ||||||
|  | 			self.assertEqual(row.qty, wo_qty[row.name]) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| def create_production_plan(**args): | def create_production_plan(**args): | ||||||
| 	""" | 	""" | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user