Validation added to prevent adding items with expired batch numbers to stock ledger entry

This commit is contained in:
Neil Trini Lasrado 2015-07-09 18:40:38 +05:30
parent 6c4085fc0c
commit 03bf529622
2 changed files with 12 additions and 2 deletions

View File

@ -730,8 +730,10 @@ class StockEntry(StockController):
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")):
frappe.throw(_("Batch {0} of Item {1} has expired.").format(item.batch_no, item.item_code))
expiry_date = getdate(frappe.db.get_value("Batch", item.batch_no, "expiry_date"))
if expiry_date:
if getdate(self.posting_date) > expiry_date:
frappe.throw(_("Batch {0} of Item {1} has expired.").format(item.batch_no, item.item_code))
@frappe.whitelist()
def get_party_details(ref_dt, ref_dn):

View File

@ -18,6 +18,7 @@ class StockLedgerEntry(Document):
from erpnext.stock.utils import validate_warehouse_company
self.validate_mandatory()
self.validate_item()
self.validate_batch()
validate_warehouse_company(self.warehouse, self.company)
self.scrub_posting_time()
@ -96,6 +97,13 @@ class StockLedgerEntry(Document):
def scrub_posting_time(self):
if not self.posting_time or self.posting_time == '00:0':
self.posting_time = '00:00'
def validate_batch(self):
if self.batch_no and self.voucher_type != "Stock Entry":
expiry_date = getdate(frappe.db.get_value("Batch", self.batch_no, "expiry_date"))
if expiry_date:
if getdate(self.posting_date) > expiry_date:
frappe.throw(_("Batch {0} of Item {1} has expired.").format(self.batch_no, self.item_code))
def on_doctype_update():
if not frappe.db.sql("""show index from `tabStock Ledger Entry`