queries to server side

This commit is contained in:
Saurabh
2013-07-10 13:07:49 +05:30
parent 2e3c06e66d
commit f52dc07a58
10 changed files with 125 additions and 54 deletions

View File

@@ -36,33 +36,34 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}
this.frm.set_query("customer_address", function() {
return 'SELECT name, address_line1, city FROM tabAddress \
WHERE customer = "'+ me.frm.doc.customer +'" AND docstatus != 2 AND \
%(key)s LIKE "%s" ORDER BY name ASC LIMIT 50';
return {
filters: {'customer': me.frm.doc.customer }
}
});
this.frm.set_query("contact_person", function() {
return 'SELECT name, CONCAT(first_name," ",ifnull(last_name,"")) As FullName, \
department, designation FROM tabContact WHERE customer = "'+ me.frm.doc.customer +
'" AND docstatus != 2 AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50';
return {
filters: {'customer': me.frm.doc.customer }
}
});
if(this.frm.fields_dict.charge) {
this.frm.set_query("charge", function() {
return 'SELECT DISTINCT `tabSales Taxes and Charges Master`.name FROM \
`tabSales Taxes and Charges Master` \
WHERE `tabSales Taxes and Charges Master`.company = "' + me.frm.doc.company +
'" AND `tabSales Taxes and Charges Master`.company is not NULL \
AND `tabSales Taxes and Charges Master`.docstatus != 2 \
AND `tabSales Taxes and Charges Master`.%(key)s LIKE "%s" \
ORDER BY `tabSales Taxes and Charges Master`.name LIMIT 50';
return {
filters: [
['Sales Taxes and Charges Master', 'company', '=', me.frm.doc.company],
['Sales Taxes and Charges Master', 'company', 'is not', 'NULL'],
['Sales Taxes and Charges Master', 'docstatus', '!=', 2]
]
}
});
}
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);
this.frm.fields_dict.lead && this.frm.set_query("lead", function(doc,cdt,cdn) {
return{ query:"controllers.queries.lead_query" } });
if(!this.fname) {
return;
@@ -71,8 +72,10 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
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" ?
erpnext.queries.item({'ifnull(tabItem.is_service_item, "No")': "Yes"}) :
erpnext.queries.item({'ifnull(tabItem.is_sales_item, "No")': "Yes"});
{ query:"controllers.queries.item_query",
filters:{'is_service_item': 'Yes'}} :
{ query:"controllers.queries.item_query",
filters:{'is_sales_item': 'Yes' }} ;
});
}
@@ -83,18 +86,22 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
wn.throw("Please enter Item Code to get batch no");
} else {
if(item.warehouse) {
return "select batch_no from `tabStock Ledger Entry` sle \
where item_code = '" + item.item_code +
"' and warehouse = '" + item.warehouse +
"' and ifnull(is_cancelled, 'No') = 'No' and batch_no like '%s' \
and exists(select * from `tabBatch` where \
name = sle.batch_no and expiry_date >= '" + me.frm.doc.posting_date +
"' and docstatus != 2) group by batch_no having sum(actual_qty) > 0 \
order by batch_no desc limit 50";
return {
query : "selling.doctype.sales_common.sales_common.get_batch_no",
filters: {
'item_code': item.item_code,
'warehouse': item.warehouse,
'posting_date': me.frm.doc.posting_date
}
}
} else {
return "SELECT name FROM tabBatch WHERE docstatus != 2 AND item = '" +
item.item_code + "' and expiry_date >= '" + me.frm.doc.posting_date +
"' AND name like '%s' ORDER BY name DESC LIMIT 50";
return{
query : "selling.doctype.sales_common.sales_common.get_batch_no",
filters: {
'item': item.item_code,
'posting_date': me.frm.doc.posting_date
}
}
}
}
});

View File

@@ -365,3 +365,25 @@ class DocType(TransactionBase):
dt = webnotes.conn.sql("select transaction_date from `tab%s` where name = '%s'" % (d.prevdoc_doctype, d.prevdoc_docname))
d.prevdoc_date = (dt and dt[0][0]) and dt[0][0].strftime('%Y-%m-%d') or ''
def get_batch_no(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond
if filters.has_key('warehouse'):
return webnotes.conn.sql("""select batch_no from `tabStock Ledger Entry` sle
where item_code = '%(item_code)s' and warehouse = '%(warehouse)s'
and ifnull(is_cancelled, 'No') = 'No' and batch_no like '%(txt)s'
and exists(select * from `tabBatch` where
name = sle.batch_no and expiry_date >= '%(posting_date)s'
and docstatus != 2) %(mcond)s
group by batch_no having sum(actual_qty) > 0
order by batch_no desc limit %(start)s, %(page_len)s
""" % {'item_code': filters['item_code'], 'warehouse': filters['warehouse'],
'posting_date': filters['posting_date'], 'txt': 'txt': "%%%s%%" % txt,
'mcond':get_match_cond(doctype, searchfield),'start': start, 'page_len': page_len})
else:
return webnotes.conn.sql("""select name from tabBatch where docstatus != 2
and item = '%(item_code)s' and expiry_date >= '%(posting_date)s'
and name like '%(txt)s' %(mcond)s ORDER BY name DESC LIMIT 50""" %
{'item_code': filters['item_code'], 'posting_date': filters['posting_date'],
'txt': 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield),
'start': start, 'page_len': page_len})