fix: Item Variant Attribute Order (#17237)

- Show Item Variant Attributes in order they appear in child table
diff --git a/erpnext/portal/product_configurator/item_variants_cache.py b/erpnext/portal/product_configurator/item_variants_cache.py
index cd557b5..458c229 100644
--- a/erpnext/portal/product_configurator/item_variants_cache.py
+++ b/erpnext/portal/product_configurator/item_variants_cache.py
@@ -39,6 +39,19 @@
 
 		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
diff --git a/erpnext/portal/product_configurator/utils.py b/erpnext/portal/product_configurator/utils.py
index 3594bc4..f02212c 100644
--- a/erpnext/portal/product_configurator/utils.py
+++ b/erpnext/portal/product_configurator/utils.py
@@ -167,8 +167,13 @@
 		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