Merge pull request #17133 from hrwX/validate_stock_transaction_v11

fix(Item): check transactions for batch, serial check
This commit is contained in:
Nabin Hait 2019-04-05 15:41:35 +05:30 committed by GitHub
commit 8cf76e74e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,9 +49,6 @@ class Item(WebsiteGenerator):
self.set_onload('stock_exists', self.stock_ledger_created())
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):
if not hasattr(self, '_asset_naming_series'):
@ -118,7 +115,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_variant_based_on_change()
@ -129,6 +125,7 @@ class Item(WebsiteGenerator):
self.validate_uom_conversion_factor()
self.validate_item_defaults()
self.update_defaults_from_item_group()
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")
@ -530,7 +527,7 @@ class Item(WebsiteGenerator):
if d.get("warehouse") and d.get("warehouse") not in warehouse:
warehouse += [d.get("warehouse")]
else:
frappe.throw(_("Row {0}: Reorder entry already exists for the warehouse {1}")
frappe.throw(_("Row {0}: An Reorder entry already exists for this warehouse {1}")
.format(d.idx, d.warehouse), DuplicateReorderRows)
if d.warehouse_reorder_level and not d.warehouse_reorder_qty:
@ -732,18 +729,6 @@ class Item(WebsiteGenerator):
if self.variant_based_on != frappe.db.get_value("Item", self.name, "variant_based_on"):
frappe.throw(_("Variant Based On cannot be changed"))
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):
if not self.get("__islocal"):
check_stock_uom_with_bin(self.name, self.stock_uom)
@ -796,6 +781,11 @@ class Item(WebsiteGenerator):
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):
'''returns timeline data based on stock ledger entry'''