diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py index 66b3dd0a94..f8c9c0a841 100644 --- a/erpnext/controllers/item_variant.py +++ b/erpnext/controllers/item_variant.py @@ -169,7 +169,7 @@ def make_variant_item_code(template_item_code, variant): item_attribute = frappe.db.sql("""select i.numeric_values, v.abbr from `tabItem Attribute` i left join `tabItem Attribute Value` v on (i.name=v.parent) - where i.name=%(attribute)s and v.attribute_value=%(attribute_value)s""", { + where i.name=%(attribute)s and (v.attribute_value=%(attribute_value)s or i.numeric_values = 1)""", { "attribute": attr.attribute, "attribute_value": attr.attribute_value }, as_dict=True) @@ -180,11 +180,8 @@ def make_variant_item_code(template_item_code, variant): # frappe.bold(attr.attribute_value)), title=_('Invalid Attribute'), # exc=InvalidItemAttributeValueError) - if item_attribute[0].numeric_values: - # don't generate item code if one of the attributes is numeric - return - - abbreviations.append(item_attribute[0].abbr) + abbr_or_value = cstr(attr.attribute_value) if item_attribute[0].numeric_values else item_attribute[0].abbr + abbreviations.append(abbr_or_value) if abbreviations: variant.item_code = "{0}-{1}".format(template_item_code, "-".join(abbreviations)) diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js index 985bd4f950..abd03fe998 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -68,7 +68,7 @@ frappe.ui.form.on("Item", { frm.set_intro(__("This Item is a Variant of {0} (Template). Attributes will be copied over from the template unless 'No Copy' is set", [frm.doc.variant_of]), true); } - if (frappe.defaults.get_default("item_naming_by")!="Naming Series") { + if (frappe.defaults.get_default("item_naming_by")!="Naming Series" || frm.doc.variant_of) { frm.toggle_display("naming_series", false); } else { erpnext.toggle_naming_series(); diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py index 706fd5a1f4..15a11186e7 100644 --- a/erpnext/stock/doctype/item/test_item.py +++ b/erpnext/stock/doctype/item/test_item.py @@ -162,14 +162,14 @@ class TestItem(unittest.TestCase): variant = create_variant("_Test Numeric Template Item", {"Test Size": "Large", "Test Item Length": 1.1}) - self.assertEquals(variant.item_code, None) + self.assertEquals(variant.item_code, "_Test Numeric Template Item-L-1.1") variant.item_code = "_Test Numeric Variant-L-1.1" variant.item_name = "_Test Numeric Variant Large 1.1m" self.assertRaises(InvalidItemAttributeValueError, variant.save) variant = create_variant("_Test Numeric Template Item", {"Test Size": "Large", "Test Item Length": 1.5}) - self.assertEquals(variant.item_code, None) + self.assertEquals(variant.item_code, "_Test Numeric Template Item-L-1.5") variant.item_code = "_Test Numeric Variant-L-1.5" variant.item_name = "_Test Numeric Variant Large 1.5m" variant.save()