fix: default supplier not set in the PP
This commit is contained in:
parent
756fe4b375
commit
5fd468d9ec
@ -656,6 +656,8 @@ class ProductionPlan(Document):
|
||||
row.idx = idx + 1
|
||||
self.append("sub_assembly_items", row)
|
||||
|
||||
self.set_default_supplier_for_subcontracting_order()
|
||||
|
||||
def set_sub_assembly_items_based_on_level(self, row, bom_data, manufacturing_type=None):
|
||||
"Modify bom_data, set additional details."
|
||||
for data in bom_data:
|
||||
@ -667,6 +669,32 @@ class ProductionPlan(Document):
|
||||
"Subcontract" if data.is_sub_contracted_item else "In House"
|
||||
)
|
||||
|
||||
def set_default_supplier_for_subcontracting_order(self):
|
||||
items = [
|
||||
d.production_item for d in self.sub_assembly_items if d.type_of_manufacturing == "Subcontract"
|
||||
]
|
||||
|
||||
if not items:
|
||||
return
|
||||
|
||||
default_supplier = frappe._dict(
|
||||
frappe.get_all(
|
||||
"Item Default",
|
||||
fields=["parent", "default_supplier"],
|
||||
filters={"parent": ("in", items), "default_supplier": ("is", "set")},
|
||||
as_list=1,
|
||||
)
|
||||
)
|
||||
|
||||
if not default_supplier:
|
||||
return
|
||||
|
||||
for row in self.sub_assembly_items:
|
||||
if row.type_of_manufacturing != "Subcontract":
|
||||
continue
|
||||
|
||||
row.supplier = default_supplier.get(row.production_item)
|
||||
|
||||
def combine_subassembly_items(self, sub_assembly_items_store):
|
||||
"Aggregate if same: Item, Warehouse, Inhouse/Outhouse Manu.g, BOM No."
|
||||
key_wise_data = {}
|
||||
|
@ -281,6 +281,31 @@ class TestProductionPlan(FrappeTestCase):
|
||||
pln.reload()
|
||||
pln.cancel()
|
||||
|
||||
def test_production_plan_subassembly_default_supplier(self):
|
||||
from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom
|
||||
|
||||
bom_tree_1 = {"Test Laptop": {"Test Motherboard": {"Test Motherboard Wires": {}}}}
|
||||
bom = create_nested_bom(bom_tree_1, prefix="")
|
||||
|
||||
item_doc = frappe.get_doc("Item", "Test Motherboard")
|
||||
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", use_multi_level_bom=1, do_not_submit=True)
|
||||
plan.get_sub_assembly_items()
|
||||
plan.set_default_supplier_for_subcontracting_order()
|
||||
|
||||
self.assertEqual(plan.sub_assembly_items[0].supplier, "_Test Supplier")
|
||||
|
||||
def test_production_plan_combine_subassembly(self):
|
||||
"""
|
||||
Test combining Sub assembly items belonging to the same BOM in Prod Plan.
|
||||
|
Loading…
Reference in New Issue
Block a user