From 7477899d2e3d4291a00fe65cef4325177a29fc1f Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 12 Feb 2018 11:25:58 +0530 Subject: [PATCH] Formatter, code cleanup (#12852) --- .../doctype/purchase_invoice/purchase_invoice.js | 8 ++++---- erpnext/buying/doctype/purchase_order/purchase_order.js | 6 +++--- .../doctype/supplier_scorecard/supplier_scorecard.js | 6 +++--- .../doctype/production_order/production_order.js | 8 ++++---- erpnext/selling/doctype/sales_order/sales_order.js | 8 ++++---- .../stock/doctype/material_request/material_request.js | 9 ++++----- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js index de0b6f5add..26cc59892f 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -8,6 +8,10 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({ setup: function(doc) { this.setup_posting_date_time_check(); this._super(doc); + + // formatter for material request item + this.frm.set_indicator_formatter('item_code', + function(doc) { return (doc.qty<=doc.received_qty) ? "green" : "orange" }) }, onload: function() { this._super(); @@ -20,10 +24,6 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({ } else { this.frm.set_value("disable_rounded_total", cint(frappe.sys_defaults.disable_rounded_total)); } - - // formatter for material request item - this.frm.set_indicator_formatter('item_code', - function(doc) { return (doc.qty<=doc.received_qty) ? "green" : "orange" }) }, refresh: function(doc) { diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index ab8ab03dbf..d012dee730 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -12,6 +12,9 @@ frappe.ui.form.on("Purchase Order", { 'Purchase Invoice': 'Invoice', 'Stock Entry': 'Material to Supplier' } + + frm.set_indicator_formatter('item_code', + function(doc) { return (doc.qty<=doc.received_qty) ? "green" : "orange" }) }, onload: function(frm) { @@ -25,9 +28,6 @@ frappe.ui.form.on("Purchase Order", { 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/supplier_scorecard/supplier_scorecard.js b/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.js index a3a14147f2..e7a704a28a 100644 --- a/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.js +++ b/erpnext/buying/doctype/supplier_scorecard/supplier_scorecard.js @@ -4,14 +4,14 @@ /* global frappe, refresh_field */ frappe.ui.form.on("Supplier Scorecard", { - - onload: function(frm) { - + setup: function(frm) { if (frm.doc.indicator_color !== "") { frm.set_indicator_formatter("status", function(doc) { return doc.indicator_color.toLowerCase(); }); } + }, + onload: function(frm) { if (frm.doc.__unsaved == 1) { loadAllCriteria(frm); loadAllStandings(frm); diff --git a/erpnext/manufacturing/doctype/production_order/production_order.js b/erpnext/manufacturing/doctype/production_order/production_order.js index 8a86668fcd..bba3e1ed6d 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.js +++ b/erpnext/manufacturing/doctype/production_order/production_order.js @@ -79,6 +79,10 @@ frappe.ui.form.on("Production Order", { ] } }); + + // formatter for production order operation + frm.set_indicator_formatter('operation', + function(doc) { return (frm.doc.qty==doc.completed_qty) ? "green" : "orange" }); }, onload: function(frm) { @@ -94,10 +98,6 @@ frappe.ui.form.on("Production Order", { }); erpnext.production_order.set_default_warehouse(frm); } - - // formatter for production order operation - frm.set_indicator_formatter('operation', - function(doc) { return (frm.doc.qty==doc.completed_qty) ? "green" : "orange" }); }, refresh: function(frm) { diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js index a6133c877a..a9eb7dbac1 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.js +++ b/erpnext/selling/doctype/sales_order/sales_order.js @@ -13,6 +13,10 @@ frappe.ui.form.on("Sales Order", { 'Project': 'Project' } frm.add_fetch('customer', 'tax_id', 'tax_id'); + + // formatter for material request item + frm.set_indicator_formatter('item_code', + function(doc) { return (doc.stock_qty<=doc.delivered_qty) ? "green" : "orange" }) }, onload: function(frm) { erpnext.queries.setup_queries(frm, "Warehouse", function() { @@ -28,10 +32,6 @@ frappe.ui.form.on("Sales Order", { } }); - // formatter for material request item - frm.set_indicator_formatter('item_code', - function(doc) { return (doc.stock_qty<=doc.delivered_qty) ? "green" : "orange" }) - erpnext.queries.setup_warehouse_query(frm); }, diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js index ed0597cd98..709c2c7d19 100644 --- a/erpnext/stock/doctype/material_request/material_request.js +++ b/erpnext/stock/doctype/material_request/material_request.js @@ -12,6 +12,10 @@ frappe.ui.form.on('Material Request', { 'Supplier Quotation': 'Supplier Quotation', 'Production Order': 'Production Order' } + + // formatter for material request item + frm.set_indicator_formatter('item_code', + function(doc) { return (doc.qty<=doc.ordered_qty) ? "green" : "orange" }) }, onload: function(frm) { // add item, if previous view was item @@ -19,11 +23,6 @@ frappe.ui.form.on('Material Request', { //set schedule_date set_schedule_date(frm); - - // formatter for material request item - frm.set_indicator_formatter('item_code', - function(doc) { return (doc.qty<=doc.ordered_qty) ? "green" : "orange" }), - frm.fields_dict["items"].grid.get_field("warehouse").get_query = function(doc, cdt, cdn){ return{ filters: {'company': doc.company}