fix: incorrect fg item quantity in subcontracted PO
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py
index df50cbf..f9e68b9 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py
@@ -587,6 +587,7 @@
"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 91864d0..4648d89 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 @@
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.