Skip to content

Commit

Permalink
fix: production plan bom error (#43591)
Browse files Browse the repository at this point in the history
(cherry picked from commit ab17132)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed Oct 9, 2024
1 parent 9e109ac commit 9f35ae9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
41 changes: 35 additions & 6 deletions erpnext/manufacturing/doctype/production_plan/production_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", [])
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 9f35ae9

Please sign in to comment.