mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-01 04:28:27 +00:00
fix: allow variant uom to differ from template uom (#45850)
This commit is contained in:
committed by
GitHub
parent
58ed697ba5
commit
4f559b6df2
@@ -896,13 +896,17 @@ class Item(Document):
|
||||
for d in frappe.db.get_all("Item", filters={"variant_of": self.name}):
|
||||
check_stock_uom_with_bin(d.name, self.stock_uom)
|
||||
if self.variant_of:
|
||||
template_uom = frappe.db.get_value("Item", self.variant_of, "stock_uom")
|
||||
if template_uom != self.stock_uom:
|
||||
frappe.throw(
|
||||
_("Default Unit of Measure for Variant '{0}' must be same as in Template '{1}'").format(
|
||||
self.stock_uom, template_uom
|
||||
allow_different_uom = frappe.get_cached_value(
|
||||
"Item Variant Settings", "Item Variant Settings", "allow_different_uom"
|
||||
)
|
||||
if not allow_different_uom:
|
||||
template_uom = frappe.db.get_value("Item", self.variant_of, "stock_uom")
|
||||
if template_uom != self.stock_uom:
|
||||
frappe.throw(
|
||||
_(
|
||||
"Default Unit of Measure for Variant '{0}' must be same as in Template '{1}'"
|
||||
).format(self.stock_uom, template_uom)
|
||||
)
|
||||
)
|
||||
|
||||
def validate_uom_conversion_factor(self):
|
||||
if self.uoms:
|
||||
|
||||
@@ -933,6 +933,45 @@ class TestItem(IntegrationTestCase):
|
||||
|
||||
self.assertRaises(frappe.ValidationError, item_doc.save)
|
||||
|
||||
def test_variant_uom_mismatch_throws_error(self):
|
||||
frappe.db.set_single_value("Item Variant Settings", "allow_different_uom", 0)
|
||||
|
||||
template_item = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Item",
|
||||
"item_code": "_Test Template UOM",
|
||||
"item_name": "_Test Template UOM",
|
||||
"item_group": "_Test Item Group",
|
||||
"stock_uom": "Kg",
|
||||
"is_stock_item": 1,
|
||||
"has_variants": 1,
|
||||
"attributes": [
|
||||
{"attribute": "Test Size"},
|
||||
],
|
||||
}
|
||||
).insert()
|
||||
|
||||
with self.assertRaises(frappe.ValidationError) as ve:
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Item",
|
||||
"item_code": "_Test Variant UOM",
|
||||
"item_name": "_Test Variant UOM",
|
||||
"item_group": "_Test Item Group",
|
||||
"stock_uom": "Litre",
|
||||
"is_stock_item": 1,
|
||||
"variant_of": template_item.name,
|
||||
"attributes": [
|
||||
{"attribute": "Test Size", "attribute_value": "Small"},
|
||||
],
|
||||
}
|
||||
).insert()
|
||||
|
||||
self.assertTrue(
|
||||
"must be same as in Template" in str(ve.exception),
|
||||
msg="Different Variant UOM should not be allowed when `allow_different_uom` is disabled.",
|
||||
)
|
||||
|
||||
|
||||
def set_item_variant_settings(fields):
|
||||
doc = frappe.get_doc("Item Variant Settings")
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"section_break_3",
|
||||
"do_not_update_variants",
|
||||
"allow_rename_attribute_value",
|
||||
"allow_different_uom",
|
||||
"copy_fields_to_variant",
|
||||
"fields"
|
||||
],
|
||||
@@ -40,11 +41,17 @@
|
||||
"fieldtype": "Table",
|
||||
"label": "Fields",
|
||||
"options": "Variant Field"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "allow_different_uom",
|
||||
"fieldtype": "Check",
|
||||
"label": "Allow Variant UOM to be different from Template UOM"
|
||||
}
|
||||
],
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2024-03-27 13:09:56.095684",
|
||||
"modified": "2025-02-10 16:13:47.435148",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Item Variant Settings",
|
||||
|
||||
@@ -18,6 +18,7 @@ class ItemVariantSettings(Document):
|
||||
|
||||
from erpnext.stock.doctype.variant_field.variant_field import VariantField
|
||||
|
||||
allow_different_uom: DF.Check
|
||||
allow_rename_attribute_value: DF.Check
|
||||
do_not_update_variants: DF.Check
|
||||
fields: DF.Table[VariantField]
|
||||
|
||||
Reference in New Issue
Block a user