Release testing fixes develop (#20987)

* fix: Multiple fixes during pre-release testing

* fix: Merge conflict
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 2cbd40b..eb3017a 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -454,8 +454,10 @@
 	def set_print_format_fields(self):
 		bank_amount = party_amount = total_amount = 0.0
 		currency = bank_account_currency = party_account_currency = pay_to_recd_from= None
+		party_type = None
 		for d in self.get('accounts'):
 			if d.party_type in ['Customer', 'Supplier'] and d.party:
+				party_type = d.party_type
 				if not pay_to_recd_from:
 					pay_to_recd_from = d.party
 
@@ -467,9 +469,9 @@
 				bank_amount += (d.debit_in_account_currency or d.credit_in_account_currency)
 				bank_account_currency = d.account_currency
 
-		if pay_to_recd_from:
-			self.pay_to_recd_from = frappe.db.get_value(d.party_type, pay_to_recd_from,
-				"customer_name" if d.party_type=="Customer" else "supplier_name")
+		if party_type and pay_to_recd_from:
+			self.pay_to_recd_from = frappe.db.get_value(party_type, pay_to_recd_from,
+				"customer_name" if party_type=="Customer" else "supplier_name")
 			if bank_amount:
 				total_amount = bank_amount
 				currency = bank_account_currency
diff --git a/erpnext/hr/doctype/vehicle_log/test_vehicle_log.py b/erpnext/hr/doctype/vehicle_log/test_vehicle_log.py
index 3770da7..e9dc776 100644
--- a/erpnext/hr/doctype/vehicle_log/test_vehicle_log.py
+++ b/erpnext/hr/doctype/vehicle_log/test_vehicle_log.py
@@ -6,11 +6,14 @@
 import frappe
 import unittest
 from frappe.utils import nowdate,flt, cstr,random_string
-# test_records = frappe.get_test_records('Vehicle Log')
+
 class TestVehicleLog(unittest.TestCase):
 	def test_make_vehicle_log_and_syncing_of_odometer_value(self):
-		employee_id=frappe.db.sql("""select name from `tabEmployee` order by modified desc limit 1""")[0][0]
+		employee_id = frappe.db.sql("""select name from `tabEmployee` where status='Active' order by modified desc limit 1""")
+		employee_id = employee_id[0][0] if employee_id else None
+
 		license_plate = get_vehicle(employee_id)
+
 		vehicle_log = frappe.get_doc({
 			"doctype": "Vehicle Log",
 			"license_plate": cstr(license_plate),
diff --git a/erpnext/hr/doctype/vehicle_log/vehicle_log.js b/erpnext/hr/doctype/vehicle_log/vehicle_log.js
index bdb37d2..6f3a0dc 100644
--- a/erpnext/hr/doctype/vehicle_log/vehicle_log.js
+++ b/erpnext/hr/doctype/vehicle_log/vehicle_log.js
@@ -3,11 +3,6 @@
 
 frappe.ui.form.on("Vehicle Log", {
 	refresh: function(frm) {
-
-		if(frm.doc.license_plate && frm.doc.__islocal){
-			frm.events.set_vehicle_details(frm);
-		}
-
 		if(frm.doc.docstatus == 1) {
 			frm.add_custom_button(__('Expense Claim'), function() {
 				frm.events.expense_claim(frm);
@@ -16,27 +11,6 @@
 		}
 	},
 
-	license_plate: function(frm) {
-		if(frm.doc.license_plate){
-			frm.events.set_vehicle_details(frm);
-		}
-	},
-
-	set_vehicle_details: function(frm) {
-		frappe.call({
-			method: "erpnext.hr.doctype.vehicle_log.vehicle_log.get_make_model",
-			args: {
-				license_plate: frm.doc.license_plate
-			},
-			callback: function(r) {
-				frappe.model.set_value(cur_frm.doctype, cur_frm.docname, "make", r.message[0]);
-				frappe.model.set_value(cur_frm.doctype, cur_frm.docname, "model", r.message[1]);
-				frappe.model.set_value(cur_frm.doctype, cur_frm.docname, "last_odometer", r.message[2]);
-				frappe.model.set_value(cur_frm.doctype, cur_frm.docname, "employee", r.message[3]);
-			}
-		});
-	},
-
 	expense_claim: function(frm){
 		frappe.call({
 			method: "erpnext.hr.doctype.vehicle_log.vehicle_log.make_expense_claim",
diff --git a/erpnext/hr/doctype/vehicle_log/vehicle_log.json b/erpnext/hr/doctype/vehicle_log/vehicle_log.json
index 52effff..619e295 100644
--- a/erpnext/hr/doctype/vehicle_log/vehicle_log.json
+++ b/erpnext/hr/doctype/vehicle_log/vehicle_log.json
@@ -1,5 +1,4 @@
 {
- "actions": [],
  "autoname": "naming_series:",
  "creation": "2016-09-03 14:14:51.788550",
  "doctype": "DocType",
@@ -56,6 +55,8 @@
    "reqd": 1
   },
   {
+   "fetch_from": "license_plate.employee",
+   "fetch_if_empty": 1,
    "fieldname": "employee",
    "fieldtype": "Link",
    "in_list_view": 1,
@@ -73,11 +74,13 @@
    "fieldtype": "Column Break"
   },
   {
+   "fetch_from": "license_plate.model",
    "fieldname": "model",
    "fieldtype": "Read Only",
    "label": "Model"
   },
   {
+   "fetch_from": "license_plate.make",
    "fieldname": "make",
    "fieldtype": "Read Only",
    "label": "Make"
@@ -152,6 +155,7 @@
    "read_only": 1
   },
   {
+   "fetch_from": "license_plate.last_odometer",
    "fieldname": "last_odometer",
    "fieldtype": "Int",
    "label": "last Odometer Value ",
@@ -164,8 +168,7 @@
   }
  ],
  "is_submittable": 1,
- "links": [],
- "modified": "2020-01-28 12:43:34.419647",
+ "modified": "2020-03-18 16:45:45.060761",
  "modified_by": "Administrator",
  "module": "HR",
  "name": "Vehicle Log",
diff --git a/erpnext/hr/doctype/vehicle_log/vehicle_log.py b/erpnext/hr/doctype/vehicle_log/vehicle_log.py
index 12cc1dd..8affab2 100644
--- a/erpnext/hr/doctype/vehicle_log/vehicle_log.py
+++ b/erpnext/hr/doctype/vehicle_log/vehicle_log.py
@@ -12,18 +12,7 @@
 class VehicleLog(Document):
 	def validate(self):
 		if flt(self.odometer) < flt(self.last_odometer):
-			frappe.throw(_("Current Odometer reading entered should be greater than initial Vehicle Odometer {0}").format(self.last_odometer))
-		for service_detail in self.service_detail:
-			if (service_detail.service_item or service_detail.type or service_detail.frequency or service_detail.expense_amount):
-					if not (service_detail.service_item and service_detail.type and service_detail.frequency and service_detail.expense_amount):
-							frappe.throw(_("Service Item,Type,frequency and expense amount are required"))
-
-	def before_insert(self):
-		model_details = get_make_model(self.license_plate)
-		self.make = model_details[0]
-		self.model = model_details[1]
-		self.last_odometer = model_details[2]
-		self.employee = model_details[3]
+			frappe.throw(_("Current Odometer Value should be greater than Last Odometer Value {0}").format(self.last_odometer))
 
 	def on_submit(self):
 		frappe.db.set_value("Vehicle", self.license_plate, "last_odometer", self.odometer)
@@ -35,34 +24,25 @@
 			frappe.db.set_value("Vehicle", self.license_plate, "last_odometer", updated_odometer_value)
 
 @frappe.whitelist()
-def get_make_model(license_plate):
-	vehicle=frappe.get_doc("Vehicle",license_plate)
-	return (vehicle.make, vehicle.model, vehicle.last_odometer, vehicle.employee)
-
-@frappe.whitelist()
 def make_expense_claim(docname):
-	def check_exp_claim_exists():
-		exp_claim = frappe.db.sql("""select name from `tabExpense Claim` where vehicle_log=%s""",vehicle_log.name)
-		return exp_claim[0][0] if exp_claim else ""
-	def calc_service_exp():
-		total_exp_amt=0
-		exp_claim = check_exp_claim_exists()
-		if exp_claim:
-			frappe.throw(_("Expense Claim {0} already exists for the Vehicle Log").format(exp_claim))
-		for serdetail in vehicle_log.service_detail:
-			total_exp_amt = total_exp_amt + serdetail.expense_amount
-		return total_exp_amt
+	expense_claim = frappe.db.exists("Expense Claim", {"vehicle_log": docname})
+	if expense_claim:
+		frappe.throw(_("Expense Claim {0} already exists for the Vehicle Log").format(expense_claim))
 
 	vehicle_log = frappe.get_doc("Vehicle Log", docname)
+	service_expense = sum([flt(d.expense_amount) for d in vehicle_log.service_detail])
+
+	claim_amount = service_expense + flt(vehicle_log.price)
+	if not claim_amount:
+		frappe.throw(_("No additional expenses has been added"))
+
 	exp_claim = frappe.new_doc("Expense Claim")
-	exp_claim.employee=vehicle_log.employee
-	exp_claim.vehicle_log=vehicle_log.name
-	exp_claim.remark=_("Expense Claim for Vehicle Log {0}").format(vehicle_log.name)
-	fuel_price=vehicle_log.price
-	total_claim_amt=calc_service_exp() + fuel_price
-	exp_claim.append("expenses",{
-		"expense_date":vehicle_log.date,
-		"description":_("Vehicle Expenses"),
-		"amount":total_claim_amt
+	exp_claim.employee = vehicle_log.employee
+	exp_claim.vehicle_log = vehicle_log.name
+	exp_claim.remark = _("Expense Claim for Vehicle Log {0}").format(vehicle_log.name)
+	exp_claim.append("expenses", {
+		"expense_date": vehicle_log.date,
+		"description": _("Vehicle Expenses"),
+		"amount": claim_amount
 	})
 	return exp_claim.as_dict()
diff --git a/erpnext/hr/doctype/vehicle_service/vehicle_service.json b/erpnext/hr/doctype/vehicle_service/vehicle_service.json
index 7d9d0df..e0bce2b 100644
--- a/erpnext/hr/doctype/vehicle_service/vehicle_service.json
+++ b/erpnext/hr/doctype/vehicle_service/vehicle_service.json
@@ -1,153 +1,57 @@
 {
- "allow_copy": 0, 
- "allow_import": 0, 
- "allow_rename": 0, 
- "beta": 0, 
- "creation": "2016-09-03 19:20:14.561962", 
- "custom": 0, 
- "docstatus": 0, 
- "doctype": "DocType", 
- "document_type": "Document", 
- "editable_grid": 1, 
+ "creation": "2016-09-03 19:20:14.561962",
+ "doctype": "DocType",
+ "document_type": "Document",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "field_order": [
+  "service_item",
+  "type",
+  "frequency",
+  "expense_amount"
+ ],
  "fields": [
   {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "service_item", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Service Item", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nBrake Oil\nBrake Pad\nClutch Plate\nEngine Oil\nOil Change\nWheels", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "service_item",
+   "fieldtype": "Select",
+   "in_list_view": 1,
+   "label": "Service Item",
+   "options": "\nBrake Oil\nBrake Pad\nClutch Plate\nEngine Oil\nOil Change\nWheels",
+   "reqd": 1
+  },
   {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "type", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Type", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nInspection\nService\nChange", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "type",
+   "fieldtype": "Select",
+   "in_list_view": 1,
+   "label": "Type",
+   "options": "\nInspection\nService\nChange",
+   "reqd": 1
+  },
   {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "frequency", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Frequency", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nMileage\nMonthly\nQuarterly\nHalf Yearly\nYearly", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "frequency",
+   "fieldtype": "Select",
+   "in_list_view": 1,
+   "label": "Frequency",
+   "options": "\nMileage\nMonthly\nQuarterly\nHalf Yearly\nYearly",
+   "reqd": 1
+  },
   {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "expense_amount", 
-   "fieldtype": "Currency", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Expense", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
+   "fieldname": "expense_amount",
+   "fieldtype": "Currency",
+   "in_list_view": 1,
+   "label": "Expense",
+   "reqd": 1
   }
- ], 
- "hide_heading": 0, 
- "hide_toolbar": 0, 
- "idx": 0, 
- "image_view": 0, 
- "in_create": 0, 
-
- "is_submittable": 0, 
- "issingle": 0, 
- "istable": 1, 
- "max_attachments": 0, 
- "modified": "2017-01-09 11:10:29.476907", 
- "modified_by": "Administrator", 
- "module": "HR", 
- "name": "Vehicle Service", 
- "name_case": "", 
- "owner": "Administrator", 
- "permissions": [], 
- "quick_entry": 1, 
- "read_only": 0, 
- "read_only_onload": 0, 
- "sort_field": "modified", 
- "sort_order": "DESC", 
- "track_changes": 1, 
- "track_seen": 0
+ ],
+ "istable": 1,
+ "modified": "2020-03-18 16:49:46.645004",
+ "modified_by": "Administrator",
+ "module": "HR",
+ "name": "Vehicle Service",
+ "owner": "Administrator",
+ "permissions": [],
+ "quick_entry": 1,
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "track_changes": 1
 }
\ No newline at end of file