get_query to server side

This commit is contained in:
Saurabh 2013-07-10 17:35:14 +05:30
parent a29b69245e
commit ee85cfd476
13 changed files with 116 additions and 83 deletions

View File

@ -153,13 +153,14 @@ def gl_entry_details(doctype, txt, searchfield, start, page_len, filters):
or ifnull(gle.against_voucher, '') = gle.voucher_no ) or ifnull(gle.against_voucher, '') = gle.voucher_no )
and ifnull(gle.%(account_type)s, 0) > 0 and ifnull(gle.%(account_type)s, 0) > 0
and (select ifnull(abs(sum(ifnull(debit, 0)) and (select ifnull(abs(sum(ifnull(debit, 0))
- sum(ifnull(credit, 0))), 0) - sum(ifnull(credit, 0))), 0)
from `tabGL Entry` from `tabGL Entry`
where against_voucher_type = '%(dt)s' where against_voucher_type = '%(dt)s'
and against_voucher = gle.voucher_no and against_voucher = gle.voucher_no
and voucher_no != gle.voucher_no and voucher_no != gle.voucher_no
and ifnull(is_cancelled, 'No') = 'No') and ifnull(is_cancelled, 'No') = 'No')
!= abs(ifnull(gle.debit, 0) - ifnull(gle.credit, 0)) != abs(ifnull(gle.debit, 0) - ifnull(gle.credit, 0)
)
%(mcond)s %(mcond)s
ORDER BY gle.posting_date desc, gle.voucher_no desc ORDER BY gle.posting_date desc, gle.voucher_no desc
limit %(start)s, %(page_len)s""" % {dt:filters["dt"], acc:filters["acc"], limit %(start)s, %(page_len)s""" % {dt:filters["dt"], acc:filters["acc"],

View File

@ -55,7 +55,7 @@ cur_frm.fields_dict['cost_center'].get_query = function(doc,cdt,cdn) {
return{ return{
filters:{ filters:{
'company_name': doc.company, 'company_name': doc.company,
'group_or_ledger': "Ledger", 'group_or_ledger': "Ledger"
} }
} }
} }

View File

@ -990,8 +990,10 @@ def get_income_account(doctype, txt, searchfield, start, page_len, filters):
return webnotes.conn.sql("""select tabAccount.name from `tabAccount` return webnotes.conn.sql("""select tabAccount.name from `tabAccount`
where (tabAccount.debit_or_credit="Credit" where (tabAccount.debit_or_credit="Credit"
or tabAccount.account_type = "Income Account") or tabAccount.account_type = "Income Account")
and tabAccount.group_or_ledger="Ledger" and tabAccount.docstatus!=2 and tabAccount.group_or_ledger="Ledger"
and tabAccount.company = '%(company)s' and tabAccount.%(key)s LIKE '%(txt)s' and tabAccount.docstatus!=2
%(mcond)s""" % {'company': filters['company'], 'key': searchfield, and tabAccount.company = '%(company)s'
and tabAccount.%(key)s LIKE '%(txt)s'
%(mcond)s""" % {'company': filters['company'], 'key': searchfield,
'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield)}) 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield)})

View File

@ -43,15 +43,11 @@ cur_frm.cscript.refresh = cur_frm.cscript.inspection_type;
// item code based on GRN/DN // item code based on GRN/DN
cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) { cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) {
filter = {}; var filter = {};
if (doc.purchase_receipt_no) if (doc.purchase_receipt_no) filter['parent'] = doc.purchase_receipt_no;
filter:{
'parent': doc.purchase_receipt_no else if (doc.delivery_note_no) filter['parent'] = doc.delivery_note_no;
}
else if (doc.delivery_note_no)
filter:{
'parent': doc.delivery_note_no
}
return{ return{
filters: filter filters: filter
} }
@ -59,15 +55,14 @@ cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) {
// Serial No based on item_code // Serial No based on item_code
cur_frm.fields_dict['item_serial_no'].get_query = function(doc, cdt, cdn) { cur_frm.fields_dict['item_serial_no'].get_query = function(doc, cdt, cdn) {
filter = {}; var filter = {};
if (doc.item_code) if (doc.item_code)
filter:{ filter:{
'item_code': doc.item_code, 'item_code': doc.item_code,
'status': "In Store" 'status': "In Store"
} }
// return 'SELECT name, item_code, warehouse FROM `tabSerial No` WHERE docstatus != 2 AND item_code = "' + doc.item_code +'" AND status = "In Store" AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50';
else else
filter:{ 'status': "In Store" } filter: { 'status': "In Store" }
// return 'SELECT name, item_code, warehouse FROM `tabSerial No` WHERE docstatus != 2 AND status = "In Store" AND %(key)s LIKE "%s" ORDER BY name ASC LIMIT 50';
return{ filters: filter } return { filters: filter }
} }

View File

@ -67,7 +67,7 @@ cur_frm.fields_dict['quotation_items'].grid.get_field('project_name').get_query
function(doc, cdt, cdn) { function(doc, cdt, cdn) {
return{ return{
filters:[ filters:[
['Project', 'status', 'not in', 'Completed, Cancelled'], ['Project', 'status', 'not in', 'Completed, Cancelled']
] ]
} }
} }

View File

@ -96,8 +96,9 @@ def get_events(start, end, filters=None):
def get_project(doctype, txt, searchfield, start, page_len, filters): def get_project(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond from controllers.queries import get_match_cond
return webnotes.conn.sql(""" select name from `tabProject` return webnotes.conn.sql(""" select name from `tabProject`
where %(key)s like "%(txt)s" %(mcond)s where %(key)s like "%(txt)s"
order by name limit %(start)s, %(page_len)s %(mcond)s
""" % {'key': searchfield, 'txt': "%%%s%%" % txt, order by name
'mcond':get_match_cond(doctype, searchfield), limit %(start)s, %(page_len)s """ % {'key': searchfield,
'start': start, 'page_len': page_len}) 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield),
'start': start, 'page_len': page_len})

View File

@ -207,8 +207,9 @@ def make_quotation(source_name, target_doclist=None):
def get_lead(doctype, txt, searchfield, start, page_len, filters): def get_lead(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond from controllers.queries import get_match_cond
return webnotes.conn.sql ("""select `tabLead`.name, `tabLead`.lead_name FROM `tabLead` return webnotes.conn.sql ("""select `tabLead`.name, `tabLead`.lead_name FROM `tabLead`
where `tabLead`.%(key)s like "%(txt)s" %(mcond)s where `tabLead`.%(key)s like "%(txt)s"
order by `tabLead`.`name` asc limit %(start)s, %(page_len)s %(mcond)s
""" % {'key': searchfield, 'txt': "%%%s%%" % txt, order by `tabLead`.`name` asc
'mcond':get_match_cond(doctype, searchfield), limit %(start)s, %(page_len)s """ % {'key': searchfield,
'start': start, 'page_len': page_len}) 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield),
'start': start, 'page_len': page_len})

View File

@ -199,7 +199,7 @@ cur_frm.fields_dict['quotation_details'].grid.get_field('item_code').get_query=
return { return {
query: 'selling.doctype.quotation.quotation.quotation_details', query: 'selling.doctype.quotation.quotation.quotation_details',
filters:{ filters:{
cond: cond, cond: cond
} }
} }
} }

View File

@ -266,26 +266,35 @@ def quotation_details(doctype, txt, searchfield, start, page_len, filters):
if filters.has_key('cust') and filters.has_key('precision'): if filters.has_key('cust') and filters.has_key('precision'):
return webnotes.conn.sql("""select item.name, return webnotes.conn.sql("""select item.name,
(select concat('Last Quote @ ', q.currency, ' ', format(q_item.export_rate, %(precision)s)) (select concat('Last Quote @ ', q.currency, ' ',
format(q_item.export_rate, %(precision)s))
from `tabQuotation` q, `tabQuotation Item` q_item from `tabQuotation` q, `tabQuotation Item` q_item
where q.name = q_item.parent and q_item.item_code = item.name where q.name = q_item.parent
and q.docstatus = 1 and q.customer = "%(cust)s" and q_item.item_code = item.name
and q.docstatus = 1
and q.customer = "%(cust)s"
order by q.transaction_date desc order by q.transaction_date desc
limit 1) as quote_rate, limit 1) as quote_rate,
(select concat('Last Sale @ ', si.currency, ' ', format(si_item.basic_rate, %(precision)s)) (select concat('Last Sale @ ', si.currency, ' ',
format(si_item.basic_rate, %(precision)s))
from `tabSales Invoice` si, `tabSales Invoice Item` si_item from `tabSales Invoice` si, `tabSales Invoice Item` si_item
where si.name = si_item.parent and si_item.item_code = item.name where si.name = si_item.parent
and si.docstatus = 1 and si.customer ="%(cust)s" and si_item.item_code = item.name
and si.docstatus = 1
and si.customer ="%(cust)s"
order by si.posting_date desc order by si.posting_date desc
limit 1) as sales_rate, limit 1) as sales_rate,
item.item_name, item.description item.item_name, item.description
from `tabItem` item from `tabItem` item
where %(cond)s %(mcond)s and item.%(searchfield)s like '%(txt)s' order by item.name desc limit %(start)s, where %(cond)s %(mcond)s
%(page_len)s """ % {'precision': filters["precision"], 'cust': filters['cust'], and item.%(searchfield)s like '%(txt)s'
'cond': filters['cond'], 'searchfield': searchfield, 'txt': "%%%s%%" % txt, order by item.name desc limit %(start)s, %(page_len)s """ % {'precision': filters["precision"],
'mcond': get_match_cond(doctype, searchfield), 'start': start, 'page_len': page_len}) 'cust': filters['cust'], 'cond': filters['cond'], 'searchfield': searchfield,
'txt': "%%%s%%" % txt, 'mcond': get_match_cond(doctype, searchfield),
'start': start, 'page_len': page_len})
else: else:
webnotes.conn.sql(""" select name, item_name, description from `tabItem` item 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""" % 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)) ("%s", get_match_cond(doctype, searchfield), searchfield, "%s", "%s", "%s"),
(filters["cond"], "%%%s%%" % txt, start, page_len))

View File

@ -370,20 +370,30 @@ def get_batch_no(doctype, txt, searchfield, start, page_len, filters):
if filters.has_key('warehouse'): if filters.has_key('warehouse'):
return webnotes.conn.sql("""select batch_no from `tabStock Ledger Entry` sle return webnotes.conn.sql("""select batch_no from `tabStock Ledger Entry` sle
where item_code = '%(item_code)s' and warehouse = '%(warehouse)s' where item_code = '%(item_code)s'
and ifnull(is_cancelled, 'No') = 'No' and batch_no like '%(txt)s' and warehouse = '%(warehouse)s'
and exists(select * from `tabBatch` where and ifnull(is_cancelled, 'No') = 'No'
name = sle.batch_no and expiry_date >= '%(posting_date)s' and batch_no like '%(txt)s'
and docstatus != 2) %(mcond)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 group by batch_no having sum(actual_qty) > 0
order by batch_no desc limit %(start)s, %(page_len)s order by batch_no desc
""" % {'item_code': filters['item_code'], 'warehouse': filters['warehouse'], limit %(start)s, %(page_len)s """ % {'item_code': filters['item_code'],
'posting_date': filters['posting_date'], 'txt': 'txt': "%%%s%%" % txt, 'warehouse': filters['warehouse'], 'posting_date': filters['posting_date'],
'mcond':get_match_cond(doctype, searchfield),'start': start, 'page_len': page_len}) 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield),
'start': start, 'page_len': page_len})
else: else:
return webnotes.conn.sql("""select name from tabBatch where docstatus != 2 return webnotes.conn.sql("""select name from tabBatch
and item = '%(item_code)s' and expiry_date >= '%(posting_date)s' where docstatus != 2
and name like '%(txt)s' %(mcond)s ORDER BY name DESC LIMIT 50""" % and item = '%(item_code)s'
{'item_code': filters['item_code'], 'posting_date': filters['posting_date'], and expiry_date >= '%(posting_date)s'
'txt': 'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield), and name like '%(txt)s'
'start': start, 'page_len': page_len}) %(mcond)s
order by name desc
limit %(start)s, %(page_len)s""" % {'item_code': filters['item_code'],
'posting_date': filters['posting_date'], 'txt': "%%%s%%" % txt,
'mcond':get_match_cond(doctype, searchfield),'start': start,
'page_len': page_len})

View File

@ -177,7 +177,9 @@ def item_details(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond from controllers.queries import get_match_cond
return webnotes.conn.sql("""select name, item_name, description from `tabItem` return webnotes.conn.sql("""select name, item_name, description from `tabItem`
where name in ( select item_code FROM `tabDelivery Note Item` where name in ( select item_code FROM `tabDelivery Note Item`
where parent= %s and ifnull(qty, 0) > ifnull(packed_qty, 0)) where parent= %s
and %s like "%s" %s limit %s, %s """ % ("%s", searchfield, "%s", and ifnull(qty, 0) > ifnull(packed_qty, 0))
and %s like "%s" %s
limit %s, %s """ % ("%s", searchfield, "%s",
get_match_cond(doctype, searchfield), "%s", "%s"), get_match_cond(doctype, searchfield), "%s", "%s"),
(filters["delivery_note"], "%%%s%%" % txt, start, page_len)) (filters["delivery_note"], "%%%s%%" % txt, start, page_len))

View File

@ -717,7 +717,8 @@ def query_sales_return_doc(doctype, txt, searchfield, start, page_len, filters):
return webnotes.conn.sql("""select name, customer, customer_name return webnotes.conn.sql("""select name, customer, customer_name
from `tab%s` where docstatus = 1 from `tab%s` where docstatus = 1
and (`%s` like %%(txt)s or `customer` like %%(txt)s) %s %s and (`%s` like %%(txt)s
or `customer` like %%(txt)s) %s %s
order by name, customer, customer_name order by name, customer, customer_name
limit %s""" % (doctype, searchfield, conditions, limit %s""" % (doctype, searchfield, conditions,
get_match_cond(doctype, searchfield), "%(start)s, %(page_len)s"), get_match_cond(doctype, searchfield), "%(start)s, %(page_len)s"),
@ -728,7 +729,8 @@ def query_purchase_return_doc(doctype, txt, searchfield, start, page_len, filter
from controllers.queries import get_match_cond from controllers.queries import get_match_cond
return webnotes.conn.sql("""select name, supplier, supplier_name return webnotes.conn.sql("""select name, supplier, supplier_name
from `tab%s` where docstatus = 1 from `tab%s` where docstatus = 1
and (`%s` like %%(txt)s or `supplier` like %%(txt)s) %s and (`%s` like %%(txt)s
or `supplier` like %%(txt)s) %s
order by name, supplier, supplier_name order by name, supplier, supplier_name
limit %s""" % (doctype, searchfield, get_match_cond(doctype, searchfield), limit %s""" % (doctype, searchfield, get_match_cond(doctype, searchfield),
"%(start)s, %(page_len)s"), {"txt": "%%%s%%" % txt, "start": "%(start)s, %(page_len)s"), {"txt": "%%%s%%" % txt, "start":
@ -762,15 +764,21 @@ def get_batch_no(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond from controllers.queries import get_match_cond
return webnotes.conn.sql("""select batch_no from `tabStock Ledger Entry` sle return webnotes.conn.sql("""select batch_no from `tabStock Ledger Entry` sle
where item_code = '%(item_code)s' and warehouse = '%(s_warehouse)s' where item_code = '%(item_code)s'
and ifnull(is_cancelled, 'No') = 'No' and batch_no like '%(txt)s' and warehouse = '%(s_warehouse)s'
and exists(select * from `tabBatch` where name = sle.batch_no and ifnull(is_cancelled, 'No') = 'No'
and expiry_date >= %(posting_date)s and docstatus != 2) %(mcond)s and batch_no like '%(txt)s'
group by batch_no having sum(actual_qty) > 0 and exists(select * from `tabBatch`
order by batch_no desc limit %(start)s, %(page_len)s """ where name = sle.batch_no
% {'item_code': filters['item_code'], 's_warehouse': filters['s_warehouse'], and expiry_date >= %(posting_date)s
'posting_date': filters['posting_date'], 'txt': "%%%s%%" % txt, and docstatus != 2)
'mcond':get_match_cond(doctype, searchfield),"start": start, "page_len": page_len}) %(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'],
's_warehouse': filters['s_warehouse'], 'posting_date': filters['posting_date'],
'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield),
"start": start, "page_len": page_len})
def get_stock_items_for_return(ref_doclist, parentfields): def get_stock_items_for_return(ref_doclist, parentfields):
"""return item codes filtered from doclist, which are stock items""" """return item codes filtered from doclist, which are stock items"""

View File

@ -335,12 +335,16 @@ def make_maintenance_visit(source_name, target_doclist=None):
def get_sales_order_no(doctype, txt, searchfield, start, page_len, filters): def get_sales_order_no(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond from controllers.queries import get_match_cond
return webnotes.conn.sql(""" select distinct `tabSales Order`.name from `tabSales Order`, return webnotes.conn.sql(""" select distinct `tabSales Order`.name
`tabSales Order Item`, `tabItem` from `tabSales Order`, `tabSales Order Item`, `tabItem`
where `tabSales Order`.company = "%(company)s" and `tabSales Order`.docstatus = 1 where `tabSales Order`.company = "%(company)s"
and `tabSales Order Item`.parent = `tabSales Order`.name and `tabSales Order`.docstatus = 1
and `tabSales Order Item`.item_code = `tabItem`.name and `tabSales Order Item`.parent = `tabSales Order`.name
and `tabItem`.is_service_item = "Yes" and %(cond)s `tabSales Order`.name LIKE "%(txt)s" %(mcond)s and `tabSales Order Item`.item_code = `tabItem`.name
ORDER BY `tabSales Order`.name desc LIMIT %(start)s, %(page_len)s""" and `tabItem`.is_service_item = "Yes"
% 'company': filters["company"], 'cond': filters['cond'], 'txt': "%%%s%%" % txt, and %(cond)s `tabSales Order`.name LIKE "%(txt)s"
'mcond':get_match_cond(doctype, searchfield), "start": start, "page_len": page_len}) %(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})