diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js index f9f1031be865fb6a292af97646de1e13ddfdd37c..bfff76eaa3305abde6fb4fcb085b65e1832ee7da 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.js +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js @@ -560,6 +560,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 9ae432a748637b5f10750bc5deefb439630b6b8b..1593477263a3c400591f3776856f293bcbb002be 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -936,8 +936,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) @@ -1736,14 +1742,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: @@ -1753,11 +1768,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, @@ -1774,7 +1792,15 @@ 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) + get_sub_assembly_items( + d.value, + bom_data, + stock_qty, + company, + warehouse, + indent=indent + 1, + skip_available_sub_assembly_item=skip_available_sub_assembly_item, + ) def set_default_warehouses(row, default_warehouses):