Merge pull request #3621 from neilLasrado/batch

Validation added to prevent adding items with expired batch numbers t…
This commit is contained in:
Nabin Hait 2015-07-10 17:31:52 +05:30
commit 97bb6bbaf4
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 = frappe.db.get_value("Batch", item.batch_no, "expiry_date")
if expiry_date:
if getdate(self.posting_date) > getdate(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 = frappe.db.get_value("Batch", self.batch_no, "expiry_date")
if expiry_date:
if getdate(self.posting_date) > getdate(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`