[fix] [stock] batch no query in stock entry

This commit is contained in:
Nabin Hait
2013-07-11 11:58:20 +05:30
parent 76cacdbb78
commit 789976f272
2 changed files with 44 additions and 29 deletions

View File

@@ -313,23 +313,14 @@ cur_frm.fields_dict['mtn_details'].grid.onrowadd = function(doc, cdt, cdn){
cur_frm.fields_dict['mtn_details'].grid.get_field('batch_no').get_query = function(doc, cdt, cdn) { cur_frm.fields_dict['mtn_details'].grid.get_field('batch_no').get_query = function(doc, cdt, cdn) {
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if(d.item_code) { if(d.item_code) {
if (d.s_warehouse) { return{
return{ query: "stock.doctype.stock_entry.stock_entry.get_batch_no",
query: "stock.doctype.stock_entry.stock_entry.get_batch_no", filters:{
filters:{ 'item_code': d.item_code,
'item_code': d.item_code, 's_warehouse': d.s_warehouse,
's_warehouse': d.s_warehouse, 'posting_date': doc.posting_date
'posting_date': doc.posting_date
}
}
} else {
return{
filters:[
['Batch', 'item', '=', d.item_code],
['Batch', 'expiry_date', '>=', doc.posting_date]
]
} }
} }
} else { } else {
msgprint("Please enter Item Code to get batch no"); msgprint("Please enter Item Code to get batch no");
} }

View File

@@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes import webnotes
import webnotes.defaults import webnotes.defaults
from webnotes.utils import cstr, cint, flt, comma_or from webnotes.utils import cstr, cint, flt, comma_or, nowdate
from webnotes.model.doc import Document, addchild from webnotes.model.doc import Document, addchild
from webnotes.model.bean import getlist from webnotes.model.bean import getlist
from webnotes.model.code import get_obj from webnotes.model.code import get_obj
@@ -710,7 +710,6 @@ def get_production_order_details(production_order):
return result and result[0] or {} return result and result[0] or {}
def query_sales_return_doc(doctype, txt, searchfield, start, page_len, filters): def query_sales_return_doc(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond
conditions = "" conditions = ""
if doctype == "Sales Invoice": if doctype == "Sales Invoice":
conditions = "and update_stock=1" conditions = "and update_stock=1"
@@ -726,7 +725,6 @@ def query_sales_return_doc(doctype, txt, searchfield, start, page_len, filters):
as_list=True) as_list=True)
def query_purchase_return_doc(doctype, txt, searchfield, start, page_len, filters): def query_purchase_return_doc(doctype, txt, searchfield, start, page_len, filters):
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 and (`%s` like %%(txt)s
@@ -761,24 +759,50 @@ def query_return_item(doctype, txt, searchfield, start, page_len, filters):
return result[start:start+page_len] return result[start:start+page_len]
def get_batch_no(doctype, txt, searchfield, start, page_len, filters): def get_batch_no(doctype, txt, searchfield, start, page_len, filters):
from controllers.queries import get_match_cond if not filters.get("posting_date"):
filters["posting_date"] = nowdate()
return webnotes.conn.sql("""select batch_no from `tabStock Ledger Entry` sle
batch_nos = None
args = {
'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
}
if filters.get("s_warehouse"):
batch_nos = webnotes.conn.sql("""select batch_no
from `tabStock Ledger Entry` sle
where item_code = '%(item_code)s' where item_code = '%(item_code)s'
and warehouse = '%(s_warehouse)s' and warehouse = '%(s_warehouse)s'
and ifnull(is_cancelled, 'No') = 'No' and ifnull(is_cancelled, 'No') = 'No'
and batch_no like '%(txt)s' and batch_no like '%(txt)s'
and exists(select * from `tabBatch` and exists(select * from `tabBatch`
where name = sle.batch_no where name = sle.batch_no
and expiry_date >= %(posting_date)s and (ifnull(expiry_date, '2099-12-31') >= %(posting_date)s
and docstatus != 2) or expiry_date = '')
and docstatus != 2)
%(mcond)s %(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 order by batch_no desc
limit %(start)s, %(page_len)s """ % {'item_code': filters['item_code'], limit %(start)s, %(page_len)s """
's_warehouse': filters['s_warehouse'], 'posting_date': filters['posting_date'], % args)
'txt': "%%%s%%" % txt, 'mcond':get_match_cond(doctype, searchfield),
"start": start, "page_len": page_len}) if batch_nos:
return batch_nos
else:
return webnotes.conn.sql("""select name from `tabBatch`
where item = '%(item_code)s'
and docstatus < 2
and (ifnull(expiry_date, '2099-12-31') >= %(posting_date)s
or expiry_date = '' or expiry_date = "0000-00-00")
%(mcond)s
order by name desc
limit %(start)s, %(page_len)s
""" % args)
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"""