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

@@ -207,8 +207,9 @@ def make_quotation(source_name, target_doclist=None):
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})
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

@@ -199,7 +199,7 @@ cur_frm.fields_dict['quotation_details'].grid.get_field('item_code').get_query=
return {
query: 'selling.doctype.quotation.quotation.quotation_details',
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'):
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
where q.name = q_item.parent and q_item.item_code = item.name
and q.docstatus = 1 and q.customer = "%(cust)s"
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))
(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"
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})
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))
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

@@ -370,20 +370,30 @@ def get_batch_no(doctype, txt, searchfield, start, page_len, filters):
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
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})
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': "%%%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})
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 %(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})