From ebb60f5dbc0eafe53e3d315b235321ae7dafb498 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Wed, 8 Jul 2015 14:36:09 +0530 Subject: [PATCH] Fixed issues in Expired Batches while making Stock Entry --- erpnext/controllers/queries.py | 17 +++++++++-------- erpnext/selling/sales_common.js | 2 +- .../stock/doctype/stock_entry/stock_entry.js | 17 ++++++++++++----- .../stock/doctype/stock_entry/stock_entry.py | 2 +- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index 4f35fea38a..801f6f28ed 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -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 = [] diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 775eb4143f..cd65d1890b 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -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 diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 1135bc708f..c12395793d 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -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 diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 813a61b7d3..e5e3bb3f64 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -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")):