From d4453aef684871d1c2c33abaa26d97c6e73c1405 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 4 Jul 2018 16:37:58 +0530 Subject: [PATCH] Fixed permission issue --- .../doctype/work_order/work_order.js | 55 +++++++++---------- .../doctype/work_order/work_order.py | 6 ++ 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/work_order.js b/erpnext/manufacturing/doctype/work_order/work_order.js index 672ec26c4b..013183ec2b 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.js +++ b/erpnext/manufacturing/doctype/work_order/work_order.js @@ -329,39 +329,38 @@ erpnext.work_order = { if(!frm.doc.skip_transfer){ // If "Material Consumption is check in Manufacturing Settings, allow Material Consumption - frappe.model.get_value('Manufacturing Settings', {'name': 'Manufacturing Settings'}, 'material_consumption', function(d) { - if ((flt(doc.produced_qty) < flt(doc.material_transferred_for_manufacturing)) - && frm.doc.status != 'Stopped') { - frm.has_finish_btn = true; + if ((flt(doc.produced_qty) < flt(doc.material_transferred_for_manufacturing)) + && frm.doc.status != 'Stopped') { + frm.has_finish_btn = true; - if (d.material_consumption == 1) { - // Only show "Material Consumption" when required_qty > consumed_qty - var counter = 0; - var tbl = frm.doc.required_items || []; - var tbl_lenght = tbl.length; - for (var i = 0, len = tbl_lenght; i < len; i++) { - if (flt(frm.doc.required_items[i].required_qty) > flt(frm.doc.required_items[i].consumed_qty)) { - counter += 1; - } - } - if (counter > 0) { - var consumption_btn = frm.add_custom_button(__('Material Consumption'), function() { - erpnext.work_order.make_consumption_se(frm, d.backflush_raw_materials_based_on); - }); - consumption_btn.addClass('btn-primary'); + if (frm.doc.__onload && frm.doc.__onload.material_consumption == 1) { + // Only show "Material Consumption" when required_qty > consumed_qty + var counter = 0; + var tbl = frm.doc.required_items || []; + var tbl_lenght = tbl.length; + for (var i = 0, len = tbl_lenght; i < len; i++) { + if (flt(frm.doc.required_items[i].required_qty) > flt(frm.doc.required_items[i].consumed_qty)) { + counter += 1; } } - - var finish_btn = frm.add_custom_button(__('Finish'), function() { - erpnext.work_order.make_se(frm, 'Manufacture'); - }); - - if(doc.material_transferred_for_manufacturing>=doc.qty) { - // all materials transferred for manufacturing, make this primary - finish_btn.addClass('btn-primary'); + if (counter > 0) { + var consumption_btn = frm.add_custom_button(__('Material Consumption'), function() { + const backflush_raw_materials_based_on = frm.doc.__onload.backflush_raw_materials_based_on; + erpnext.work_order.make_consumption_se(frm, backflush_raw_materials_based_on); + }); + consumption_btn.addClass('btn-primary'); } } - }) + + var finish_btn = frm.add_custom_button(__('Finish'), function() { + erpnext.work_order.make_se(frm, 'Manufacture'); + }); + + if(doc.material_transferred_for_manufacturing>=doc.qty) { + // all materials transferred for manufacturing, make this primary + finish_btn.addClass('btn-primary'); + } + } } else { if ((flt(doc.produced_qty) < flt(doc.qty)) && frm.doc.status != 'Stopped') { var finish_btn = frm.add_custom_button(__('Finish'), function() { diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index 1624bb989c..62091ffd69 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -31,6 +31,12 @@ form_grid_templates = { } class WorkOrder(Document): + def onload(self): + ms = frappe.get_doc("Manufacturing Settings") + self.set_onload("material_consumption", ms.material_consumption) + self.set_onload("backflush_raw_materials_based_on", ms.backflush_raw_materials_based_on) + + def validate(self): self.validate_production_item() if self.bom_no: