From 9b4961400a23a9dc28cf4e8e90d8591834694ab6 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 11 Jul 2013 19:13:58 +0530 Subject: [PATCH] [minor] [fix] get queries --- .../purchase_common/purchase_common.js | 16 +++----- selling/doctype/quotation/quotation.js | 30 +-------------- selling/doctype/quotation/quotation.py | 38 ------------------- selling/doctype/sales_common/sales_common.js | 26 +++++++------ utilities/transaction_base.py | 2 +- 5 files changed, 22 insertions(+), 90 deletions(-) diff --git a/buying/doctype/purchase_common/purchase_common.js b/buying/doctype/purchase_common/purchase_common.js index ada4beb2ebf..bf2cbce91f6 100644 --- a/buying/doctype/purchase_common/purchase_common.js +++ b/buying/doctype/purchase_common/purchase_common.js @@ -23,7 +23,11 @@ wn.provide("erpnext.buying"); wn.require("app/js/transaction.js"); erpnext.buying.BuyingController = erpnext.TransactionController.extend({ - setup: function() { + onload: function() { + this.setup_queries(); + }, + + setup_queries: function() { var me = this; if(this.frm.fields_dict.price_list_name) { @@ -473,15 +477,5 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ } }); -// to save previous state of cur_frm.cscript -var prev_cscript = {}; -$.extend(prev_cscript, cur_frm.cscript); - -cur_frm.cscript = new erpnext.buying.BuyingController({frm: cur_frm}); - -// for backward compatibility: combine new and previous states -$.extend(cur_frm.cscript, prev_cscript); - - var tname = cur_frm.cscript.tname; var fname = cur_frm.cscript.fname; diff --git a/selling/doctype/quotation/quotation.js b/selling/doctype/quotation/quotation.js index 0649f545127..f1082712499 100644 --- a/selling/doctype/quotation/quotation.js +++ b/selling/doctype/quotation/quotation.js @@ -15,12 +15,12 @@ // along with this program. If not, see . // Module CRM +// ===================================================================================== cur_frm.cscript.tname = "Quotation Item"; cur_frm.cscript.fname = "quotation_details"; cur_frm.cscript.other_fname = "other_charges"; cur_frm.cscript.sales_team_fname = "sales_team"; -// ===================================================================================== wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js'); wn.require('app/utilities/doctype/sms_control/sms_control.js'); wn.require('app/selling/doctype/sales_common/sales_common.js'); @@ -107,8 +107,7 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({ }, }); -// for backward compatibility: combine new and previous states -$.extend(cur_frm.cscript, new erpnext.selling.QuotationController({frm: cur_frm})); +cur_frm.script_manager.make(erpnext.selling.QuotationController); cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) { if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({ @@ -180,31 +179,6 @@ cur_frm.cscript['Declare Order Lost'] = function(){ } -//================ Last Quoted Price and Last Sold Price suggestion ====================== -cur_frm.fields_dict['quotation_details'].grid.get_field('item_code').get_query= function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; - var cond = (doc.order_type == 'Maintenance') ? " and item.is_service_item = 'Yes'" : " and item.is_sales_item = 'Yes'"; - if(doc.customer) { - var export_rate_field = wn.meta.get_docfield(cdt, 'export_rate', cdn); - var precision = (export_rate_field && export_rate_field.fieldtype) === 'Float' ? 6 : 2; - return { - query: "selling.doctype.quotation.quotation.quotation_details", - filters:{ - cust: doc.customer, - cond: cond, - precision: precision - } - } - } else { - return { - query: 'selling.doctype.quotation.quotation.quotation_details', - filters:{ - cond: cond - } - } - } -} - cur_frm.cscript.on_submit = function(doc, cdt, cdn) { if(cint(wn.boot.notification_settings.quotation)) { cur_frm.email_doc(wn.boot.notification_settings.quotation_message); diff --git a/selling/doctype/quotation/quotation.py b/selling/doctype/quotation/quotation.py index ee4975d4694..f1e11a0ee8a 100644 --- a/selling/doctype/quotation/quotation.py +++ b/selling/doctype/quotation/quotation.py @@ -286,41 +286,3 @@ def _make_customer(source_name, ignore_permissions=False): return customer else: raise e - -def quotation_details(doctype, txt, searchfield, start, page_len, filters): - from controllers.queries import get_match_cond - - if filters.has_key('cust') and filters.has_key('precision'): - return webnotes.conn.sql("""select item.name, - (select concat('Last Quote @ ', q.currency, ' ', - format(q_item.export_rate, %(precision)s)) - from `tabQuotation` q, `tabQuotation Item` q_item - where q.name = q_item.parent - and q_item.item_code = item.name - and q.docstatus = 1 - and q.customer = "%(cust)s" - order by q.transaction_date desc - limit 1) as quote_rate, - (select concat('Last Sale @ ', si.currency, ' ', - format(si_item.basic_rate, %(precision)s)) - from `tabSales Invoice` si, `tabSales Invoice Item` si_item - where si.name = si_item.parent - and si_item.item_code = item.name - and si.docstatus = 1 - and si.customer ="%(cust)s" - order by si.posting_date desc - limit 1) as sales_rate, - item.item_name, item.description - from `tabItem` item - where %(cond)s %(mcond)s - and item.%(searchfield)s like '%(txt)s' - order by item.name desc limit %(start)s, %(page_len)s """ % {'precision': filters["precision"], - 'cust': filters['cust'], 'cond': filters['cond'], 'searchfield': searchfield, - 'txt': "%%%s%%" % txt, 'mcond': get_match_cond(doctype, searchfield), - 'start': start, 'page_len': page_len}) - - else: - return webnotes.conn.sql(""" select name, item_name, description from `tabItem` item - where %s %s and %s like %s order by name desc limit %s, %s""" % - ("%s", get_match_cond(doctype, searchfield), searchfield, "%s", "%s", "%s"), - (filters["cond"], "%%%s%%" % txt, start, page_len)) diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js index 8d869501f2c..01ea8f53bb3 100644 --- a/selling/doctype/sales_common/sales_common.js +++ b/selling/doctype/sales_common/sales_common.js @@ -25,7 +25,13 @@ wn.provide("erpnext.selling"); wn.require("app/js/transaction.js"); erpnext.selling.SellingController = erpnext.TransactionController.extend({ - setup: function() { + onload: function() { + this._super(); + this.toggle_rounded_total(); + this.setup_queries(); + }, + + setup_queries: function() { var me = this; this.frm.add_fetch("sales_partner", "commission_rate", "commission_rate"); @@ -64,18 +70,19 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ this.frm.fields_dict.lead && this.frm.set_query("lead", function(doc,cdt,cdn) { return{ query:"controllers.queries.lead_query" } }); - + if(!this.fname) { return; } if(this.frm.fields_dict[this.fname].grid.get_field('item_code')) { this.frm.set_query("item_code", this.fname, function() { - return me.frm.doc.order_type === "Maintenance" ? - { query:"controllers.queries.item_query", - filters:{'is_service_item': 'Yes'}} : - { query:"controllers.queries.item_query", - filters:{'is_sales_item': 'Yes' }} ; + return { + query: "controllers.queries.item_query", + filters: (me.frm.doc.order_type === "Maintenance" ? + {'is_service_item': 'Yes'}: + {'is_sales_item': 'Yes' }) + } }); } @@ -108,11 +115,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ } }, - onload: function() { - this._super(); - this.toggle_rounded_total(); - }, - refresh: function(doc) { this.frm.toggle_display("customer_name", (this.customer_name && this.frm.doc.customer_name!==this.frm.doc.customer)); diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py index cbcd4886cb9..8fa99b8820c 100644 --- a/utilities/transaction_base.py +++ b/utilities/transaction_base.py @@ -90,7 +90,7 @@ class TransactionBase(StatusUpdater): """ customer_defaults = self.get_customer_defaults() - customer_defaults["price_list"] = customer_defaults["price_list"] or \ + customer_defaults["price_list"] = customer_defaults.get("price_list") or \ webnotes.conn.get_value("Customer Group", self.doc.customer_group, "default_price_list") or \ self.doc.price_list