From 9d44ac88f2a4181db268a25c5a4c22a3ed073c48 Mon Sep 17 00:00:00 2001 From: gabtzi Date: Mon, 28 Dec 2015 10:26:42 +0200 Subject: [PATCH 1/4] Fix for Issue #4543: Automatic item_code generation for variants when parent item is named after a Naming Series --- erpnext/stock/doctype/item/item.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index dfe17e89fc..12c39dbdc3 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -33,6 +33,11 @@ class Item(WebsiteGenerator): if frappe.db.get_default("item_naming_by")=="Naming Series" and not self.variant_of: from frappe.model.naming import make_autoname self.item_code = make_autoname(self.naming_series+'.#####') + elif frappe.db.get_default("item_naming_by")=="Naming Series" and self.variant_of: + item_code_suffix = "" + for attribute in self.attributes: + item_code_suffix += "-" + str(attribute.attribute_value) + self.item_code = str(self.variant_of) + item_code_suffix elif not self.item_code: msgprint(_("Item Code is mandatory because Item is not automatically numbered"), raise_exception=1) From 096fc8820080757adf6dd1a1140690ee721b50a6 Mon Sep 17 00:00:00 2001 From: gabtzi Date: Mon, 28 Dec 2015 11:07:10 +0200 Subject: [PATCH 2/4] Fix for Issue #4543: Improved code to check if it's a variant only once. --- erpnext/stock/doctype/item/item.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 12c39dbdc3..830e62d549 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -30,14 +30,15 @@ class Item(WebsiteGenerator): self.get("__onload").sle_exists = self.check_if_sle_exists() def autoname(self): - if frappe.db.get_default("item_naming_by")=="Naming Series" and not self.variant_of: - from frappe.model.naming import make_autoname - self.item_code = make_autoname(self.naming_series+'.#####') - elif frappe.db.get_default("item_naming_by")=="Naming Series" and self.variant_of: - item_code_suffix = "" - for attribute in self.attributes: - item_code_suffix += "-" + str(attribute.attribute_value) - self.item_code = str(self.variant_of) + item_code_suffix + if frappe.db.get_default("item_naming_by")=="Naming Series": + if self.variant_of: + item_code_suffix = "" + for attribute in self.attributes: + item_code_suffix += "-" + str(attribute.attribute_value) + self.item_code = str(self.variant_of) + item_code_suffix + else: + from frappe.model.naming import make_autoname + self.item_code = make_autoname(self.naming_series+'.#####') elif not self.item_code: msgprint(_("Item Code is mandatory because Item is not automatically numbered"), raise_exception=1) From d46abb49f33b5346983b07fdd1959720582d27a9 Mon Sep 17 00:00:00 2001 From: gabtzi Date: Mon, 28 Dec 2015 12:03:24 +0200 Subject: [PATCH 3/4] Fix for Issue #4543: Suffix now uses attribute abbreviation if it exists or value for numeric attributes --- erpnext/stock/doctype/item/item.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 830e62d549..7ac7a15dcd 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -34,7 +34,8 @@ class Item(WebsiteGenerator): if self.variant_of: item_code_suffix = "" for attribute in self.attributes: - item_code_suffix += "-" + str(attribute.attribute_value) + attribute_abbr = frappe.db.get_value("Item Attribute Value", {"parent": attribute.attribute, "attribute_value": attribute.attribute_value}, "abbr") + item_code_suffix += "-" + str(attribute_abbr or attribute.attribute_value) self.item_code = str(self.variant_of) + item_code_suffix else: from frappe.model.naming import make_autoname From 51ff2658cb4e674f03263b96272a488a168af5fe Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 31 Dec 2015 15:48:48 +0530 Subject: [PATCH 4/4] [fix] Minor changes in item naming --- erpnext/stock/doctype/item/item.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 67f3a25376..fe13fa17ea 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -32,11 +32,13 @@ class Item(WebsiteGenerator): def autoname(self): if frappe.db.get_default("item_naming_by")=="Naming Series": if self.variant_of: - item_code_suffix = "" - for attribute in self.attributes: - attribute_abbr = frappe.db.get_value("Item Attribute Value", {"parent": attribute.attribute, "attribute_value": attribute.attribute_value}, "abbr") - item_code_suffix += "-" + str(attribute_abbr or attribute.attribute_value) - self.item_code = str(self.variant_of) + item_code_suffix + if not self.item_code: + item_code_suffix = "" + for attribute in self.attributes: + attribute_abbr = frappe.db.get_value("Item Attribute Value", + {"parent": attribute.attribute, "attribute_value": attribute.attribute_value}, "abbr") + item_code_suffix += "-" + str(attribute_abbr or attribute.attribute_value) + self.item_code = str(self.variant_of) + item_code_suffix else: from frappe.model.naming import make_autoname self.item_code = make_autoname(self.naming_series+'.#####')