Merge pull request #3600 from neilLasrado/batch

Fixed issues in Expired Batches while making Stock Entry
This commit is contained in:
Nabin Hait 2015-07-08 16:10:21 +05:30
commit 736000c223
4 changed files with 23 additions and 15 deletions

View File

@ -229,9 +229,10 @@ def get_delivery_notes_to_be_billed(doctype, txt, searchfield, start, page_len,
}, { "start": start, "page_len": page_len, "txt": ("%%%s%%" % txt) })
def get_batch_no(doctype, txt, searchfield, start, page_len, filters):
if not filters.get("posting_date"):
filters["posting_date"] = nowdate()
cond = ""
if filters.get("posting_date"):
cond = "and (ifnull(batch.expiry_date, '')='' or batch.expiry_date >= %(posting_date)s)"
batch_nos = None
args = {
'item_code': filters.get("item_code"),
@ -251,23 +252,23 @@ def get_batch_no(doctype, txt, searchfield, start, page_len, filters):
and sle.warehouse = %(warehouse)s
and sle.batch_no like %(txt)s
and batch.docstatus < 2
and (ifnull(batch.expiry_date, '')='' or batch.expiry_date >= %(posting_date)s)
{0}
{match_conditions}
group by batch_no having sum(sle.actual_qty) > 0
order by batch.expiry_date, sle.batch_no desc
limit %(start)s, %(page_len)s""".format(match_conditions=get_match_cond(doctype)), args)
limit %(start)s, %(page_len)s""".format(cond, match_conditions=get_match_cond(doctype)), args)
if batch_nos:
return batch_nos
else:
return frappe.db.sql("""select name, expiry_date from `tabBatch`
return frappe.db.sql("""select name, expiry_date from `tabBatch` batch
where item = %(item_code)s
and name like %(txt)s
and docstatus < 2
and (ifnull(expiry_date, '')='' or expiry_date >= %(posting_date)s)
{0}
{match_conditions}
order by expiry_date, name desc
limit %(start)s, %(page_len)s""".format(match_conditions=get_match_cond(doctype)), args)
limit %(start)s, %(page_len)s""".format(cond, match_conditions=get_match_cond(doctype)), args, debug=1)
def get_account_list(doctype, txt, searchfield, start, page_len, filters):
filter_list = []

View File

@ -71,7 +71,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
} else {
filters = {
'item_code': item.item_code,
'posting_date': me.frm.doc.posting_date,
'posting_date': me.frm.doc.posting_date || nowdate(),
}
if(item.warehouse) filters["warehouse"] = item.warehouse

View File

@ -411,14 +411,21 @@ cur_frm.fields_dict['items'].grid.get_field('batch_no').get_query = function(doc
var item = locals[cdt][cdn];
if(!item.item_code) {
frappe.throw(__("Please enter Item Code to get batch no"));
} else {
var filters = {
'item_code': item.item_code,
'posting_date': me.frm.doc.posting_date,
}
else {
if (in_list(["Material Transfer for Manufacture", "Manufacture", "Repack", "Subcontract"], doc.purpose)) {
var filters = {
'item_code': item.item_code,
'posting_date': me.frm.doc.posting_date || nowdate()
}
} else {
var filters = {
'item_code': item.item_code
}
}
if(item.s_warehouse) filters["warehouse"] = item.s_warehouse
return {
query : "erpnext.controllers.queries.get_batch_no",
filters: filters

View File

@ -727,7 +727,7 @@ class StockEntry(StockController):
frappe.MappingMismatchError)
def validate_batch(self):
if self.purpose == "Material Transfer for Manufacture":
if self.purpose in ["Material Transfer for Manufacture", "Manufacture", "Repack", "Subcontract"]:
for item in self.get("items"):
if item.batch_no:
if getdate(self.posting_date) > getdate(frappe.db.get_value("Batch", item.batch_no, "expiry_date")):