From af16fbb0a301514ab9a890a5f87571ee739539e2 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Sat, 6 May 2023 20:30:53 +0530 Subject: [PATCH] fix: incorrect fg item quantity in subcontracted PO --- .../production_plan/production_plan.py | 1 + .../production_plan/test_production_plan.py | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index df50cbf26954..f9e68b916f8c 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -587,6 +587,7 @@ def make_subcontracted_purchase_order(self, subcontracted_po, purchase_orders): "production_plan_sub_assembly_item": row.name, "bom": row.bom_no, "production_plan": self.name, + "fg_item_qty": row.qty, } for field in [ diff --git a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py index 91864d09dbd4..4648d896cee0 100644 --- a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py @@ -307,6 +307,43 @@ def test_production_plan_subassembly_default_supplier(self): self.assertEqual(plan.sub_assembly_items[0].supplier, "_Test Supplier") + def test_production_plan_for_subcontracting_po(self): + from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom + + bom_tree_1 = {"Test Laptop 1": {"Test Motherboard 1": {"Test Motherboard Wires 1": {}}}} + create_nested_bom(bom_tree_1, prefix="") + + item_doc = frappe.get_doc("Item", "Test Motherboard 1") + company = "_Test Company" + + item_doc.is_sub_contracted_item = 1 + for row in item_doc.item_defaults: + if row.company == company and not row.default_supplier: + row.default_supplier = "_Test Supplier" + + if not item_doc.item_defaults: + item_doc.append("item_defaults", {"company": company, "default_supplier": "_Test Supplier"}) + + item_doc.save() + + plan = create_production_plan( + item_code="Test Laptop 1", planned_qty=10, use_multi_level_bom=1, do_not_submit=True + ) + plan.get_sub_assembly_items() + plan.set_default_supplier_for_subcontracting_order() + plan.submit() + + self.assertEqual(plan.sub_assembly_items[0].supplier, "_Test Supplier") + plan.make_work_order() + + po = frappe.db.get_value("Purchase Order Item", {"production_plan": plan.name}, "parent") + po_doc = frappe.get_doc("Purchase Order", po) + self.assertEqual(po_doc.supplier, "_Test Supplier") + self.assertEqual(po_doc.items[0].qty, 10.0) + self.assertEqual(po_doc.items[0].fg_item_qty, 10.0) + self.assertEqual(po_doc.items[0].fg_item_qty, 10.0) + self.assertEqual(po_doc.items[0].fg_item, "Test Motherboard 1") + def test_production_plan_combine_subassembly(self): """ Test combining Sub assembly items belonging to the same BOM in Prod Plan.