From 86cbde90571bd85c23f5ed0ddf6b6a17147da9bc Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 19 Jan 2018 12:40:27 +0530 Subject: [PATCH] [Fix] Error in PO. No Permission for Buying Settings --- erpnext/buying/doctype/purchase_order/purchase_order.js | 8 ++++---- erpnext/buying/doctype/purchase_order/purchase_order.py | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index fe8642c311..ab8ab03dbf 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -21,10 +21,10 @@ frappe.ui.form.on("Purchase Order", { return erpnext.queries.warehouse(frm.doc); }); - frappe.db.get_value('Buying Settings', {name: 'Buying Settings'}, 'disable_fetch_last_purchase_rate', (r) => { - value = r && cint(r.disable_fetch_last_purchase_rate); - frm.toggle_display('get_last_purchase_rate', !value); - }); + if (frm.doc.__onload) { + frm.toggle_display('get_last_purchase_rate', + frm.doc.__onload.disable_fetch_last_purchase_rate); + } frm.set_indicator_formatter('item_code', function(doc) { return (doc.qty<=doc.received_qty) ? "green" : "orange" }) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index 1929476cf3..db13bd5520 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -34,6 +34,12 @@ class PurchaseOrder(BuyingController): 'overflow_type': 'order' }] + def onload(self): + super(PurchaseOrder, self).onload() + + self.set_onload('disable_fetch_last_purchase_rate', + cint(frappe.db.get_single_value("Buying Settings", "disable_fetch_last_purchase_rate"))) + def validate(self): super(PurchaseOrder, self).validate()