From cdd79e3c40b217ad5cdc64f232eb94fc040a6ab8 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Thu, 4 Apr 2019 15:26:35 +0530 Subject: [PATCH] fix: check transactions for batch, serial check --- erpnext/stock/doctype/item/item.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 43d7972196..a1083051f1 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -118,7 +118,6 @@ class Item(WebsiteGenerator): self.validate_has_variants() self.validate_stock_exists_for_template_item() - self.validate_asset_exists_for_serialized_asset() self.validate_attributes() self.validate_variant_attributes() self.validate_website_image() @@ -128,6 +127,7 @@ class Item(WebsiteGenerator): self.validate_uom_conversion_factor() self.validate_item_defaults() self.validate_customer_provided_part() + self.validate_stock_for_has_batch_and_has_serial() if not self.get("__islocal"): self.old_item_group = frappe.db.get_value(self.doctype, self.name, "item_group") @@ -759,12 +759,6 @@ class Item(WebsiteGenerator): frappe.throw( _('Cannot change Attributes after stock transaction. Make a new Item and transfer stock to the new Item')) - def validate_asset_exists_for_serialized_asset(self): - if (not self.get("__islocal") and self.asset_exists() and - cint(self.has_serial_no) != cint(frappe.db.get_value('Item', self.name, 'has_serial_no'))): - frappe.throw(_("Asset is already exists against the item {0}, you cannot change the has serial no value") - .format(self.name)) - def asset_exists(self): if not hasattr(self, '_asset_created'): self._asset_created = frappe.db.get_all("Asset", @@ -824,6 +818,11 @@ class Item(WebsiteGenerator): for d in self.attributes: d.variant_of = self.variant_of + def validate_stock_for_has_batch_and_has_serial(self): + if self.stock_ledger_created(): + for value in ["has_batch_no", "has_serial_no"]: + if frappe.db.get_value("Item", self.name, value) != self.get_value(value): + frappe.throw(_("Cannot change {0} as Stock Transaction for Item {1} exist.".format(value, self.name))) def get_timeline_data(doctype, name): '''returns timeline data based on stock ledger entry'''