[fix] Do not append description to variant if description already exists (#11204)
diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py
index 513b97f..8ca4f70 100644
--- a/erpnext/controllers/item_variant.py
+++ b/erpnext/controllers/item_variant.py
@@ -205,9 +205,10 @@
if item.variant_based_on=='Item Attribute':
if variant.attributes:
- variant.description += "\n"
- for d in variant.attributes:
- variant.description += "<div>" + d.attribute + ": " + cstr(d.attribute_value) + "</div>"
+ if not variant.description:
+ variant.description += "\n"
+ for d in variant.attributes:
+ variant.description += "<div>" + d.attribute + ": " + cstr(d.attribute_value) + "</div>"
def make_variant_item_code(template_item_code, template_item_name, variant):
"""Uses template's item code and abbreviations to make variant's item code"""
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 0b9e826..e7c0614 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -450,3 +450,4 @@
erpnext.patches.v8_9.update_billing_gstin_for_indian_account
erpnext.patches.v9_0.fix_subscription_next_date
erpnext.patches.v9_0.add_healthcare_domain
+erpnext.patches.v9_0.set_variant_item_description
diff --git a/erpnext/patches/v9_0/set_variant_item_description.py b/erpnext/patches/v9_0/set_variant_item_description.py
new file mode 100644
index 0000000..8093b04
--- /dev/null
+++ b/erpnext/patches/v9_0/set_variant_item_description.py
@@ -0,0 +1,47 @@
+import frappe
+from frappe.utils import cstr
+
+def execute():
+ '''
+ Issue:
+ While copying data from template item to variant item,
+ the system appending description multiple times to the respective variant.
+
+ Purpose:
+ Check variant description,
+ if variant have user defined description remove all system appended descriptions
+ else replace multiple system generated descriptions with single description
+
+ Steps:
+ 1. Get all variant items
+ 2. Create system generated variant description
+ 3. If variant have user defined description, remove all system generated descriptions
+ 4. If variant description only contains system generated description,
+ replace multiple descriptions by new description.
+ '''
+ for item in frappe.db.sql(""" select name from tabItem
+ where ifnull(variant_of, '') != '' """,as_dict=1):
+ variant = frappe.get_doc("Item", item.name)
+ temp_variant_description = '\n'
+
+ if variant.attributes:
+ for d in variant.attributes:
+ temp_variant_description += "<div>" + d.attribute + ": " + cstr(d.attribute_value) + "</div>"
+
+ variant_description = variant.description.replace(temp_variant_description, '').rstrip()
+ if variant_description:
+ splitted_desc = variant.description.strip().split(temp_variant_description)
+
+ if len(splitted_desc) > 2:
+ if splitted_desc[0] == '':
+ variant_description = temp_variant_description + variant_description
+ elif splitted_desc[1] == '' or splitted_desc[1] == '\n':
+ variant_description += temp_variant_description
+
+ variant.db_set('description', variant_description, update_modified=False)
+
+ else:
+ variant.db_set('description', temp_variant_description, update_modified=False)
+
+ variant.flags.ignore_permissions=True
+ variant.save()
\ No newline at end of file