Merge pull request #17235 from hrwX/remove_asset_permission_v12

fix(Asset): Remove user permission for employee in asset
diff --git a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py
index 3063606..3b08931 100644
--- a/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py
+++ b/erpnext/accounts/dashboard_chart_source/account_balance_timeline/account_balance_timeline.py
@@ -20,10 +20,10 @@
 	account = filters.get("account")
 	company = filters.get("company")
 
-	if not from_date:
-		from_date = get_from_date_from_timespan(to_date, timespan)
 	if not to_date:
 		to_date = nowdate()
+	if not from_date:
+		from_date = get_from_date_from_timespan(to_date, timespan)
 
 	# fetch dates to plot
 	dates = get_dates_from_timegrain(from_date, to_date, timegrain)
@@ -66,7 +66,7 @@
 	# for balance sheet accounts, the totals are cumulative
 	if root_type in ('Asset', 'Liability', 'Equity'):
 		for i, r in enumerate(result):
-			if i < 0:
+			if i > 0:
 				r[1] = r[1] + result[i-1][1]
 
 	return result
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