mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 16:04:46 +00:00
Validate stock exists against template item (#11305)
This commit is contained in:
committed by
Nabin Hait
parent
6c06e700d6
commit
311823aca1
@@ -103,6 +103,11 @@ frappe.ui.form.on("Item", {
|
|||||||
frappe.set_route("Form", "Item Variant Settings");
|
frappe.set_route("Form", "Item Variant Settings");
|
||||||
}, __("View"));
|
}, __("View"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(frm.doc.__onload && frm.doc.__onload.stock_exists) {
|
||||||
|
// Hide variants section if stock exists
|
||||||
|
frm.toggle_display("variants_section", 0);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
validate: function(frm){
|
validate: function(frm){
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ from erpnext.controllers.item_variant import (get_variant, copy_attributes_to_va
|
|||||||
make_variant_item_code, validate_item_variant_attributes, ItemVariantExistsError)
|
make_variant_item_code, validate_item_variant_attributes, ItemVariantExistsError)
|
||||||
|
|
||||||
class DuplicateReorderRows(frappe.ValidationError): pass
|
class DuplicateReorderRows(frappe.ValidationError): pass
|
||||||
|
class StockExistsForTemplate(frappe.ValidationError): pass
|
||||||
|
|
||||||
class Item(WebsiteGenerator):
|
class Item(WebsiteGenerator):
|
||||||
website = frappe._dict(
|
website = frappe._dict(
|
||||||
@@ -28,11 +29,15 @@ class Item(WebsiteGenerator):
|
|||||||
|
|
||||||
def onload(self):
|
def onload(self):
|
||||||
super(Item, self).onload()
|
super(Item, self).onload()
|
||||||
|
|
||||||
self.set_onload('sle_exists', self.check_if_sle_exists())
|
self.set_onload('sle_exists', self.check_if_sle_exists())
|
||||||
if self.is_fixed_asset:
|
if self.is_fixed_asset:
|
||||||
asset = frappe.db.get_all("Asset", filters={"item_code": self.name, "docstatus": 1}, limit=1)
|
asset = frappe.db.get_all("Asset", filters={"item_code": self.name, "docstatus": 1}, limit=1)
|
||||||
self.set_onload("asset_exists", True if asset else False)
|
self.set_onload("asset_exists", True if asset else False)
|
||||||
|
|
||||||
|
if frappe.db.get_value('Stock Ledger Entry', {'item_code': self.name}):
|
||||||
|
self.set_onload('stock_exists', True)
|
||||||
|
|
||||||
def autoname(self):
|
def autoname(self):
|
||||||
if frappe.db.get_default("item_naming_by")=="Naming Series":
|
if frappe.db.get_default("item_naming_by")=="Naming Series":
|
||||||
if self.variant_of:
|
if self.variant_of:
|
||||||
@@ -85,6 +90,7 @@ class Item(WebsiteGenerator):
|
|||||||
self.synced_with_hub = 0
|
self.synced_with_hub = 0
|
||||||
|
|
||||||
self.validate_has_variants()
|
self.validate_has_variants()
|
||||||
|
self.validate_stock_exists_for_template_item()
|
||||||
self.validate_attributes()
|
self.validate_attributes()
|
||||||
self.validate_variant_attributes()
|
self.validate_variant_attributes()
|
||||||
self.validate_website_image()
|
self.validate_website_image()
|
||||||
@@ -631,6 +637,12 @@ class Item(WebsiteGenerator):
|
|||||||
if frappe.db.exists("Item", {"variant_of": self.name}):
|
if frappe.db.exists("Item", {"variant_of": self.name}):
|
||||||
frappe.throw(_("Item has variants."))
|
frappe.throw(_("Item has variants."))
|
||||||
|
|
||||||
|
def validate_stock_exists_for_template_item(self):
|
||||||
|
if self.has_variants and \
|
||||||
|
frappe.db.get_value('Stock Ledger Entry', {'item_code': self.name}):
|
||||||
|
frappe.throw(_("As stock exists against an item {0}, you can not enable has variants property")
|
||||||
|
.format(self.name), StockExistsForTemplate)
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import frappe
|
|||||||
from frappe.test_runner import make_test_records
|
from frappe.test_runner import make_test_records
|
||||||
from erpnext.controllers.item_variant import (create_variant, ItemVariantExistsError,
|
from erpnext.controllers.item_variant import (create_variant, ItemVariantExistsError,
|
||||||
InvalidItemAttributeValueError, get_variant)
|
InvalidItemAttributeValueError, get_variant)
|
||||||
|
from erpnext.stock.doctype.item.item import StockExistsForTemplate
|
||||||
|
|
||||||
from frappe.model.rename_doc import rename_doc
|
from frappe.model.rename_doc import rename_doc
|
||||||
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
||||||
@@ -263,6 +264,15 @@ class TestItem(unittest.TestCase):
|
|||||||
self.assertEquals(variant.manufacturer, 'MSG1')
|
self.assertEquals(variant.manufacturer, 'MSG1')
|
||||||
self.assertEquals(variant.manufacturer_part_no, '007')
|
self.assertEquals(variant.manufacturer_part_no, '007')
|
||||||
|
|
||||||
|
def test_stock_exists_against_template_item(self):
|
||||||
|
stock_item = frappe.get_all('Stock Ledger Entry', fields = ["item_code"], limit=1)
|
||||||
|
if stock_item:
|
||||||
|
item_code = stock_item[0].item_code
|
||||||
|
|
||||||
|
item_doc = frappe.get_doc('Item', item_code)
|
||||||
|
item_doc.has_variants = 1
|
||||||
|
self.assertRaises(StockExistsForTemplate, item_doc.save)
|
||||||
|
|
||||||
def set_item_variant_settings(fields):
|
def set_item_variant_settings(fields):
|
||||||
doc = frappe.get_doc('Item Variant Settings')
|
doc = frappe.get_doc('Item Variant Settings')
|
||||||
doc.set('fields', fields)
|
doc.set('fields', fields)
|
||||||
|
|||||||
Reference in New Issue
Block a user