fix: Item Variant Attribute Order (#17237)

- Show Item Variant Attributes in order they appear in child table
This commit is contained in:
Faris Ansari 2019-04-15 23:19:44 +05:30 committed by GitHub
parent a5265113ce
commit 557520148e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -39,6 +39,19 @@ class ItemVariantsCacheManager:
return frappe.cache().hget('optional_attributes', self.item_code)
def get_ordered_attribute_values(self):
val = frappe.cache().get_value('ordered_attribute_values_map')
if val: return val
all_attribute_values = frappe.db.get_all('Item Attribute Value',
['attribute_value', 'idx', 'parent'], order_by='idx asc')
ordered_attribute_values_map = frappe._dict({})
for d in all_attribute_values:
ordered_attribute_values_map.setdefault(d.parent, []).append(d.attribute_value)
frappe.cache().set_value('ordered_attribute_values_map', ordered_attribute_values_map)
return ordered_attribute_values_map
def build_cache(self):
parent_item_code = self.item_code

View File

@ -167,8 +167,13 @@ def get_attributes_and_values(item_code):
if attribute in attribute_list:
valid_options.setdefault(attribute, set()).add(attribute_value)
# build attribute values in idx order
ordered_attribute_value_map = item_cache.get_ordered_attribute_values()
for attr in attributes:
attr['values'] = valid_options.get(attr.attribute, [])
valid_attribute_values = valid_options.get(attr.attribute, [])
ordered_values = ordered_attribute_value_map.get(attr.attribute, [])
attr['values'] = [v for v in ordered_values if v in valid_attribute_values]
attr['values'] = valid_attribute_values
return attributes