Merge pull request #24508 from frappe/rebrand-ui

diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
index af8d21d..f28cee7 100644
--- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
@@ -56,6 +56,7 @@
 		self.assertEqual(details.get("discount_percentage"), 10)
 
 		prule = frappe.get_doc(test_record.copy())
+		prule.priority = 1
 		prule.applicable_for = "Customer"
 		prule.title = "_Test Pricing Rule for Customer"
 		self.assertRaises(MandatoryError, prule.insert)
@@ -261,6 +262,7 @@
 			"rate_or_discount": "Discount Percentage",
 			"rate": 0,
 			"discount_percentage": 17.5,
+			"priority": 1,
 			"company": "_Test Company"
 		}).insert()
 
@@ -557,6 +559,7 @@
 		"rate": args.rate or 0.0,
 		"margin_rate_or_amount": args.margin_rate_or_amount or 0.0,
 		"condition": args.condition or '',
+		"priority": 1,
 		"apply_multiple_pricing_rules": args.apply_multiple_pricing_rules or 0
 	})
 
diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py
index fb1fbe4..d163335 100644
--- a/erpnext/accounts/doctype/pricing_rule/utils.py
+++ b/erpnext/accounts/doctype/pricing_rule/utils.py
@@ -41,10 +41,11 @@
 	if not pricing_rules: return []
 
 	if apply_multiple_pricing_rules(pricing_rules):
-		pricing_rules = sorted_by_priority(pricing_rules)
+		pricing_rules = sorted_by_priority(pricing_rules, args, doc)
 		for pricing_rule in pricing_rules:
-			pricing_rule = filter_pricing_rules(args, pricing_rule, doc)
-			if pricing_rule:
+			if isinstance(pricing_rule, list):
+				rules.extend(pricing_rule)
+			else:
 				rules.append(pricing_rule)
 	else:
 		pricing_rule = filter_pricing_rules(args, pricing_rules, doc)
@@ -53,17 +54,22 @@
 
 	return rules
 
-def sorted_by_priority(pricing_rules):
+def sorted_by_priority(pricing_rules, args, doc=None):
 	# If more than one pricing rules, then sort by priority
 	pricing_rules_list = []
 	pricing_rule_dict = {}
-	for pricing_rule in pricing_rules:
-		if not pricing_rule.get("priority"): continue
 
-		pricing_rule_dict.setdefault(cint(pricing_rule.get("priority")), []).append(pricing_rule)
+	for pricing_rule in pricing_rules:
+		pricing_rule = filter_pricing_rules(args, pricing_rule, doc)
+		if pricing_rule:
+			if not pricing_rule.get('priority'):
+				pricing_rule['priority'] = 1
+
+			if pricing_rule.get('apply_multiple_pricing_rules'):
+				pricing_rule_dict.setdefault(cint(pricing_rule.get("priority")), []).append(pricing_rule)
 
 	for key in sorted(pricing_rule_dict):
-		pricing_rules_list.append(pricing_rule_dict.get(key))
+		pricing_rules_list.extend(pricing_rule_dict.get(key))
 
 	return pricing_rules_list or pricing_rules
 
@@ -144,9 +150,7 @@
 
 	if not apply_multiple_rule: return False
 
-	if (apply_multiple_rule
-		and len(apply_multiple_rule) == len(pricing_rules)):
-		return True
+	return True
 
 def _get_tree_conditions(args, parenttype, table, allow_blank=True):
 	field = frappe.scrub(parenttype)
@@ -264,18 +268,6 @@
 		if max_priority:
 			pricing_rules = list(filter(lambda x: cint(x.priority)==max_priority, pricing_rules))
 
-	# apply internal priority
-	all_fields = ["item_code", "item_group", "brand", "customer", "customer_group", "territory",
-		"supplier", "supplier_group", "campaign", "sales_partner", "variant_of"]
-
-	if len(pricing_rules) > 1:
-		for field_set in [["item_code", "variant_of", "item_group", "brand"],
-			["customer", "customer_group", "territory"], ["supplier", "supplier_group"]]:
-				remaining_fields = list(set(all_fields) - set(field_set))
-				if if_all_rules_same(pricing_rules, remaining_fields):
-					pricing_rules = apply_internal_priority(pricing_rules, field_set, args)
-					break
-
 	if pricing_rules and not isinstance(pricing_rules, list):
 		pricing_rules = list(pricing_rules)
 
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index 64268b8..38b2284 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -39,7 +39,7 @@
 	party_details = frappe._dict(set_account_and_due_date(party, account, party_type, company, posting_date, bill_date, doctype))
 	party = party_details[party_type.lower()]
 
-	if not ignore_permissions and not frappe.has_permission(party_type, "read", party):
+	if not ignore_permissions and not (frappe.has_permission(party_type, "read", party) or frappe.has_permission(party_type, "select", party)):
 		frappe.throw(_("Not permitted for {0}").format(party), frappe.PermissionError)
 
 	party = frappe.get_doc(party_type, party)
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index c11bcee..21874fe 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -135,7 +135,7 @@
 
 	def before_cancel(self):
 		validate_einvoice_fields(self)
-	
+
 	def on_trash(self):
 		# delete sl and gl entries on deletion of transaction
 		if frappe.db.get_single_value('Accounts Settings', 'delete_linked_ledger_entries'):
diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py
index 77ba06e..cfa4991 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -613,7 +613,6 @@
 				self.doc.precision("base_write_off_amount"))
 
 	def calculate_margin(self, item):
-
 		rate_with_margin = 0.0
 		base_rate_with_margin = 0.0
 		if item.price_list_rate:
@@ -622,8 +621,8 @@
 				for d in get_applied_pricing_rules(item.pricing_rules):
 					pricing_rule = frappe.get_cached_doc('Pricing Rule', d)
 
-					if (pricing_rule.margin_type in ['Amount', 'Percentage'] and pricing_rule.currency == self.doc.currency)\
-							or (pricing_rule.margin_type == 'Percentage'):
+					if pricing_rule.margin_rate_or_amount and ((pricing_rule.currency == self.doc.currency and
+						pricing_rule.margin_type in ['Amount', 'Percentage']) or pricing_rule.margin_type == 'Percentage'):
 						item.margin_type = pricing_rule.margin_type
 						item.margin_rate_or_amount = pricing_rule.margin_rate_or_amount
 						has_margin = True
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 33c8e29..3b7c6ab 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -751,4 +751,4 @@
 erpnext.patches.v13_0.set_company_in_leave_ledger_entry
 erpnext.patches.v13_0.convert_qi_parameter_to_link_field
 erpnext.patches.v13_0.setup_patient_history_settings_for_standard_doctypes
-erpnext.patches.v13_0.add_naming_series_to_old_projects
+erpnext.patches.v13_0.add_naming_series_to_old_projects # 1-02-2021
diff --git a/erpnext/patches/v13_0/add_naming_series_to_old_projects.py b/erpnext/patches/v13_0/add_naming_series_to_old_projects.py
index 79b6753..5ed9040 100644
--- a/erpnext/patches/v13_0/add_naming_series_to_old_projects.py
+++ b/erpnext/patches/v13_0/add_naming_series_to_old_projects.py
@@ -4,23 +4,10 @@
 
 def execute():
 	frappe.reload_doc("projects", "doctype", "project")
-	projects = frappe.db.get_all("Project",
-		fields=["name", "naming_series", "modified"],
-		filters={
-			"naming_series": ["is", "not set"]
-		},
-		order_by="timestamp(modified) asc")
 
-	# disable set only once as the old docs must be saved
-	# (to bypass 'Cant change naming series' validation on save)
-	make_property_setter("Project", "naming_series", "set_only_once", 0, "Check")
+	frappe.db.sql("""UPDATE `tabProject`
+		SET
+			naming_series = 'PROJ-.####'
+		WHERE
+			naming_series is NULL""")
 
-	for entry in projects:
-		# need to save the doc so that users can edit old projects
-		doc = frappe.get_doc("Project", entry.name)
-		if not doc.naming_series:
-			doc.naming_series = "PROJ-.####"
-			doc.save()
-
-	delete_property_setter("Project", "set_only_once", "naming_series")
-	frappe.db.commit()
diff --git a/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json b/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json
index 3e81619..471e685 100644
--- a/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json
+++ b/erpnext/stock/doctype/item_quality_inspection_parameter/item_quality_inspection_parameter.json
@@ -8,7 +8,7 @@
  "field_order": [
   "specification",
   "value",
-  "non_numeric",
+  "numeric",
   "column_break_3",
   "min_value",
   "max_value",
@@ -29,7 +29,7 @@
    "width": "100px"
   },
   {
-   "depends_on": "eval:(!doc.formula_based_criteria && doc.non_numeric)",
+   "depends_on": "eval:(!doc.formula_based_criteria && !doc.numeric)",
    "fieldname": "value",
    "fieldtype": "Data",
    "in_list_view": 1,
@@ -55,32 +55,32 @@
    "label": "Formula Based Criteria"
   },
   {
-   "depends_on": "eval:(!doc.formula_based_criteria && !doc.non_numeric)",
+   "depends_on": "eval:(!doc.formula_based_criteria && doc.numeric)",
    "fieldname": "min_value",
    "fieldtype": "Float",
    "in_list_view": 1,
    "label": "Minimum Value"
   },
   {
-   "depends_on": "eval:(!doc.formula_based_criteria && !doc.non_numeric)",
+   "depends_on": "eval:(!doc.formula_based_criteria && doc.numeric)",
    "fieldname": "max_value",
    "fieldtype": "Float",
    "in_list_view": 1,
    "label": "Maximum Value"
   },
   {
-   "default": "0",
-   "fieldname": "non_numeric",
+   "default": "1",
+   "fieldname": "numeric",
    "fieldtype": "Check",
    "in_list_view": 1,
-   "label": "Non-Numeric",
+   "label": "Numeric",
    "width": "80px"
   }
  ],
  "idx": 1,
  "istable": 1,
  "links": [],
- "modified": "2021-01-07 21:32:49.866439",
+ "modified": "2021-02-01 19:18:46.924399",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Item Quality Inspection Parameter",
diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.py b/erpnext/stock/doctype/quality_inspection/quality_inspection.py
index b3acbc5..58b1eca 100644
--- a/erpnext/stock/doctype/quality_inspection/quality_inspection.py
+++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.py
@@ -97,7 +97,7 @@
 					self.set_status_based_on_acceptance_values(reading)
 
 	def set_status_based_on_acceptance_values(self, reading):
-		if cint(reading.non_numeric):
+		if not cint(reading.numeric):
 			result = reading.get("reading_value") == reading.get("value")
 		else:
 			# numeric readings
@@ -136,7 +136,7 @@
 
 	def get_formula_evaluation_data(self, reading):
 		data = {}
-		if cint(reading.non_numeric):
+		if not cint(reading.numeric):
 			data = {"reading_value": reading.get("reading_value")}
 		else:
 			# numeric readings
diff --git a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py
index 8c5a04b..a7dfc9e 100644
--- a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py
+++ b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py
@@ -55,7 +55,7 @@
 		},
 		{
 			"specification": "Particle Inspection Needed", # non-numeric reading
-			"non_numeric": 1,
+			"numeric": 0,
 			"value": "Yes",
 			"reading_value": "Yes"
 		}]
@@ -96,7 +96,7 @@
 		{
 			"specification": "Calcium Content", # non-numeric reading
 			"formula_based_criteria": 1,
-			"non_numeric": 1,
+			"numeric": 0,
 			"acceptance_formula": "reading_value in ('Grade A', 'Grade B', 'Grade C')",
 			"reading_value": "Grade B"
 		}]
diff --git a/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json b/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json
index 30ff1fe..35d58ef 100644
--- a/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json
+++ b/erpnext/stock/doctype/quality_inspection_reading/quality_inspection_reading.json
@@ -9,7 +9,7 @@
   "specification",
   "status",
   "value",
-  "non_numeric",
+  "numeric",
   "manual_inspection",
   "column_break_4",
   "min_value",
@@ -46,7 +46,7 @@
   },
   {
    "columns": 2,
-   "depends_on": "eval:(!doc.formula_based_criteria && doc.non_numeric)",
+   "depends_on": "eval:(!doc.formula_based_criteria && !doc.numeric)",
    "fieldname": "value",
    "fieldtype": "Data",
    "label": "Acceptance Criteria Value",
@@ -54,7 +54,7 @@
    "oldfieldtype": "Data"
   },
   {
-   "columns": 1,
+   "columns": 2,
    "fieldname": "reading_1",
    "fieldtype": "Data",
    "in_list_view": 1,
@@ -66,7 +66,6 @@
    "columns": 1,
    "fieldname": "reading_2",
    "fieldtype": "Data",
-   "in_list_view": 1,
    "label": "Reading 2",
    "oldfieldname": "reading_2",
    "oldfieldtype": "Data"
@@ -140,7 +139,7 @@
    "options": "\nAccepted\nRejected"
   },
   {
-   "depends_on": "non_numeric",
+   "depends_on": "eval:!doc.numeric",
    "fieldname": "section_break_3",
    "fieldtype": "Section Break",
    "label": "Value Based Inspection"
@@ -171,51 +170,52 @@
    "label": "Formula Based Criteria"
   },
   {
-   "depends_on": "eval:(!doc.formula_based_criteria && !doc.non_numeric)",
+   "depends_on": "eval:(!doc.formula_based_criteria && doc.numeric)",
    "description": "Applied on each reading.",
    "fieldname": "min_value",
    "fieldtype": "Float",
    "label": "Minimum Value"
   },
   {
-   "depends_on": "eval:(!doc.formula_based_criteria && !doc.non_numeric)",
+   "depends_on": "eval:(!doc.formula_based_criteria && doc.numeric)",
    "description": "Applied on each reading.",
    "fieldname": "max_value",
    "fieldtype": "Float",
    "label": "Maximum Value"
   },
   {
-   "depends_on": "non_numeric",
+   "columns": 2,
+   "depends_on": "eval:!doc.numeric",
    "fieldname": "reading_value",
    "fieldtype": "Data",
    "in_list_view": 1,
    "label": "Reading Value"
   },
   {
-   "depends_on": "eval:!doc.non_numeric",
+   "depends_on": "numeric",
    "fieldname": "section_break_14",
    "fieldtype": "Section Break",
    "label": "Numeric Inspection"
   },
   {
    "default": "0",
-   "fieldname": "non_numeric",
-   "fieldtype": "Check",
-   "in_list_view": 1,
-   "label": "Non-Numeric"
-  },
-  {
-   "default": "0",
    "description": "Set the status manually.",
    "fieldname": "manual_inspection",
    "fieldtype": "Check",
    "label": "Manual Inspection"
+  },
+  {
+   "default": "1",
+   "fieldname": "numeric",
+   "fieldtype": "Check",
+   "in_list_view": 1,
+   "label": "Numeric"
   }
  ],
  "idx": 1,
  "istable": 1,
  "links": [],
- "modified": "2021-01-07 22:16:53.978410",
+ "modified": "2021-02-01 19:46:22.138018",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Quality Inspection Reading",
diff --git a/erpnext/stock/doctype/quality_inspection_template/quality_inspection_template.py b/erpnext/stock/doctype/quality_inspection_template/quality_inspection_template.py
index c5a7974..01d2031 100644
--- a/erpnext/stock/doctype/quality_inspection_template/quality_inspection_template.py
+++ b/erpnext/stock/doctype/quality_inspection_template/quality_inspection_template.py
@@ -14,6 +14,6 @@
 
 	return frappe.get_all('Item Quality Inspection Parameter',
 		fields=["specification", "value", "acceptance_formula",
-			"non_numeric", "formula_based_criteria", "min_value", "max_value"],
+			"numeric", "formula_based_criteria", "min_value", "max_value"],
 		filters={'parenttype': 'Quality Inspection Template', 'parent': template},
 		order_by="idx")
\ No newline at end of file