From 00e02f07acc90f87357d7df4491d52784994b410 Mon Sep 17 00:00:00 2001 From: Pandiyan P Date: Wed, 9 Sep 2026 12:37:03 +0530 Subject: [PATCH] fix: validate shelf life for automatically created expiring batches (#58911) Co-authored-by: Ajish18 (cherry picked from commit b2bdeaa6725441089ae59cde4aa1c3b518ffb7c2) --- erpnext/stock/doctype/item/item.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index fb2a7ee95f8..cdeedae35bd 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -194,6 +194,7 @@ class Item(Document): self.validate_conversion_factor() self.validate_item_type() self.validate_naming_series() + self.validate_shelf_life() self.check_for_active_boms() self.fill_customer_code() self.check_item_tax() @@ -344,6 +345,19 @@ class Item(Document): ).format(self.item_code) ) + def validate_shelf_life(self): + if ( + self.has_batch_no + and self.has_expiry_date + and self.create_new_batch + and cint(self.shelf_life_in_days) <= 0 + ): + frappe.throw( + _("{0} must be greater than zero.").format( + self.get_label_from_fieldname("shelf_life_in_days") + ) + ) + def clear_retain_sample(self): if not self.has_batch_no: self.retain_sample = False