From a7d5f94d4a8aee612b611dcbb5d9e9b6c002eb84 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 18 Oct 2017 16:02:08 +0530 Subject: [PATCH] [fix] Do not append description to variant if description already exists (#11204) --- erpnext/controllers/item_variant.py | 7 +-- erpnext/patches.txt | 1 + .../v9_0/set_variant_item_description.py | 47 +++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 erpnext/patches/v9_0/set_variant_item_description.py diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py index 513b97f53a..8ca4f7096c 100644 --- a/erpnext/controllers/item_variant.py +++ b/erpnext/controllers/item_variant.py @@ -205,9 +205,10 @@ def copy_attributes_to_variant(item, variant): if item.variant_based_on=='Item Attribute': if variant.attributes: - variant.description += "\n" - for d in variant.attributes: - variant.description += "
" + d.attribute + ": " + cstr(d.attribute_value) + "
" + if not variant.description: + variant.description += "\n" + for d in variant.attributes: + variant.description += "
" + d.attribute + ": " + cstr(d.attribute_value) + "
" 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 0b9e8264ee..e7c0614b7a 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -450,3 +450,4 @@ erpnext.patches.v8_9.set_default_fields_in_variant_settings 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 0000000000..8093b04e2f --- /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 += "
" + d.attribute + ": " + cstr(d.attribute_value) + "
" + + 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