[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

@@ -65,24 +65,34 @@ 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['serial_no'].get_query = function(doc, cdt, cdn) {
var cond = '';
if(doc.item_code) cond = ' AND `tabSerial No`.item_code = "'+ doc.item_code +'"';
if(doc.customer) cond += ' AND `tabSerial No`.customer = "' + doc.customer + '"';
return 'SELECT `tabSerial No`.name, `tabSerial No`.description \
FROM `tabSerial No` \
WHERE `tabSerial No`.docstatus != 2 AND `tabSerial No`.status = "Delivered" \
AND `tabSerial No`.name LIKE "%s" ' + cond + ' ORDER BY `tabSerial No`.name ASC LIMIT 50';
var cond = [];
var filter = [
['Serial No', 'docstatus', '!=', 2],
['Serial No', 'status', '=', "Delivered"]
];
if(doc.item_code) cond = ['Serial No', 'item_code', '=', doc.item_code];
if(doc.customer) cond = ['Serial No', 'customer', '=', doc.customer];
filter.push(cond);
return{
filters:filter
}
}
cur_frm.add_fetch('serial_no', 'item_code', 'item_code');
@@ -97,15 +107,23 @@ cur_frm.add_fetch('serial_no', 'delivery_address', 'customer_address');
cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) {
if(doc.serial_no) {
return 'SELECT `tabSerial No`.item_code, `tabSerial No`.description \
FROM `tabSerial No` \
WHERE `tabSerial No`.docstatus != 2 AND `tabSerial No`.name = "' + doc.serial_no +
'" AND `tabSerial No`.item_code LIKE "%s" ORDER BY `tabSerial No`.item_code ASC LIMIT 50';
return{
filters:{ 'serial_no': doc.serial_no}
}
// return 'SELECT `tabSerial No`.item_code, `tabSerial No`.description \
// FROM `tabSerial No` \
// WHERE `tabSerial No`.docstatus != 2 AND `tabSerial No`.name = "' + doc.serial_no +
// '" AND `tabSerial No`.item_code LIKE "%s" ORDER BY `tabSerial No`.item_code ASC LIMIT 50';
}
else{
return 'SELECT `tabItem`.name, `tabItem`.item_name, `tabItem`.description \
FROM `tabItem` \
WHERE `tabItem`.docstatus != 2 AND `tabItem`.%(key)s LIKE "%s" ORDER BY `tabItem`.name ASC LIMIT 50';
return{
filters:[
['Item', 'docstatus', '!=', 2]
]
}
// return 'SELECT `tabItem`.name, `tabItem`.item_name, `tabItem`.description \
// FROM `tabItem` \
// WHERE `tabItem`.docstatus != 2 AND `tabItem`.%(key)s LIKE "%s" ORDER BY `tabItem`.name ASC LIMIT 50';
}
}
@@ -113,10 +131,14 @@ cur_frm.add_fetch('item_code', 'item_name', 'item_name');
cur_frm.add_fetch('item_code', 'description', 'description');
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.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

@@ -62,16 +62,22 @@ 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}
}
}
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}
}
}
//
cur_frm.fields_dict['item_maintenance_detail'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
return 'SELECT tabItem.name,tabItem.item_name,tabItem.description FROM tabItem WHERE tabItem.is_service_item="Yes" AND tabItem.docstatus != 2 AND tabItem.%(key)s LIKE "%s" LIMIT 50';
return{
filters:{ 'is_service_item': "Yes"}
}
}
cur_frm.cscript.item_code = function(doc, cdt, cdn) {
@@ -88,7 +94,13 @@ cur_frm.fields_dict['sales_order_no'].get_query = function(doc) {
if(doc.customer) {
cond = '`tabSales Order`.customer = "'+doc.customer+'" AND';
}
return repl('SELECT DISTINCT `tabSales Order`.name FROM `tabSales Order`, `tabSales Order Item`, `tabItem` WHERE `tabSales Order`.company = "%(company)s" AND `tabSales Order`.docstatus = 1 AND `tabSales Order Item`.parent = `tabSales Order`.name AND `tabSales Order Item`.item_code = `tabItem`.name AND `tabItem`.is_service_item = "Yes" AND %(cond)s `tabSales Order`.name LIKE "%s" ORDER BY `tabSales Order`.name DESC LIMIT 50', {company:doc.company, cond:cond});
return{
query:"support.doctype.maintenance_schedule.maintenance_schedule.get_sales_order_no",
filters: {
'cond': cond,
'company': doc.company
}
}
}
cur_frm.cscript.periodicity = function(doc, cdt, cdn){
@@ -118,7 +130,10 @@ cur_frm.cscript.generate_schedule = function(doc, cdt, cdn) {
}
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.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

@@ -331,4 +331,16 @@ def make_maintenance_visit(source_name, target_doclist=None):
}
}, target_doclist)
return [d.fields for d in doclist]
return [d.fields for d in doclist]
def get_sales_order_no(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond
return webnotes.conn.sql(""" select distinct `tabSales Order`.name from `tabSales Order`,
`tabSales Order Item`, `tabItem`
where `tabSales Order`.company = "%(company)s" and `tabSales Order`.docstatus = 1
and `tabSales Order Item`.parent = `tabSales Order`.name
and `tabSales Order Item`.item_code = `tabItem`.name
and `tabItem`.is_service_item = "Yes" and %(cond)s `tabSales Order`.name LIKE "%(txt)s" %(mcond)s
ORDER BY `tabSales Order`.name desc LIMIT %(start)s, %(page_len)s"""
% 'company': filters["company"], 'cond': filters['cond'], 'txt': "%%%s%%" % txt,
'mcond':get_match_cond(doctype, searchfield), "start": start, "page_len": page_len})

View File

@@ -77,11 +77,15 @@ 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}
}
}
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}
}
}
cur_frm.cscript.get_items = function(doc, dt, dn) {
@@ -93,7 +97,9 @@ cur_frm.cscript.get_items = function(doc, dt, dn) {
}
cur_frm.fields_dict['maintenance_visit_details'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
return 'SELECT tabItem.name,tabItem.item_name,tabItem.description FROM tabItem WHERE tabItem.is_service_item="Yes" AND tabItem.docstatus != 2 AND tabItem.%(key)s LIKE "%s" LIMIT 50';
return{
filters:{ 'is_service_item': "Yes"}
}
}
cur_frm.cscript.item_code = function(doc, cdt, cdn) {
@@ -110,30 +116,52 @@ cur_frm.fields_dict['sales_order_no'].get_query = function(doc) {
if(doc.customer) {
cond = '`tabSales Order`.customer = "'+doc.customer+'" AND';
}
return repl('SELECT DISTINCT `tabSales Order`.name FROM `tabSales Order`, `tabSales Order Item`, `tabItem` WHERE `tabSales Order`.company = "%(company)s" AND `tabSales Order`.docstatus = 1 AND `tabSales Order Item`.parent = `tabSales Order`.name AND `tabSales Order Item`.item_code = `tabItem`.name AND `tabItem`.is_service_item = "Yes" AND %(cond)s `tabSales Order`.name LIKE "%s" ORDER BY `tabSales Order`.name DESC LIMIT 50', {company:doc.company, cond:cond});
return{
query:"support.doctype.maintenance_schedule.maintenance_schedule.get_sales_order_no",
filters: {
'cond': cond,
'company': doc.company
}
}
}
cur_frm.fields_dict['customer_issue_no'].get_query = function(doc) {
doc = locals[this.doctype][this.docname];
var cond = '';
if(doc.customer) {
cond = '`tabCustomer Issue`.customer = "'+doc.customer+'" AND';
}
return repl('SELECT `tabCustomer Issue`.name FROM `tabCustomer Issue` WHERE `tabCustomer Issue`.company = "%(company)s" AND %(cond)s `tabCustomer Issue`.docstatus = 1 AND (`tabCustomer Issue`.status = "Open" OR `tabCustomer Issue`.status = "Work In Progress") AND `tabCustomer Issue`.name LIKE "%s" ORDER BY `tabCustomer Issue`.name DESC LIMIT 50', {company:doc.company, cond:cond});
var cond = [];
var filter = [
['Customer Issue', 'company', '=', doc.company],
['Customer Issue', 'docstatus', '=', 1],
['Customer Issue', 'status', 'in', 'Open, Work In Progress']
];
if(doc.customer) cond = ['Customer Issue', 'customer', '=', doc.customer];
filter.push(cond);
return {
filters:filter
}
}
cur_frm.fields_dict['maintenance_schedule'].get_query = function(doc) {
doc = locals[this.doctype][this.docname];
var cond = '';
if(doc.customer) {
cond = '`tabMaintenance Schedule`.customer = "'+doc.customer+'" AND';
}
return repl('SELECT `tabMaintenance Schedule`.name FROM `tabMaintenance Schedule` WHERE `tabMaintenance Schedule`.company = "%(company)s" AND %(cond)s `tabMaintenance Schedule`.docstatus = 1 AND `tabMaintenance Schedule`.name LIKE "%s" ORDER BY `tabMaintenance Schedule`.name DESC LIMIT 50', {company:doc.company, cond:cond});
var cond = [];
var filter = [
['Maintenance Schedule', 'company', '=', doc.company],
['Maintenance Schedule', 'docstatus', '=', 1]
];
if(doc.customer) cond = ['Maintenance Schedule', 'customer', '=', doc.customer];
filter.push(cond);
return{
filters:filter
}
}
//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"
}
}
}
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

@@ -14,7 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
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" } }
wn.provide("erpnext.support");
// TODO commonify this code