fix: check transactions for batch, serial check

This commit is contained in:
Himanshu Warekar
2019-04-04 15:02:25 +05:30
parent f86a01446f
commit 28db545947

View File

@@ -49,9 +49,6 @@ class Item(WebsiteGenerator):
self.set_onload('stock_exists', self.stock_ledger_created()) self.set_onload('stock_exists', self.stock_ledger_created())
self.set_asset_naming_series() self.set_asset_naming_series()
if self.is_fixed_asset:
asset = self.asset_exists()
self.set_onload("asset_exists", True if asset else False)
def set_asset_naming_series(self): def set_asset_naming_series(self):
if not hasattr(self, '_asset_naming_series'): if not hasattr(self, '_asset_naming_series'):
@@ -118,7 +115,6 @@ class Item(WebsiteGenerator):
self.validate_has_variants() self.validate_has_variants()
self.validate_stock_exists_for_template_item() self.validate_stock_exists_for_template_item()
self.validate_asset_exists_for_serialized_asset()
self.validate_attributes() self.validate_attributes()
self.validate_variant_attributes() self.validate_variant_attributes()
self.validate_website_image() self.validate_website_image()
@@ -128,6 +124,7 @@ class Item(WebsiteGenerator):
self.validate_uom_conversion_factor() self.validate_uom_conversion_factor()
self.validate_item_defaults() self.validate_item_defaults()
self.update_defaults_from_item_group() self.update_defaults_from_item_group()
self.validate_stock_for_has_batch_and_has_serial()
if not self.get("__islocal"): if not self.get("__islocal"):
self.old_item_group = frappe.db.get_value(self.doctype, self.name, "item_group") self.old_item_group = frappe.db.get_value(self.doctype, self.name, "item_group")
@@ -726,18 +723,6 @@ class Item(WebsiteGenerator):
frappe.throw( frappe.throw(
_('Cannot change Attributes after stock transaction. Make a new Item and transfer stock to the new Item')) _('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",
filters={"item_code": self.name, "docstatus": 1}, limit=1)
return self._asset_created
def validate_uom(self): def validate_uom(self):
if not self.get("__islocal"): if not self.get("__islocal"):
check_stock_uom_with_bin(self.name, self.stock_uom) check_stock_uom_with_bin(self.name, self.stock_uom)
@@ -787,6 +772,11 @@ class Item(WebsiteGenerator):
validate_item_variant_attributes(self, args) validate_item_variant_attributes(self, args)
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): def get_timeline_data(doctype, name):
'''returns timeline data based on stock ledger entry''' '''returns timeline data based on stock ledger entry'''