From 035160c9a6c41ae3eddd94dce7a0bae97254916f Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Wed, 24 Jun 2015 15:25:57 +0530 Subject: [PATCH] Added validation to prevent transfer of raw material from an expired batch for manufacturing --- erpnext/stock/doctype/stock_entry/stock_entry.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index e732898c61..813a61b7d3 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe import frappe.defaults -from frappe.utils import cstr, cint, flt, comma_or, get_datetime +from frappe.utils import cstr, cint, flt, comma_or, get_datetime, getdate from frappe import _ from erpnext.stock.utils import get_incoming_rate @@ -66,6 +66,7 @@ class StockEntry(StockController): self.validate_valuation_rate() self.set_total_incoming_outgoing_value() self.set_total_amount() + self.validate_batch() def on_submit(self): self.update_stock_ledger() @@ -724,6 +725,13 @@ class StockEntry(StockController): mreq_item.warehouse != (item.s_warehouse if self.purpose== "Material Issue" else item.t_warehouse): frappe.throw(_("Item or Warehouse for row {0} does not match Material Request").format(item.idx), frappe.MappingMismatchError) + + def validate_batch(self): + if self.purpose == "Material Transfer for Manufacture": + 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)) @frappe.whitelist() def get_party_details(ref_dt, ref_dn):