diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js index 5b4ef2339265..aba213ebca41 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.js +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js @@ -277,7 +277,7 @@ frappe.ui.form.on("Production Plan", { frm.clear_table("prod_plan_references"); frappe.call({ - method: "get_items", + method: "combine_so_items", freeze: true, doc: frm.doc, callback: function () { diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index 7d3aa000c870..3f82a75d3020 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -269,6 +269,31 @@ def add_mr_in_table(self, pending_mr): {"material_request": data.name, "material_request_date": data.transaction_date}, ) + @frappe.whitelist() + def combine_so_items(self): + if self.combine_items and self.po_items and len(self.po_items) > 0: + items = [] + for row in self.po_items: + items.append( + frappe._dict( + { + "parent": row.sales_order, + "item_code": row.item_code, + "warehouse": row.warehouse, + "qty": row.pending_qty, + "pending_qty": row.pending_qty, + "conversion_factor": 1.0, + "description": row.description, + "bom_no": row.bom_no, + } + ) + ) + + self.set("po_items", []) + self.add_items(items) + else: + self.get_items() + @frappe.whitelist() def get_items(self): self.set("po_items", []) @@ -435,24 +460,28 @@ def add_items(self, items): item_details = get_item_details(data.item_code, throw=False) if self.combine_items: - if item_details.bom_no in refs: - refs[item_details.bom_no]["so_details"].append( + bom_no = item_details.bom_no + if data.get("bom_no"): + bom_no = data.get("bom_no") + + if bom_no in refs: + refs[bom_no]["so_details"].append( {"sales_order": data.parent, "sales_order_item": data.name, "qty": data.pending_qty} ) - refs[item_details.bom_no]["qty"] += data.pending_qty + refs[bom_no]["qty"] += data.pending_qty continue else: - refs[item_details.bom_no] = { + refs[bom_no] = { "qty": data.pending_qty, "po_item_ref": data.name, "so_details": [], } - refs[item_details.bom_no]["so_details"].append( + refs[bom_no]["so_details"].append( {"sales_order": data.parent, "sales_order_item": data.name, "qty": data.pending_qty} ) - bom_no = data.bom_no or item_details and item_details.bom_no or "" + bom_no = data.bom_no or item_details and item_details.get("bom_no") or "" if not bom_no: continue