[fix] Do not append description to variant if description already exists (#11204)
This commit is contained in:
parent
7624e7bf85
commit
a7d5f94d4a
@ -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 += "<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"""
|
||||
|
@ -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
|
||||
|
47
erpnext/patches/v9_0/set_variant_item_description.py
Normal file
47
erpnext/patches/v9_0/set_variant_item_description.py
Normal file
@ -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()
|
Loading…
x
Reference in New Issue
Block a user