Merge pull request #22571 from marination/quality-feedback

fix: Quality Feedback and Template (minor)
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index db91b66..b764eff 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -388,7 +388,7 @@
 	from erpnext.accounts.doctype.tax_rule.tax_rule import get_tax_template, get_party_details
 	args = {
 		party_type.lower(): party,
-		"company":			company
+		"company": company
 	}
 
 	if tax_category:
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 16146f4..69866e1 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -133,7 +133,7 @@
 		acc = frappe.get_doc("Account", account)
 
 	try:
-		year_start_date = get_fiscal_year(date, verbose=0)[1]
+		year_start_date = get_fiscal_year(date, company=company, verbose=0)[1]
 	except FiscalYearError:
 		if getdate(date) > getdate(nowdate()):
 			# if fiscal year not found and the date is greater than today
@@ -787,10 +787,10 @@
 		company_currency = frappe.get_cached_value('Company',  company,  "default_currency")
 		for each in acc:
 			each["company_currency"] = company_currency
-			each["balance"] = flt(get_balance_on(each.get("value"), in_account_currency=False))
+			each["balance"] = flt(get_balance_on(each.get("value"), in_account_currency=False, company=company))
 
 			if each.account_currency != company_currency:
-				each["balance_in_account_currency"] = flt(get_balance_on(each.get("value")))
+				each["balance_in_account_currency"] = flt(get_balance_on(each.get("value"), company=company))
 
 	return acc
 
diff --git a/erpnext/loan_management/doctype/loan/test_loan.py b/erpnext/loan_management/doctype/loan/test_loan.py
index 1f771c2..c65996e 100644
--- a/erpnext/loan_management/doctype/loan/test_loan.py
+++ b/erpnext/loan_management/doctype/loan/test_loan.py
@@ -79,10 +79,12 @@
 			"qty": 4000.00,
 		}]
 
-		loan_application = create_loan_application('_Test Company', self.applicant2, 'Stock Loan', pledge, "Repay Over Number of Periods", 12)
+		loan_application = create_loan_application('_Test Company', self.applicant2,
+			'Stock Loan', pledge, "Repay Over Number of Periods", 12)
 		create_pledge(loan_application)
 
-		loan = create_loan_with_security(self.applicant2, "Stock Loan", "Repay Over Number of Periods", 12, loan_application)
+		loan = create_loan_with_security(self.applicant2, "Stock Loan", "Repay Over Number of Periods",
+			12, loan_application)
 		self.assertEquals(loan.loan_amount, 1000000)
 
 	def test_loan_disbursement(self):
@@ -92,6 +94,7 @@
 		}]
 
 		loan_application = create_loan_application('_Test Company', self.applicant2, 'Stock Loan', pledge, "Repay Over Number of Periods", 12)
+
 		create_pledge(loan_application)
 
 		loan = create_loan_with_security(self.applicant2, "Stock Loan", "Repay Over Number of Periods", 12, loan_application)
@@ -217,7 +220,8 @@
 			"qty": 2000.00
 		}]
 
-		loan_application = create_loan_application('_Test Company', self.applicant2, 'Stock Loan', pledges)
+		loan_application = create_loan_application('_Test Company', self.applicant2, 'Stock Loan', pledges,
+			"Repay Over Number of Periods", 12)
 		create_pledge(loan_application)
 
 		loan = create_loan_with_security(self.applicant2, "Stock Loan", "Repay Over Number of Periods", 12, loan_application,
@@ -247,7 +251,9 @@
 			"haircut": 50,
 		}]
 
-		loan_application = create_loan_application('_Test Company', self.applicant2, 'Stock Loan', pledges)
+		loan_application = create_loan_application('_Test Company', self.applicant2,
+			'Stock Loan', pledges, "Repay Over Number of Periods", 12)
+
 		create_pledge(loan_application)
 
 		loan = create_loan_with_security(self.applicant2, "Stock Loan", "Repay Over Number of Periods", 12, loan_application)
diff --git a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py
index be9a2d3..37cd89a 100644
--- a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py
+++ b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py
@@ -105,7 +105,7 @@
 		#Gross pay calculation based on attendances
 		gross_pay = 78000 - ((78000 / (days_in_month - no_of_holidays)) * flt(ss.leave_without_pay))
 
-		self.assertEqual(ss.gross_pay, gross_pay)
+		self.assertEqual(flt(ss.gross_pay, 2), flt(gross_pay, 2))
 
 		frappe.db.set_value("Payroll Settings", None, "payroll_based_on", "Leave")
 
diff --git a/erpnext/public/js/utils/party.js b/erpnext/public/js/utils/party.js
index 99c1b8a..0653267 100644
--- a/erpnext/public/js/utils/party.js
+++ b/erpnext/public/js/utils/party.js
@@ -4,7 +4,7 @@
 frappe.provide("erpnext.utils");
 
 erpnext.utils.get_party_details = function(frm, method, args, callback) {
-	if(!method) {
+	if (!method) {
 		method = "erpnext.accounts.party.get_party_details";
 	}
 
@@ -22,12 +22,12 @@
 		}
 	}
 
-	if(!args) {
-		if((frm.doctype != "Purchase Order" && frm.doc.customer)
+	if (!args) {
+		if ((frm.doctype != "Purchase Order" && frm.doc.customer)
 			|| (frm.doc.party_name && in_list(['Quotation', 'Opportunity'], frm.doc.doctype))) {
 
 			let party_type = "Customer";
-			if(frm.doc.quotation_to && frm.doc.quotation_to === "Lead") {
+			if (frm.doc.quotation_to && frm.doc.quotation_to === "Lead") {
 				party_type = "Lead";
 			}
 
@@ -36,7 +36,7 @@
 				party_type: party_type,
 				price_list: frm.doc.selling_price_list
 			};
-		} else if(frm.doc.supplier) {
+		} else if (frm.doc.supplier) {
 			args = {
 				party: frm.doc.supplier,
 				party_type: "Supplier",
@@ -78,13 +78,17 @@
 			args.posting_date = frm.doc.posting_date || frm.doc.transaction_date;
 		}
 	}
-	if(!args || !args.party) return;
+	if (!args || !args.party) return;
 
-	if(frappe.meta.get_docfield(frm.doc.doctype, "taxes")) {
-		if(!erpnext.utils.validate_mandatory(frm, "Posting/Transaction Date",
+	if (frappe.meta.get_docfield(frm.doc.doctype, "taxes")) {
+		if (!erpnext.utils.validate_mandatory(frm, "Posting / Transaction Date",
 			args.posting_date, args.party_type=="Customer" ? "customer": "supplier")) return;
 	}
 
+	if (!erpnext.utils.validate_mandatory(frm, "Company", frm.doc.company, args.party_type=="Customer" ? "customer": "supplier")) {
+		return;
+	}
+
 	args.currency = frm.doc.currency;
 	args.company = frm.doc.company;
 	args.doctype = frm.doc.doctype;
@@ -92,14 +96,14 @@
 		method: method,
 		args: args,
 		callback: function(r) {
-			if(r.message) {
+			if (r.message) {
 				frm.supplier_tds = r.message.supplier_tds;
 				frm.updating_party_details = true;
 				frappe.run_serially([
 					() => frm.set_value(r.message),
 					() => {
 						frm.updating_party_details = false;
-						if(callback) callback();
+						if (callback) callback();
 						frm.refresh();
 						erpnext.utils.add_item(frm);
 					}
@@ -110,9 +114,9 @@
 }
 
 erpnext.utils.add_item = function(frm) {
-	if(frm.is_new()) {
+	if (frm.is_new()) {
 		var prev_route = frappe.get_prev_route();
-		if(prev_route[1]==='Item' && !(frm.doc.items && frm.doc.items.length)) {
+		if (prev_route[1]==='Item' && !(frm.doc.items && frm.doc.items.length)) {
 			// add row
 			var item = frm.add_child('items');
 			frm.refresh_field('items');
@@ -124,23 +128,23 @@
 }
 
 erpnext.utils.get_address_display = function(frm, address_field, display_field, is_your_company_address) {
-	if(frm.updating_party_details) return;
+	if (frm.updating_party_details) return;
 
-	if(!address_field) {
-		if(frm.doctype != "Purchase Order" && frm.doc.customer) {
+	if (!address_field) {
+		if (frm.doctype != "Purchase Order" && frm.doc.customer) {
 			address_field = "customer_address";
-		} else if(frm.doc.supplier) {
+		} else if (frm.doc.supplier) {
 			address_field = "supplier_address";
 		} else return;
 	}
 
-	if(!display_field) display_field = "address_display";
-	if(frm.doc[address_field]) {
+	if (!display_field) display_field = "address_display";
+	if (frm.doc[address_field]) {
 		frappe.call({
 			method: "frappe.contacts.doctype.address.address.get_address_display",
 			args: {"address_dict": frm.doc[address_field] },
 			callback: function(r) {
-				if(r.message) {
+				if (r.message) {
 					frm.set_value(display_field, r.message)
 				}
 			}
@@ -151,15 +155,15 @@
 };
 
 erpnext.utils.set_taxes_from_address = function(frm, triggered_from_field, billing_address_field, shipping_address_field) {
-	if(frm.updating_party_details) return;
+	if (frm.updating_party_details) return;
 
-	if(frappe.meta.get_docfield(frm.doc.doctype, "taxes")) {
-		if(!erpnext.utils.validate_mandatory(frm, "Lead/Customer/Supplier",
+	if (frappe.meta.get_docfield(frm.doc.doctype, "taxes")) {
+		if (!erpnext.utils.validate_mandatory(frm, "Lead / Customer / Supplier",
 			frm.doc.customer || frm.doc.supplier || frm.doc.lead || frm.doc.party_name, triggered_from_field)) {
 			return;
 		}
 
-		if(!erpnext.utils.validate_mandatory(frm, "Posting/Transaction Date",
+		if (!erpnext.utils.validate_mandatory(frm, "Posting / Transaction Date",
 			frm.doc.posting_date || frm.doc.transaction_date, triggered_from_field)) {
 			return;
 		}
@@ -175,8 +179,8 @@
 			"shipping_address": frm.doc[shipping_address_field]
 		},
 		callback: function(r) {
-			if(!r.exc){
-				if(frm.doc.tax_category != r.message) {
+			if (!r.exc){
+				if (frm.doc.tax_category != r.message) {
 					frm.set_value("tax_category", r.message);
 				} else {
 					erpnext.utils.set_taxes(frm, triggered_from_field);
@@ -187,13 +191,17 @@
 };
 
 erpnext.utils.set_taxes = function(frm, triggered_from_field) {
-	if(frappe.meta.get_docfield(frm.doc.doctype, "taxes")) {
-		if(!erpnext.utils.validate_mandatory(frm, "Lead/Customer/Supplier",
+	if (frappe.meta.get_docfield(frm.doc.doctype, "taxes")) {
+		if (!erpnext.utils.validate_mandatory(frm, "Company", frm.doc.company, triggered_from_field)) {
+			return;
+		}
+
+		if (!erpnext.utils.validate_mandatory(frm, "Lead / Customer / Supplier",
 			frm.doc.customer || frm.doc.supplier || frm.doc.lead || frm.doc.party_name, triggered_from_field)) {
 			return;
 		}
 
-		if(!erpnext.utils.validate_mandatory(frm, "Posting/Transaction Date",
+		if (!erpnext.utils.validate_mandatory(frm, "Posting / Transaction Date",
 			frm.doc.posting_date || frm.doc.transaction_date, triggered_from_field)) {
 			return;
 		}
@@ -230,7 +238,7 @@
 			"shipping_address": frm.doc.shipping_address_name
 		},
 		callback: function(r) {
-			if(r.message){
+			if (r.message){
 				frm.set_value("taxes_and_charges", r.message)
 			}
 		}
@@ -238,14 +246,14 @@
 };
 
 erpnext.utils.get_contact_details = function(frm) {
-	if(frm.updating_party_details) return;
+	if (frm.updating_party_details) return;
 
-	if(frm.doc["contact_person"]) {
+	if (frm.doc["contact_person"]) {
 		frappe.call({
 			method: "frappe.contacts.doctype.contact.contact.get_contact_details",
 			args: {contact: frm.doc.contact_person },
 			callback: function(r) {
-				if(r.message)
+				if (r.message)
 					frm.set_value(r.message);
 			}
 		})
@@ -253,10 +261,10 @@
 }
 
 erpnext.utils.validate_mandatory = function(frm, label, value, trigger_on) {
-	if(!value) {
+	if (!value) {
 		frm.doc[trigger_on] = "";
 		refresh_field(trigger_on);
-		frappe.msgprint(__("Please enter {0} first", [label]));
+		frappe.throw({message:__("Please enter {0} first", [label]), title:__("Mandatory")});
 		return false;
 	}
 	return true;
@@ -271,12 +279,12 @@
 				address: frm.doc.shipping_address
 			},
 			callback: function(r){
-				if(r.message){
+				if (r.message){
 					frm.set_value("shipping_address", r.message[0]) //Address title or name
 					frm.set_value("shipping_address_display", r.message[1]) //Address to be displayed on the page
 				}
 
-				if(callback){
+				if (callback){
 					return callback();
 				}
 			}
diff --git a/erpnext/regional/united_arab_emirates/utils.py b/erpnext/regional/united_arab_emirates/utils.py
index 772bbf5..a0425f6 100644
--- a/erpnext/regional/united_arab_emirates/utils.py
+++ b/erpnext/regional/united_arab_emirates/utils.py
@@ -11,14 +11,17 @@
 
 	for row in doc.items:
 		tax_rate = 0.0
-		item_tax_rate = frappe.parse_json(row.item_tax_rate)
+		item_tax_rate = 0.0
+
+		if row.item_tax_rate:
+			item_tax_rate = frappe.parse_json(row.item_tax_rate)
 
 		# First check if tax rate is present
 		# If not then look up in item_wise_tax_detail
 		if item_tax_rate:
 			for account, rate in iteritems(item_tax_rate):
 				tax_rate += rate
-		elif itemised_tax.get(row.item_code):
+		elif row.item_code and itemised_tax.get(row.item_code):
 			tax_rate = sum([tax.get('tax_rate', 0) for d, tax in itemised_tax.get(row.item_code).items()])
 
 		row.tax_rate = flt(tax_rate, row.precision("tax_rate"))