From d0b6b0ee971318175ba3cb8a9e39c3b0821b7ef1 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 31 Jan 2025 15:51:09 +0530 Subject: [PATCH] fix: actual qty showing blank for sub-assembly items --- .../production_plan/production_plan.js | 22 ++++++++++++ .../production_plan/production_plan.py | 34 ++++++++++++++++--- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js index e7ac7f7cc83..f381c9d39e2 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.js +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js @@ -562,6 +562,28 @@ frappe.ui.form.on("Production Plan Sales Order", { frappe.ui.form.on("Production Plan Sub Assembly Item", { fg_warehouse(frm, cdt, cdn) { erpnext.utils.copy_value_in_all_rows(frm.doc, cdt, cdn, "sub_assembly_items", "fg_warehouse"); + + let row = locals[cdt][cdn]; + if (row.fg_warehouse && row.production_item) { + let child_row = { + item_code: row.production_item, + warehouse: row.fg_warehouse, + }; + + frappe.call({ + method: "erpnext.manufacturing.doctype.production_plan.production_plan.get_bin_details", + args: { + row: child_row, + company: frm.doc.company, + for_warehouse: row.fg_warehouse, + }, + callback: function (r) { + if (r.message && r.message.length) { + frappe.model.set_value(cdt, cdn, "actual_qty", r.message[0].actual_qty); + } + }, + }); + } }, }); diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index c048ab40416..cf704c54ebb 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -974,8 +974,14 @@ class ProductionPlan(Document): bom_data = [] - warehouse = (self.sub_assembly_warehouse) if self.skip_available_sub_assembly_item else None - get_sub_assembly_items(row.bom_no, bom_data, row.planned_qty, self.company, warehouse=warehouse) + get_sub_assembly_items( + row.bom_no, + bom_data, + row.planned_qty, + self.company, + warehouse=self.sub_assembly_warehouse, + skip_available_sub_assembly_item=self.skip_available_sub_assembly_item, + ) self.set_sub_assembly_items_based_on_level(row, bom_data, manufacturing_type) sub_assembly_items_store.extend(bom_data) @@ -1766,14 +1772,23 @@ def get_item_data(item_code): } -def get_sub_assembly_items(bom_no, bom_data, to_produce_qty, company, warehouse=None, indent=0): +def get_sub_assembly_items( + bom_no, + bom_data, + to_produce_qty, + company, + warehouse=None, + indent=0, + skip_available_sub_assembly_item=False, +): data = get_bom_children(parent=bom_no) for d in data: if d.expandable: parent_item_code = frappe.get_cached_value("BOM", bom_no, "item") stock_qty = (d.stock_qty / d.parent_bom_qty) * flt(to_produce_qty) - if warehouse: + bin_details = frappe._dict() + if skip_available_sub_assembly_item: bin_details = get_bin_details(d, company, for_warehouse=warehouse) for _bin_dict in bin_details: @@ -1783,11 +1798,14 @@ def get_sub_assembly_items(bom_no, bom_data, to_produce_qty, company, warehouse= continue else: stock_qty = stock_qty - _bin_dict.projected_qty + elif warehouse: + bin_details = get_bin_details(d, company, for_warehouse=warehouse) if stock_qty > 0: bom_data.append( frappe._dict( { + "actual_qty": bin_details[0].get("actual_qty", 0) if bin_details else 0, "parent_item_code": parent_item_code, "description": d.description, "production_item": d.item_code, @@ -1805,7 +1823,13 @@ def get_sub_assembly_items(bom_no, bom_data, to_produce_qty, company, warehouse= if d.value: get_sub_assembly_items( - d.value, bom_data, stock_qty, company, warehouse, indent=indent + 1 + d.value, + bom_data, + stock_qty, + company, + warehouse, + indent=indent + 1, + skip_available_sub_assembly_item=skip_available_sub_assembly_item, ) -- GitLab