From b948cf204caa629c067c6d29145b49a27eddc5bc Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 22 Sep 2020 19:47:33 +0530 Subject: [PATCH] fix: Download Required Materials not working for production plan --- .../doctype/production_plan/production_plan.js | 6 ++++-- .../doctype/production_plan/production_plan.py | 9 ++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js index 2b168d1d76d..cb8d3a02068 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.js +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js @@ -159,6 +159,7 @@ frappe.ui.form.on('Production Plan', { get_sales_orders: function(frm) { frappe.call({ method: "get_open_sales_orders", + freeze: true, doc: frm.doc, callback: function(r) { refresh_field("sales_orders"); @@ -169,6 +170,7 @@ frappe.ui.form.on('Production Plan', { get_material_request: function(frm) { frappe.call({ method: "get_pending_material_requests", + freeze: true, doc: frm.doc, callback: function() { refresh_field('material_requests'); @@ -188,7 +190,7 @@ frappe.ui.form.on('Production Plan', { }, get_items_for_mr: function(frm) { - const set_fields = ['actual_qty', 'item_code','item_name', 'description', 'uom', + const set_fields = ['actual_qty', 'item_code','item_name', 'description', 'uom', 'min_order_qty', 'quantity', 'sales_order', 'warehouse', 'projected_qty', 'material_request_type']; frappe.call({ method: "erpnext.manufacturing.doctype.production_plan.production_plan.get_items_for_material_requests", @@ -219,7 +221,7 @@ frappe.ui.form.on('Production Plan', { download_materials_required: function(frm) { let get_template_url = 'erpnext.manufacturing.doctype.production_plan.production_plan.download_raw_materials'; - open_url_post(frappe.request.url, { cmd: get_template_url, production_plan: frm.doc.name }); + open_url_post(frappe.request.url, { cmd: get_template_url, doc: frm.doc }); }, show_progress: function(frm) { diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index 02dfabe6f70..aa80dcfed24 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -422,14 +422,13 @@ class ProductionPlan(Document): msgprint(_("No material request created")) @frappe.whitelist() -def download_raw_materials(production_plan): - doc = frappe.get_doc('Production Plan', production_plan) - doc.check_permission() - +def download_raw_materials(doc): item_list = [['Item Code', 'Description', 'Stock UOM', 'Required Qty', 'Warehouse', 'projected Qty', 'Actual Qty']] - doc = doc.as_dict() + if isinstance(doc, string_types): + doc = frappe._dict(json.loads(doc)) + for d in get_items_for_material_requests(doc, ignore_existing_ordered_qty=True): item_list.append([d.get('item_code'), d.get('description'), d.get('stock_uom'), d.get('quantity'), d.get('warehouse'), d.get('projected_qty'), d.get('actual_qty')])