[Fix] Item variants broken when using naming series for items and vriants of numeric value
This commit is contained in:
parent
89d494fbf5
commit
0169341917
@ -169,7 +169,7 @@ def make_variant_item_code(template_item_code, variant):
|
|||||||
item_attribute = frappe.db.sql("""select i.numeric_values, v.abbr
|
item_attribute = frappe.db.sql("""select i.numeric_values, v.abbr
|
||||||
from `tabItem Attribute` i left join `tabItem Attribute Value` v
|
from `tabItem Attribute` i left join `tabItem Attribute Value` v
|
||||||
on (i.name=v.parent)
|
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": attr.attribute,
|
||||||
"attribute_value": attr.attribute_value
|
"attribute_value": attr.attribute_value
|
||||||
}, as_dict=True)
|
}, as_dict=True)
|
||||||
@ -180,11 +180,8 @@ def make_variant_item_code(template_item_code, variant):
|
|||||||
# frappe.bold(attr.attribute_value)), title=_('Invalid Attribute'),
|
# frappe.bold(attr.attribute_value)), title=_('Invalid Attribute'),
|
||||||
# exc=InvalidItemAttributeValueError)
|
# exc=InvalidItemAttributeValueError)
|
||||||
|
|
||||||
if item_attribute[0].numeric_values:
|
abbr_or_value = cstr(attr.attribute_value) if item_attribute[0].numeric_values else item_attribute[0].abbr
|
||||||
# don't generate item code if one of the attributes is numeric
|
abbreviations.append(abbr_or_value)
|
||||||
return
|
|
||||||
|
|
||||||
abbreviations.append(item_attribute[0].abbr)
|
|
||||||
|
|
||||||
if abbreviations:
|
if abbreviations:
|
||||||
variant.item_code = "{0}-{1}".format(template_item_code, "-".join(abbreviations))
|
variant.item_code = "{0}-{1}".format(template_item_code, "-".join(abbreviations))
|
||||||
|
|||||||
@ -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);
|
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);
|
frm.toggle_display("naming_series", false);
|
||||||
} else {
|
} else {
|
||||||
erpnext.toggle_naming_series();
|
erpnext.toggle_naming_series();
|
||||||
|
|||||||
@ -162,14 +162,14 @@ class TestItem(unittest.TestCase):
|
|||||||
|
|
||||||
variant = create_variant("_Test Numeric Template Item",
|
variant = create_variant("_Test Numeric Template Item",
|
||||||
{"Test Size": "Large", "Test Item Length": 1.1})
|
{"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_code = "_Test Numeric Variant-L-1.1"
|
||||||
variant.item_name = "_Test Numeric Variant Large 1.1m"
|
variant.item_name = "_Test Numeric Variant Large 1.1m"
|
||||||
self.assertRaises(InvalidItemAttributeValueError, variant.save)
|
self.assertRaises(InvalidItemAttributeValueError, variant.save)
|
||||||
|
|
||||||
variant = create_variant("_Test Numeric Template Item",
|
variant = create_variant("_Test Numeric Template Item",
|
||||||
{"Test Size": "Large", "Test Item Length": 1.5})
|
{"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_code = "_Test Numeric Variant-L-1.5"
|
||||||
variant.item_name = "_Test Numeric Variant Large 1.5m"
|
variant.item_name = "_Test Numeric Variant Large 1.5m"
|
||||||
variant.save()
|
variant.save()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user