[get_query]to server side

This commit is contained in:
Saurabh
2013-07-09 16:18:52 +05:30
parent ebe50397d9
commit ab462d2000
52 changed files with 692 additions and 314 deletions

View File

@@ -122,8 +122,15 @@ cur_frm.cscript.make_contact = function() {
}
cur_frm.fields_dict['customer_group'].get_query = function(doc,dt,dn) {
return 'SELECT `tabCustomer Group`.`name`, `tabCustomer Group`.`parent_customer_group` FROM `tabCustomer Group` WHERE `tabCustomer Group`.`is_group` = "No" AND `tabCustomer Group`.`docstatus`!= 2 AND `tabCustomer Group`.%(key)s LIKE "%s" ORDER BY `tabCustomer Group`.`name` ASC LIMIT 50';
return{
filters:{'is_group': 'No'}
}
// return 'SELECT `tabCustomer Group`.`name`, `tabCustomer Group`.`parent_customer_group` FROM `tabCustomer Group` WHERE `tabCustomer Group`.`is_group` = "No" AND `tabCustomer Group`.`docstatus`!= 2 AND `tabCustomer Group`.%(key)s LIKE "%s" ORDER BY `tabCustomer Group`.`name` ASC LIMIT 50';
}
cur_frm.fields_dict.lead_name.get_query = erpnext.utils.lead_query;
cur_frm.fields_dict.lead_name.get_query = function(doc,cdt,cdn) {
return{
query:"controllers.queries.lead_query"
}
}

View File

@@ -62,16 +62,27 @@ cur_frm.cscript.onload = function(doc, dt, dn) {
cur_frm.fields_dict['delivery_note_no'].get_query = function(doc) {
doc = locals[this.doctype][this.docname];
var cond = '';
if(doc.customer) {
cond = '`tabDelivery Note`.customer = "'+doc.customer+'" AND';
var filter = {
'company': doc.company,
'docstatus': 1,
'per_installed': 99.99
};
if(doc.customer) filter['customer'] = doc.customer;
return{
filters:filter
}
return repl('SELECT DISTINCT `tabDelivery Note`.name, `tabDelivery Note`.customer_name FROM `tabDelivery Note`, `tabDelivery Note Item` WHERE `tabDelivery Note`.company = "%(company)s" AND `tabDelivery Note`.docstatus = 1 AND ifnull(`tabDelivery Note`.per_installed,0) < 99.99 AND %(cond)s `tabDelivery Note`.name LIKE "%s" ORDER BY `tabDelivery Note`.name DESC LIMIT 50', {company:doc.company, cond:cond});
// {
// cond = '`tabDelivery Note`.customer = "'+doc.customer+'" AND';
// }
// return repl('SELECT DISTINCT `tabDelivery Note`.name, `tabDelivery Note`.customer_name FROM `tabDelivery Note`, `tabDelivery Note Item` WHERE `tabDelivery Note`.company = "%(company)s" AND `tabDelivery Note`.docstatus = 1 AND ifnull(`tabDelivery Note`.per_installed,0) < 99.99 AND %(cond)s `tabDelivery Note`.name LIKE "%s" ORDER BY `tabDelivery Note`.name DESC LIMIT 50', {company:doc.company, cond:cond});
}
cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';
return{
filters{ 'is_group': "No" }
}
// return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';
}
cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
@@ -79,11 +90,21 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc
}
cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
return{
filters: { 'customer': doc.customer }
}
// return 'SELECT name,address_line1,city FROM tabAddress WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
}
cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
return{
filters: { 'customer': doc.customer }
}
// return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
}
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
return{
query:"controllers.queries.customer_query"
}
}

View File

@@ -20,16 +20,19 @@ wn.require('app/setup/doctype/contact_control/contact_control.js');
wn.provide("erpnext");
erpnext.LeadController = wn.ui.form.Controller.extend({
setup: function() {
this.frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
this.frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
return { query:"controllers.queries.customer_query" } }
},
onload: function() {
if(cur_frm.fields_dict.lead_owner.df.options.match(/^Profile/)) {
cur_frm.fields_dict.lead_owner.get_query = erpnext.utils.profile_query;
cur_frm.fields_dict.lead_owner.get_query = function(doc,cdt,cdn) {
return { query:"controllers.queries.profile_query" } }
}
if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) {
cur_frm.fields_dict.contact_by.get_query = erpnext.utils.profile_query;
cur_frm.fields_dict.contact_by.get_query = function(doc,cdt,cdn) {
return { query:"controllers.queries.profile_query" } }
}
if(in_list(user_roles,'System Manager')) {

View File

@@ -109,7 +109,8 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
}
if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) {
cur_frm.fields_dict.contact_by.get_query = erpnext.utils.profile_query;
cur_frm.fields_dict.contact_by.get_query = function(doc,cdt,cdn) {
return { query:"controllers.queries.profile_query" } }
}
if(doc.customer && !doc.customer_name) cur_frm.cscript.customer(doc);
@@ -153,23 +154,30 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc
}
cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
return 'SELECT name, address_line1, city FROM tabAddress \
WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND \
%(key)s LIKE "%s" ORDER BY name ASC LIMIT 50';
return {
filters:{'customer':doc.customer}
}
// return 'SELECT name, address_line1, city FROM tabAddress \
// WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND \
// %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50';
}
cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
if (!doc.customer) msgprint("Please select customer first");
else {
return 'SELECT name, CONCAT(first_name," ",ifnull(last_name,"")) As FullName, \
department, designation FROM tabContact WHERE customer = "'+ doc.customer +
'" AND docstatus != 2 AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50';
filters:{'customer':doc.customer}
// return 'SELECT name, CONCAT(first_name," ",ifnull(last_name,"")) As FullName, \
// department, designation FROM tabContact WHERE customer = "'+ doc.customer +
// '" AND docstatus != 2 AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50';
}
}
// lead
cur_frm.fields_dict['lead'].get_query = function(doc,cdt,cdn){
return 'SELECT `tabLead`.name, `tabLead`.lead_name FROM `tabLead` WHERE `tabLead`.%(key)s LIKE "%s" ORDER BY `tabLead`.`name` ASC LIMIT 50';
return {
query: "selling.doctype.opportunity.opportunity.get_lead"
}
// return 'SELECT `tabLead`.name, `tabLead`.lead_name FROM `tabLead` WHERE `tabLead`.%(key)s LIKE "%s" ORDER BY `tabLead`.`name` ASC LIMIT 50';
}
cur_frm.cscript.lead = function(doc, cdt, cdn) {
@@ -185,14 +193,17 @@ cur_frm.cscript.lead = function(doc, cdt, cdn) {
}
cur_frm.fields_dict['enquiry_details'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
if (doc.enquiry_type == 'Maintenance')
return erpnext.queries.item({
'ifnull(tabItem.is_service_item, "No")': 'Yes'
});
else
return erpnext.queries.item({
'ifnull(tabItem.is_sales_item, "No")': 'Yes'
});
if (doc.enquiry_type == 'Maintenance') {
return {
query:"controllers.queries.item_query",
filters:{ 'is_service_item': 'Yes' }
}
} else {
return {
query:"controllers.queries.item_query",
filters:{ 'is_sales_item': 'Yes' }
}
}
}
cur_frm.cscript['Declare Opportunity Lost'] = function(){
@@ -229,8 +240,13 @@ cur_frm.cscript['Declare Opportunity Lost'] = function(){
//get query select Territory
cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';}
return{
filters:{'is_group': 'No'}
}
// return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';}
cur_frm.fields_dict.lead.get_query = erpnext.utils.lead_query;
cur_frm.fields_dict.lead.get_query = function(doc,cdt,cdn) {
return { query:"controllers.queries.lead_query" } }
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
return { query:"controllers.queries.customer_query" } }

View File

@@ -202,4 +202,13 @@ def make_quotation(source_name, target_doclist=None):
}
}, target_doclist)
return [d.fields for d in doclist]
return [d.fields for d in doclist]
def get_lead(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond
return webnotes.conn.sql ("""select `tabLead`.name, `tabLead`.lead_name FROM `tabLead`
where `tabLead`.%(key)s like "%(txt)s" %(mcond)s
order by `tabLead`.`name` asc limit %(start)s, %(page_len)s
""" % {'key': searchfield, 'txt': "%%%s%%" % txt,
'mcond':get_match_cond(doctype, searchfield),
'start': start, 'page_len': page_len})

View File

@@ -118,7 +118,8 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc
}),'', doc, dt, dn, 1);
}
cur_frm.fields_dict.lead.get_query = erpnext.utils.lead_query;
cur_frm.fields_dict.lead.get_query = function(doc,cdt,cdn) {
return{ query:"controllers.queries.lead_query" } }
cur_frm.cscript.lead = function(doc, cdt, cdn) {
if(doc.lead) {
@@ -186,45 +187,22 @@ cur_frm.fields_dict['quotation_details'].grid.get_field('item_code').get_query=
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 repl("\
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 \
item.%(key)s like \"%s\" \
%(cond)s \
limit 25", {
cust: doc.customer,
cond: cond,
precision: precision
});
return {
query: "selling.doctype.quotation.quotation.quotation_details",
filters:{
cust: doc.customer,
cond: cond,
precision: precision
}
}
} else {
return repl("SELECT name, item_name, description FROM `tabItem` item WHERE item.%(key)s LIKE '%s' %(cond)s ORDER BY item.item_code DESC LIMIT 50", {cond:cond});
return {
query: 'selling.doctype.quotation.quotation.quotation_details',
filters:{
cond: cond,
}
}
// return repl("SELECT name, item_name, description FROM `tabItem` item WHERE item.%(key)s LIKE '%s' %(cond)s ORDER BY item.item_code DESC LIMIT 50", {cond:cond});
}
}

View File

@@ -259,4 +259,33 @@ def make_sales_order(source_name, target_doclist=None):
# postprocess: fetch shipping address, set missing values
return [d.fields for d in doclist]
return [d.fields for d in doclist]
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:
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

@@ -24,9 +24,12 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
}
cur_frm.fields_dict.new_item_code.get_query = function() {
return 'select name, description from tabItem where is_stock_item="No" and is_sales_item="Yes"\
and name not in (select name from `tabSales BOM`)\
and `%(key)s` like "%s"'
return{
query: "selling.doctype.sales_bom.sales_bom.get_new_item_code"
}
// return 'select name, description from tabItem where is_stock_item="No" and is_sales_item="Yes"\
// and name not in (select name from `tabSales BOM`)\
// and `%(key)s` like "%s"'
}
cur_frm.fields_dict.new_item_code.query_description = 'Select Item where "Is Stock Item" is "No" \
and "Is Sales Item" is "Yes" and there is no other Sales BOM';

View File

@@ -83,3 +83,13 @@ class DocType:
if l not in l2:
return 0
return 1
def get_new_item_code(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond
return webnotes.conn.sql("""select name, description from tabItem
where is_stock_item="No" and is_sales_item="Yes"
and name not in (select name from `tabSales BOM`) and %s like "%s"
%s limit %s, %s""" % (searchfield, "%s",
get_match_cond(doctype, searchfield),"%s", "%s"),
("%%%s%%" % txt, start, page_len))

View File

@@ -59,7 +59,8 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
});
}
this.frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
this.frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
return{ query:"controllers.queries.customer_query" } }
this.frm.fields_dict.lead && this.frm.set_query("lead", erpnext.utils.lead_query);

View File

@@ -154,12 +154,12 @@ cur_frm.cscript.new_contact = function(){
}
cur_frm.fields_dict['project_name'].get_query = function(doc, cdt, cdn) {
var cond = '';
if(doc.customer) cond = '(`tabProject`.customer = "'+doc.customer+'" OR IFNULL(`tabProject`.customer,"")="") AND';
return repl('SELECT `tabProject`.name FROM `tabProject` \
WHERE `tabProject`.status not in ("Completed", "Cancelled") \
AND %(cond)s `tabProject`.name LIKE "%s" \
ORDER BY `tabProject`.name ASC LIMIT 50', {cond:cond});
return {
query: "controllers.queries.get_project_name",
filters: {
'customer': doc.customer
}
}
}
cur_frm.cscript['Stop Sales Order'] = function() {
@@ -193,7 +193,9 @@ cur_frm.cscript['Unstop Sales Order'] = function() {
}
cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';
return{
filters:{ 'is_group': "No"}
}
}
cur_frm.cscript.on_submit = function(doc, cdt, cdn) {