Skip to content

Commit

Permalink
feat: make Material Request for sub-assembly items
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Nov 28, 2022
1 parent f612606 commit e02f35c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
19 changes: 19 additions & 0 deletions erpnext/manufacturing/doctype/production_plan/production_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ def make_work_order_for_subassembly_items(self, wo_list, subcontracted_po, defau
subcontracted_po.setdefault(row.supplier, []).append(row)
continue

if row.type_of_manufacturing == "Material Request":
continue

work_order_data = {
"wip_warehouse": default_warehouses.get("wip_warehouse"),
"fg_warehouse": default_warehouses.get("fg_warehouse"),
Expand Down Expand Up @@ -1161,6 +1164,7 @@ def get_bin_details(row, company, for_warehouse=None, all_warehouse=False):

subquery = frappe.qb.from_(wh).select(wh.name).where(wh.company == company)

warehouse = ""
if not all_warehouse:
warehouse = for_warehouse or row.get("source_warehouse") or row.get("default_warehouse")

Expand Down Expand Up @@ -1226,6 +1230,21 @@ def get_items_for_material_requests(doc, warehouses=None, get_parent_warehouse_d
doc["mr_items"] = []

po_items = doc.get("po_items") if doc.get("po_items") else doc.get("items")

if doc.get("sub_assembly_items"):
for sa_row in doc.sub_assembly_items:
sa_row = frappe._dict(sa_row)
if sa_row.type_of_manufacturing == "Material Request":
po_items.append(
frappe._dict(
{
"item_code": sa_row.production_item,
"required_qty": sa_row.qty,
"include_exploded_items": 0,
}
)
)

# Check for empty table or empty rows
if not po_items or not [row.get("item_code") for row in po_items if row.get("item_code")]:
frappe.throw(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,34 @@ def test_material_request_item_for_purchase_uom(self):
self.assertEqual(row.uom, "Nos")
self.assertEqual(row.qty, 1)

def test_material_request_for_sub_assembly_items(self):
from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom

bom_tree = {
"Fininshed Goods1 For MR": {
"SubAssembly1 For MR": {"SubAssembly1-1 For MR": {"ChildPart1 For MR": {}}}
}
}

parent_bom = create_nested_bom(bom_tree, prefix="")
plan = create_production_plan(
item_code=parent_bom.item, planned_qty=10, ignore_existing_ordered_qty=1, do_not_submit=1
)

plan.get_sub_assembly_items()

mr_items = []
for row in plan.sub_assembly_items:
mr_items.append(row.production_item)
row.type_of_manufacturing = "Material Request"

plan.save()
items = get_items_for_material_requests(plan.as_dict())

validate_mr_items = [d.get("item_code") for d in items]
for item_code in mr_items:
self.assertTrue(item_code in validate_mr_items)


def create_production_plan(**args):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
"fieldtype": "Select",
"in_list_view": 1,
"label": "Manufacturing Type",
"options": "In House\nSubcontract"
"options": "In House\nSubcontract\nMaterial Request"
},
{
"fieldname": "supplier",
Expand All @@ -188,7 +188,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2022-01-30 21:31:10.527559",
"modified": "2022-11-28 13:50:15.116082",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Production Plan Sub Assembly Item",
Expand Down

0 comments on commit e02f35c

Please sign in to comment.