From 029021f035b31768acfb94386219e6602cbcbc46 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:41:21 +0530 Subject: [PATCH] fix: production plan bom error (backport #43591) (#43594) fix: production plan bom error (#43591) (cherry picked from commit ab171326f337887ce323ad073e0a1882ed19c32d) Co-authored-by: rohitwaghchaure --- .../production_plan/production_plan.js | 2 +- .../production_plan/production_plan.py | 41 ++++++++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js index 5b4ef233926..aba213ebca4 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 7d3aa000c87..3f82a75d302 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -269,6 +269,31 @@ class ProductionPlan(Document): {"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 @@ class ProductionPlan(Document): 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