Skip to content

Commit

Permalink
Merge pull request #35197 from rohitwaghchaure/fix-incorrect-fg-item-…
Browse files Browse the repository at this point in the history
…qty-in-job-po

fix: incorrect fg item quantity in subcontracted PO
  • Loading branch information
rohitwaghchaure authored May 6, 2023
2 parents 23e7c14 + 140cec8 commit c3ca5d0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c3ca5d0

Please sign in to comment.