[minor] [fix] get queries

This commit is contained in:
Anand Doshi 2013-07-11 19:13:58 +05:30
parent 34736c8d87
commit 9b4961400a
5 changed files with 22 additions and 90 deletions

View File

@ -23,7 +23,11 @@ wn.provide("erpnext.buying");
wn.require("app/js/transaction.js"); wn.require("app/js/transaction.js");
erpnext.buying.BuyingController = erpnext.TransactionController.extend({ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
setup: function() { onload: function() {
this.setup_queries();
},
setup_queries: function() {
var me = this; var me = this;
if(this.frm.fields_dict.price_list_name) { 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 tname = cur_frm.cscript.tname;
var fname = cur_frm.cscript.fname; var fname = cur_frm.cscript.fname;

View File

@ -15,12 +15,12 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// Module CRM // Module CRM
// =====================================================================================
cur_frm.cscript.tname = "Quotation Item"; cur_frm.cscript.tname = "Quotation Item";
cur_frm.cscript.fname = "quotation_details"; cur_frm.cscript.fname = "quotation_details";
cur_frm.cscript.other_fname = "other_charges"; cur_frm.cscript.other_fname = "other_charges";
cur_frm.cscript.sales_team_fname = "sales_team"; 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/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/utilities/doctype/sms_control/sms_control.js');
wn.require('app/selling/doctype/sales_common/sales_common.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 cur_frm.script_manager.make(erpnext.selling.QuotationController);
$.extend(cur_frm.cscript, new erpnext.selling.QuotationController({frm: cur_frm}));
cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) { 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({ 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) { cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
if(cint(wn.boot.notification_settings.quotation)) { if(cint(wn.boot.notification_settings.quotation)) {
cur_frm.email_doc(wn.boot.notification_settings.quotation_message); cur_frm.email_doc(wn.boot.notification_settings.quotation_message);

View File

@ -286,41 +286,3 @@ def _make_customer(source_name, ignore_permissions=False):
return customer return customer
else: else:
raise e 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))

View File

@ -25,7 +25,13 @@ wn.provide("erpnext.selling");
wn.require("app/js/transaction.js"); wn.require("app/js/transaction.js");
erpnext.selling.SellingController = erpnext.TransactionController.extend({ 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; var me = this;
this.frm.add_fetch("sales_partner", "commission_rate", "commission_rate"); 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) { this.frm.fields_dict.lead && this.frm.set_query("lead", function(doc,cdt,cdn) {
return{ query:"controllers.queries.lead_query" } }); return{ query:"controllers.queries.lead_query" } });
if(!this.fname) { if(!this.fname) {
return; return;
} }
if(this.frm.fields_dict[this.fname].grid.get_field('item_code')) { if(this.frm.fields_dict[this.fname].grid.get_field('item_code')) {
this.frm.set_query("item_code", this.fname, function() { this.frm.set_query("item_code", this.fname, function() {
return me.frm.doc.order_type === "Maintenance" ? return {
{ query:"controllers.queries.item_query", query: "controllers.queries.item_query",
filters:{'is_service_item': 'Yes'}} : filters: (me.frm.doc.order_type === "Maintenance" ?
{ query:"controllers.queries.item_query", {'is_service_item': 'Yes'}:
filters:{'is_sales_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) { refresh: function(doc) {
this.frm.toggle_display("customer_name", this.frm.toggle_display("customer_name",
(this.customer_name && this.frm.doc.customer_name!==this.frm.doc.customer)); (this.customer_name && this.frm.doc.customer_name!==this.frm.doc.customer));

View File

@ -90,7 +90,7 @@ class TransactionBase(StatusUpdater):
""" """
customer_defaults = self.get_customer_defaults() 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 \ webnotes.conn.get_value("Customer Group", self.doc.customer_group, "default_price_list") or \
self.doc.price_list self.doc.price_list