Merge remote-tracking branch 'upstream/develop' into add-age-range-in-stock-ageing
Merge remote-tracking branch 'upstream/develop' into add-age-range-in-stock-ageing
diff --git a/erpnext/accounts/doctype/item_tax_template/test_records.json b/erpnext/accounts/doctype/item_tax_template/test_records.json
index db540e8..4d9537d 100644
--- a/erpnext/accounts/doctype/item_tax_template/test_records.json
+++ b/erpnext/accounts/doctype/item_tax_template/test_records.json
@@ -2,6 +2,7 @@
  {
   "doctype": "Item Tax Template",
   "title": "_Test Account Excise Duty @ 10",
+  "company": "_Test Company",
   "taxes": [
    {
     "doctype": "Item Tax Template Detail",
@@ -14,6 +15,7 @@
  {
   "doctype": "Item Tax Template",
   "title": "_Test Account Excise Duty @ 12",
+  "company": "_Test Company",
   "taxes": [
    {
     "doctype": "Item Tax Template Detail",
@@ -26,6 +28,7 @@
  {
   "doctype": "Item Tax Template",
   "title": "_Test Account Excise Duty @ 15",
+  "company": "_Test Company",
   "taxes": [
    {
     "doctype": "Item Tax Template Detail",
@@ -38,6 +41,7 @@
  {
   "doctype": "Item Tax Template",
   "title": "_Test Account Excise Duty @ 20",
+  "company": "_Test Company",
   "taxes": [
    {
     "doctype": "Item Tax Template Detail",
@@ -50,6 +54,7 @@
  {
   "doctype": "Item Tax Template",
   "title": "_Test Item Tax Template 1",
+  "company": "_Test Company",
   "taxes": [
    {
     "doctype": "Item Tax Template Detail",
diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py
index 53115f9..ad98383 100644
--- a/erpnext/accounts/doctype/pricing_rule/utils.py
+++ b/erpnext/accounts/doctype/pricing_rule/utils.py
@@ -319,7 +319,9 @@
 	filtered_rules = []
 	for field in field_set:
 		if args.get(field):
-			filtered_rules = filter(lambda x: x[field]==args[field], pricing_rules)
+			# filter function always returns a filter object even if empty
+			# list conversion is necessary to check for an empty result
+			filtered_rules = list(filter(lambda x: x.get(field)==args.get(field), pricing_rules))
 			if filtered_rules: break
 
 	return filtered_rules or pricing_rules
diff --git a/erpnext/accounts/report/accounts_payable/accounts_payable.js b/erpnext/accounts/report/accounts_payable/accounts_payable.js
index 2aa9618..6abd6e5 100644
--- a/erpnext/accounts/report/accounts_payable/accounts_payable.js
+++ b/erpnext/accounts/report/accounts_payable/accounts_payable.js
@@ -18,41 +18,6 @@
 			"default": frappe.datetime.get_today()
 		},
 		{
-			"fieldname":"ageing_based_on",
-			"label": __("Ageing Based On"),
-			"fieldtype": "Select",
-			"options": 'Posting Date\nDue Date\nSupplier Invoice Date',
-			"default": "Due Date"
-		},
-		{
-			"fieldname":"range1",
-			"label": __("Ageing Range 1"),
-			"fieldtype": "Int",
-			"default": "30",
-			"reqd": 1
-		},
-		{
-			"fieldname":"range2",
-			"label": __("Ageing Range 2"),
-			"fieldtype": "Int",
-			"default": "60",
-			"reqd": 1
-		},
-		{
-			"fieldname":"range3",
-			"label": __("Ageing Range 3"),
-			"fieldtype": "Int",
-			"default": "90",
-			"reqd": 1
-		},
-		{
-			"fieldname":"range4",
-			"label": __("Ageing Range 4"),
-			"fieldtype": "Int",
-			"default": "120",
-			"reqd": 1
-		},
-		{
 			"fieldname":"finance_book",
 			"label": __("Finance Book"),
 			"fieldtype": "Link",
@@ -89,6 +54,41 @@
 			}
 		},
 		{
+			"fieldname":"ageing_based_on",
+			"label": __("Ageing Based On"),
+			"fieldtype": "Select",
+			"options": 'Posting Date\nDue Date\nSupplier Invoice Date',
+			"default": "Due Date"
+		},
+		{
+			"fieldname":"range1",
+			"label": __("Ageing Range 1"),
+			"fieldtype": "Int",
+			"default": "30",
+			"reqd": 1
+		},
+		{
+			"fieldname":"range2",
+			"label": __("Ageing Range 2"),
+			"fieldtype": "Int",
+			"default": "60",
+			"reqd": 1
+		},
+		{
+			"fieldname":"range3",
+			"label": __("Ageing Range 3"),
+			"fieldtype": "Int",
+			"default": "90",
+			"reqd": 1
+		},
+		{
+			"fieldname":"range4",
+			"label": __("Ageing Range 4"),
+			"fieldtype": "Int",
+			"default": "120",
+			"reqd": 1
+		},
+		{
 			"fieldname":"payment_terms_template",
 			"label": __("Payment Terms Template"),
 			"fieldtype": "Link",
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js
index 8dc558a..c999eb9 100644
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js
@@ -18,41 +18,6 @@
 			"default": frappe.datetime.get_today()
 		},
 		{
-			"fieldname":"ageing_based_on",
-			"label": __("Ageing Based On"),
-			"fieldtype": "Select",
-			"options": 'Posting Date\nDue Date',
-			"default": "Due Date"
-		},
-		{
-			"fieldname":"range1",
-			"label": __("Ageing Range 1"),
-			"fieldtype": "Int",
-			"default": "30",
-			"reqd": 1
-		},
-		{
-			"fieldname":"range2",
-			"label": __("Ageing Range 2"),
-			"fieldtype": "Int",
-			"default": "60",
-			"reqd": 1
-		},
-		{
-			"fieldname":"range3",
-			"label": __("Ageing Range 3"),
-			"fieldtype": "Int",
-			"default": "90",
-			"reqd": 1
-		},
-		{
-			"fieldname":"range4",
-			"label": __("Ageing Range 4"),
-			"fieldtype": "Int",
-			"default": "120",
-			"reqd": 1
-		},
-		{
 			"fieldname":"finance_book",
 			"label": __("Finance Book"),
 			"fieldtype": "Link",
@@ -102,6 +67,41 @@
 			}
 		},
 		{
+			"fieldname":"ageing_based_on",
+			"label": __("Ageing Based On"),
+			"fieldtype": "Select",
+			"options": 'Posting Date\nDue Date',
+			"default": "Due Date"
+		},
+		{
+			"fieldname":"range1",
+			"label": __("Ageing Range 1"),
+			"fieldtype": "Int",
+			"default": "30",
+			"reqd": 1
+		},
+		{
+			"fieldname":"range2",
+			"label": __("Ageing Range 2"),
+			"fieldtype": "Int",
+			"default": "60",
+			"reqd": 1
+		},
+		{
+			"fieldname":"range3",
+			"label": __("Ageing Range 3"),
+			"fieldtype": "Int",
+			"default": "90",
+			"reqd": 1
+		},
+		{
+			"fieldname":"range4",
+			"label": __("Ageing Range 4"),
+			"fieldtype": "Int",
+			"default": "120",
+			"reqd": 1
+		},
+		{
 			"fieldname":"customer_group",
 			"label": __("Customer Group"),
 			"fieldtype": "Link",
@@ -114,12 +114,6 @@
 			"options": "Payment Terms Template"
 		},
 		{
-			"fieldname":"territory",
-			"label": __("Territory"),
-			"fieldtype": "Link",
-			"options": "Territory"
-		},
-		{
 			"fieldname":"sales_partner",
 			"label": __("Sales Partner"),
 			"fieldtype": "Link",
@@ -132,6 +126,12 @@
 			"options": "Sales Person"
 		},
 		{
+			"fieldname":"territory",
+			"label": __("Territory"),
+			"fieldtype": "Link",
+			"options": "Territory"
+		},
+		{
 			"fieldname": "group_by_party",
 			"label": __("Group By Customer"),
 			"fieldtype": "Check"
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index 533685d..ee1d54a 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -405,12 +405,12 @@
 				FROM `tabDistributed Cost Center`
 				WHERE cost_center IN %(cost_center)s
 				AND parent NOT IN %(cost_center)s
-				AND is_cancelled = 0
 				GROUP BY parent
 			) as DCC_allocation
 			WHERE company=%(company)s
 			{additional_conditions}
 			AND posting_date <= %(to_date)s
+			AND is_cancelled = 0
 			AND cost_center = DCC_allocation.parent
 			""".format(additional_conditions=additional_conditions.replace("and cost_center in %(cost_center)s ", ''))
 
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index 4a8146a..84e3a31 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -123,14 +123,14 @@
 			}
 			if(doc.status != "Closed") {
 				if (doc.status != "On Hold") {
-					if(flt(doc.per_received, 2) < 100 && allow_receipt) {
+					if(flt(doc.per_received) < 100 && allow_receipt) {
 						cur_frm.add_custom_button(__('Receipt'), this.make_purchase_receipt, __('Create'));
 						if(doc.is_subcontracted==="Yes" && me.has_unsupplied_items()) {
 							cur_frm.add_custom_button(__('Material to Supplier'),
 								function() { me.make_stock_entry(); }, __("Transfer"));
 						}
 					}
-					if(flt(doc.per_billed, 2) < 100)
+					if(flt(doc.per_billed) < 100)
 						cur_frm.add_custom_button(__('Invoice'),
 							this.make_purchase_invoice, __('Create'));
 
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
index 97aa922..5cd8e6f 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.json
@@ -1,4 +1,5 @@
 {
+ "actions": "",
  "allow_import": 1,
  "autoname": "naming_series:",
  "creation": "2016-02-25 01:24:07.224790",
@@ -28,7 +29,6 @@
   "letter_head",
   "more_info",
   "status",
-  "fiscal_year",
   "column_break3",
   "amended_from"
  ],
@@ -219,17 +219,6 @@
    "search_index": 1
   },
   {
-   "fieldname": "fiscal_year",
-   "fieldtype": "Link",
-   "label": "Fiscal Year",
-   "oldfieldname": "fiscal_year",
-   "oldfieldtype": "Select",
-   "options": "Fiscal Year",
-   "print_hide": 1,
-   "reqd": 1,
-   "search_index": 1
-  },
-  {
    "fieldname": "column_break3",
    "fieldtype": "Column Break"
   },
@@ -245,7 +234,8 @@
  ],
  "icon": "fa fa-shopping-cart",
  "is_submittable": 1,
- "modified": "2019-09-24 15:08:32.750661",
+ "links": [],
+ "modified": "2020-06-25 14:37:21.140194",
  "modified_by": "Administrator",
  "module": "Buying",
  "name": "Request for Quotation",
diff --git a/erpnext/controllers/tests/test_mapper.py b/erpnext/controllers/tests/test_mapper.py
index 8839e00..66459fd 100644
--- a/erpnext/controllers/tests/test_mapper.py
+++ b/erpnext/controllers/tests/test_mapper.py
@@ -13,14 +13,12 @@
 		'''Test mapping of multiple source docs on a single target doc'''
 
 		make_test_records("Item")
-		items = frappe.get_all("Item", fields = ["name", "item_code"], filters = {'is_sales_item': 1, 'has_variants': 0, 'disabled': 0})
-		customers = frappe.get_all("Customer")
-		if items and customers:
-			# Make source docs (quotations) and a target doc (sales order)
-			customer = random.choice(customers).name
-			qtn1, item_list_1 = self.make_quotation(items, customer)
-			qtn2, item_list_2 = self.make_quotation(items, customer)
-			so, item_list_3 = self.make_sales_order()
+		items = ['_Test Item', '_Test Item 2', '_Test FG Item']
+
+		# Make source docs (quotations) and a target doc (sales order)
+		qtn1, item_list_1 = self.make_quotation(items, '_Test Customer')
+		qtn2, item_list_2 = self.make_quotation(items, '_Test Customer')
+		so, item_list_3 = self.make_sales_order()
 
 		# Map source docs to target with corresponding mapper method
 		method = "erpnext.selling.doctype.quotation.quotation.make_sales_order"
@@ -28,18 +26,12 @@
 
 		# Assert that all inserted items are present in updated sales order
 		src_items = item_list_1 + item_list_2 + item_list_3
-		self.assertEqual(set([d.item_code for d in src_items]),
+		self.assertEqual(set([d for d in src_items]),
 			set([d.item_code for d in updated_so.items]))
 
-	def get_random_items(self, items, limit):
-		'''Get a number of random items from a list of given items'''
-		random_items = []
-		for i in range(0, limit):
-			random_items.append(random.choice(items))
-		return random_items
 
-	def make_quotation(self, items, customer):
-		item_list = self.get_random_items(items, 3)
+	def make_quotation(self, item_list, customer):
+
 		qtn = frappe.get_doc({
 			"doctype": "Quotation",
 			"quotation_to": "Customer",
@@ -49,7 +41,7 @@
 			"valid_till" : add_months(nowdate(), 1)
 		})
 		for item in item_list:
-			qtn.append("items", {"qty": "2", "item_code": item.item_code})
+			qtn.append("items", {"qty": "2", "item_code": item})
 
 		qtn.submit()
 		return qtn, item_list
@@ -60,7 +52,7 @@
 			"base_rate": 100.0,
 			"description": "CPU",
 			"doctype": "Sales Order Item",
-			"item_code": "_Test Item Home Desktop 100",
+			"item_code": "_Test Item",
 			"item_name": "CPU",
 			"parentfield": "items",
 			"qty": 10.0,
@@ -72,4 +64,4 @@
 		})
 		so = frappe.get_doc(frappe.get_test_records('Sales Order')[0])
 		so.insert(ignore_permissions=True)
-		return so, [item]
+		return so, [item.item_code]
diff --git a/erpnext/controllers/tests/test_qty_based_taxes.py b/erpnext/controllers/tests/test_qty_based_taxes.py
index fd9936b..aaeac5d 100644
--- a/erpnext/controllers/tests/test_qty_based_taxes.py
+++ b/erpnext/controllers/tests/test_qty_based_taxes.py
@@ -30,6 +30,7 @@
         self.item_tax_template = frappe.get_doc({
             'doctype': 'Item Tax Template',
             'title': uuid4(),
+            'company': self.company.name,
             'taxes': [
                 {
                     'tax_type': self.account.name,
diff --git a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py
index 56401a3..262fc46 100644
--- a/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py
+++ b/erpnext/healthcare/doctype/patient_encounter/patient_encounter.py
@@ -73,7 +73,7 @@
 		insert_encounter_to_medical_record(encounter)
 
 def delete_medical_record(encounter):
-	frappe.db.delete_doc_if_exists('Patient Medical Record', 'reference_name', encounter.name)
+	frappe.delete_doc_if_exists('Patient Medical Record', 'reference_name', encounter.name)
 
 def set_subject_field(encounter):
 	subject = frappe.bold(_('Healthcare Practitioner: ')) + encounter.practitioner + '<br>'
diff --git a/erpnext/payroll/doctype/employee_incentive/employee_incentive.py b/erpnext/payroll/doctype/employee_incentive/employee_incentive.py
index 44763fc..84a97f6 100644
--- a/erpnext/payroll/doctype/employee_incentive/employee_incentive.py
+++ b/erpnext/payroll/doctype/employee_incentive/employee_incentive.py
@@ -13,6 +13,7 @@
 		additional_salary = frappe.new_doc('Additional Salary')
 		additional_salary.employee = self.employee
 		additional_salary.salary_component = self.salary_component
+		additional_salary.overwrite_salary_structure_amount = 0
 		additional_salary.amount = self.incentive_amount
 		additional_salary.payroll_date = self.payroll_date
 		additional_salary.company = company
diff --git a/erpnext/payroll/doctype/retention_bonus/retention_bonus.py b/erpnext/payroll/doctype/retention_bonus/retention_bonus.py
index ed0d36c..b8e56ae 100644
--- a/erpnext/payroll/doctype/retention_bonus/retention_bonus.py
+++ b/erpnext/payroll/doctype/retention_bonus/retention_bonus.py
@@ -26,6 +26,7 @@
 			additional_salary.amount = self.bonus_amount
 			additional_salary.payroll_date = self.bonus_payment_date
 			additional_salary.company = company
+			additional_salary.overwrite_salary_structure_amount = 0
 			additional_salary.ref_doctype = self.doctype
 			additional_salary.ref_docname = self.name
 			additional_salary.submit()
@@ -53,7 +54,7 @@
 				'employee': self.employee,
 				'salary_component': self.salary_component,
 				'payroll_date': self.bonus_payment_date,
-				'company': company,
+				'company': self.company,
 				'docstatus': 1,
 				'ref_doctype': self.doctype,
 				'ref_docname': self.name
diff --git a/erpnext/projects/doctype/task/task.js b/erpnext/projects/doctype/task/task.js
index 5719276..8c6a9cf 100644
--- a/erpnext/projects/doctype/task/task.js
+++ b/erpnext/projects/doctype/task/task.js
@@ -3,55 +3,42 @@
 
 frappe.provide("erpnext.projects");
 
-cur_frm.add_fetch("project", "company", "company");
-
 frappe.ui.form.on("Task", {
-	onload: function(frm) {
-		frm.set_query("task", "depends_on", function() {
-			var filters = {
+	setup: function (frm) {
+		frm.set_query("project", function () {
+			return {
+				query: "erpnext.projects.doctype.task.task.get_project"
+			}
+		});
+
+		frm.make_methods = {
+			'Timesheet': () => frappe.model.open_mapped_doc({
+				method: 'erpnext.projects.doctype.task.task.make_timesheet',
+				frm: frm
+			})
+		}
+	},
+
+	onload: function (frm) {
+		frm.set_query("task", "depends_on", function () {
+			let filters = {
 				name: ["!=", frm.doc.name]
 			};
-			if(frm.doc.project) filters["project"] = frm.doc.project;
+			if (frm.doc.project) filters["project"] = frm.doc.project;
 			return {
 				filters: filters
 			};
 		})
-	},
 
-	refresh: function(frm) {
-		frm.fields_dict['parent_task'].get_query = function () {
+		frm.set_query("parent_task", function () {
+			let filters = {
+				"is_group": 1
+			};
+			if (frm.doc.project) filters["project"] = frm.doc.project;
 			return {
-				filters: {
-					"is_group": 1,
-				}
+				filters: filters
 			}
-		}
-
-		if (!frm.doc.is_group) {
-			if (!frm.is_new()) {
-				if (frappe.model.can_read("Timesheet")) {
-					frm.add_custom_button(__("Timesheet"), () => {
-						frappe.route_options = { "project": frm.doc.project, "task": frm.doc.name }
-						frappe.set_route("List", "Timesheet");
-					}, __("View"), true);
-				}
-
-				if (frappe.model.can_read("Expense Claim")) {
-					frm.add_custom_button(__("Expense Claims"), () => {
-						frappe.route_options = { "project": frm.doc.project, "task": frm.doc.name };
-						frappe.set_route("List", "Expense Claim");
-					}, __("View"), true);
-				}
-			}
-		}
-	},
-
-	setup: function(frm) {
-		frm.fields_dict.project.get_query = function() {
-			return {
-				query: "erpnext.projects.doctype.task.task.get_project"
-			}
-		};
+		});
 	},
 
 	is_group: function (frm) {
@@ -69,12 +56,8 @@
 		})
 	},
 
-	validate: function(frm) {
+	validate: function (frm) {
 		frm.doc.project && frappe.model.remove_from_locals("Project",
 			frm.doc.project);
-	},
-
+	}
 });
-
-cur_frm.add_fetch('task', 'subject', 'subject');
-cur_frm.add_fetch('task', 'project', 'project');
diff --git a/erpnext/projects/doctype/task/task.json b/erpnext/projects/doctype/task/task.json
index 4db1f19..27f1a71 100644
--- a/erpnext/projects/doctype/task/task.json
+++ b/erpnext/projects/doctype/task/task.json
@@ -325,6 +325,7 @@
    "options": "Department"
   },
   {
+   "fetch_from": "project.company",
    "fieldname": "company",
    "fieldtype": "Link",
    "label": "Company",
diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py
index 845cdba..3b75cf4 100755
--- a/erpnext/projects/doctype/task/task.py
+++ b/erpnext/projects/doctype/task/task.py
@@ -7,10 +7,11 @@
 
 import frappe
 from frappe import _, throw
+from frappe.desk.form.assign_to import clear, close_all_assignments
+from frappe.model.mapper import get_mapped_doc
 from frappe.utils import add_days, cstr, date_diff, get_link_to_form, getdate, today
 from frappe.utils.nestedset import NestedSet
-from frappe.desk.form.assign_to import close_all_assignments, clear
-from frappe.utils import date_diff
+
 
 class CircularReferenceError(frappe.ValidationError): pass
 class EndDateCannotBeGreaterThanProjectEndDateError(frappe.ValidationError): pass
@@ -220,6 +221,26 @@
 				continue
 		frappe.get_doc("Task", task.name).update_status()
 
+
+@frappe.whitelist()
+def make_timesheet(source_name, target_doc=None, ignore_permissions=False):
+	def set_missing_values(source, target):
+		target.append("time_logs", {
+			"hours": source.actual_time,
+			"completed": source.status == "Completed",
+			"project": source.project,
+			"task": source.name
+		})
+
+	doclist = get_mapped_doc("Task", source_name, {
+			"Task": {
+				"doctype": "Timesheet"
+			}
+		}, target_doc, postprocess=set_missing_values, ignore_permissions=ignore_permissions)
+
+	return doclist
+
+
 @frappe.whitelist()
 def get_children(doctype, parent, task=None, project=None, is_root=False):
 
diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py
index 05ffa87..961b8c6 100644
--- a/erpnext/regional/india/utils.py
+++ b/erpnext/regional/india/utils.py
@@ -458,19 +458,23 @@
 
 @frappe.whitelist()
 def download_ewb_json():
-	data = frappe._dict(frappe.local.form_dict)
-
-	frappe.local.response.filecontent = json.dumps(data['data'], indent=4, sort_keys=True)
+	data = json.loads(frappe.local.form_dict.data)
+	frappe.local.response.filecontent = json.dumps(data, indent=4, sort_keys=True)
 	frappe.local.response.type = 'download'
 
-	billList = json.loads(data['data'])['billLists']
+	filename_prefix = 'Bulk'
+	docname = frappe.local.form_dict.docname
+	if docname:
+		if docname.startswith('['):
+			docname = json.loads(docname)
+			if len(docname) == 1:
+				docname = docname[0]
 
-	if len(billList) > 1:
-		doc_name = 'Bulk'
-	else:
-		doc_name = data['docname']
+		if not isinstance(docname, list):
+			# removes characters not allowed in a filename (https://stackoverflow.com/a/38766141/4767738)
+			filename_prefix = re.sub('[^\w_.)( -]', '', docname)
 
-	frappe.local.response.filename = '{0}_e-WayBill_Data_{1}.json'.format(doc_name, frappe.utils.random_string(5))
+	frappe.local.response.filename = '{0}_e-WayBill_Data_{1}.json'.format(filename_prefix, frappe.utils.random_string(5))
 
 @frappe.whitelist()
 def get_gstins_for_company(company):
diff --git a/erpnext/regional/report/datev/datev.js b/erpnext/regional/report/datev/datev.js
index d8638ab..55f12cf 100644
--- a/erpnext/regional/report/datev/datev.js
+++ b/erpnext/regional/report/datev/datev.js
@@ -30,7 +30,7 @@
 		}
 	],
 	onload: function(query_report) {
-		query_report.page.add_inner_button("Download DATEV Export", () => {
+		query_report.page.add_menu_item(__("Download DATEV File"), () => {
 			const filters = JSON.stringify(query_report.get_values());
 			window.open(`/api/method/erpnext.regional.report.datev.datev.download_datev_csv?filters=${filters}`);
 		});
diff --git a/erpnext/selling/doctype/sales_order/test_records.json b/erpnext/selling/doctype/sales_order/test_records.json
index 6cbd6c2..8a090e6 100644
--- a/erpnext/selling/doctype/sales_order/test_records.json
+++ b/erpnext/selling/doctype/sales_order/test_records.json
@@ -1,39 +1,39 @@
 [
  {
   "advance_paid": 0.0,
-  "company": "_Test Company", 
-  "conversion_rate": 1.0, 
-  "currency": "INR", 
-  "customer": "_Test Customer", 
-  "customer_group": "_Test Customer Group", 
-  "customer_name": "_Test Customer", 
-  "doctype": "Sales Order", 
-  "base_grand_total": 1000.0, 
-  "grand_total": 1000.0, 
-  "naming_series": "_T-Sales Order-", 
-  "order_type": "Sales", 
-  "plc_conversion_rate": 1.0, 
-  "price_list_currency": "INR", 
+  "company": "_Test Company",
+  "conversion_rate": 1.0,
+  "currency": "INR",
+  "customer": "_Test Customer",
+  "customer_group": "_Test Customer Group",
+  "customer_name": "_Test Customer",
+  "doctype": "Sales Order",
+  "base_grand_total": 1000.0,
+  "grand_total": 1000.0,
+  "naming_series": "_T-Sales Order-",
+  "order_type": "Sales",
+  "plc_conversion_rate": 1.0,
+  "price_list_currency": "INR",
   "items": [
    {
-    "base_amount": 1000.0, 
-    "base_rate": 100.0, 
-    "description": "CPU", 
-    "doctype": "Sales Order Item", 
-    "item_code": "_Test Item Home Desktop 100", 
-    "item_name": "CPU", 
-    "delivery_date": "2013-02-23", 
-    "parentfield": "items", 
-    "qty": 10.0, 
-    "rate": 100.0, 
+    "base_amount": 1000.0,
+    "base_rate": 100.0,
+    "description": "CPU",
+    "doctype": "Sales Order Item",
+    "item_code": "_Test Item",
+    "item_name": "_Test Item 1",
+    "delivery_date": "2013-02-23",
+    "parentfield": "items",
+    "qty": 10.0,
+    "rate": 100.0,
     "warehouse": "_Test Warehouse - _TC",
     "stock_uom": "_Test UOM",
 	"conversion_factor": 1.0,
 	"uom": "_Test UOM"
    }
-  ], 
-  "selling_price_list": "_Test Price List", 
-  "territory": "_Test Territory", 
+  ],
+  "selling_price_list": "_Test Price List",
+  "territory": "_Test Territory",
   "transaction_date": "2013-02-21"
  }
 ]
\ No newline at end of file
diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py
index 74ff0ec..aa9fbc0 100644
--- a/erpnext/setup/install.py
+++ b/erpnext/setup/install.py
@@ -29,12 +29,10 @@
 
 
 def check_setup_wizard_not_completed():
-	if frappe.db.get_default('desktop:home_page') == 'desktop':
-		print()
-		print("ERPNext can only be installed on a fresh site where the setup wizard is not completed")
-		print("You can reinstall this site (after saving your data) using: bench --site [sitename] reinstall")
-		print()
-		return False
+	if frappe.db.get_default('desktop:home_page') != 'setup-wizard':
+		message = """ERPNext can only be installed on a fresh site where the setup wizard is not completed. 
+You can reinstall this site (after saving your data) using: bench --site [sitename] reinstall"""
+		frappe.throw(message)
 
 
 def set_single_defaults():
@@ -105,4 +103,3 @@
 		"ref_doctype": "Company"
 	})
 	settings.save()
-
diff --git a/erpnext/stock/doctype/item/test_records.json b/erpnext/stock/doctype/item/test_records.json
index 6c1a559..9ca887c 100644
--- a/erpnext/stock/doctype/item/test_records.json
+++ b/erpnext/stock/doctype/item/test_records.json
@@ -92,8 +92,7 @@
    {
     "doctype": "Item Tax",
     "parentfield": "taxes",
-    "item_tax_template": "_Test Account Excise Duty @ 10",
-    "tax_category": ""
+    "item_tax_template": "_Test Account Excise Duty @ 10"
    }
   ],
   "stock_uom": "_Test UOM 1"
@@ -371,8 +370,7 @@
    {
     "doctype": "Item Tax",
     "parentfield": "taxes",
-    "item_tax_template": "_Test Account Excise Duty @ 10",
-    "tax_category": ""
+    "item_tax_template": "_Test Account Excise Duty @ 10"
    },
    {
     "doctype": "Item Tax",
@@ -451,14 +449,13 @@
    {
     "doctype": "Item Tax",
     "parentfield": "taxes",
-    "item_tax_template": "_Test Account Excise Duty @ 20",
-    "tax_category": ""
+    "item_tax_template": "_Test Account Excise Duty @ 20"
    },
    {
     "doctype": "Item Tax",
     "parentfield": "taxes",
-    "item_tax_template": "_Test Item Tax Template 1",
-    "tax_category": "_Test Tax Category 1"
+    "tax_category": "_Test Tax Category 1",
+    "item_tax_template": "_Test Item Tax Template 1"
    }
   ]
  }
diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py
index f3514c7..90f0f58 100644
--- a/erpnext/stock/doctype/serial_no/serial_no.py
+++ b/erpnext/stock/doctype/serial_no/serial_no.py
@@ -190,23 +190,6 @@
 		if sle_exists:
 			frappe.throw(_("Cannot delete Serial No {0}, as it is used in stock transactions").format(self.name))
 
-	def before_rename(self, old, new, merge=False):
-		if merge:
-			frappe.throw(_("Sorry, Serial Nos cannot be merged"))
-
-	def after_rename(self, old, new, merge=False):
-		"""rename serial_no text fields"""
-		for dt in frappe.db.sql("""select parent from tabDocField
-			where fieldname='serial_no' and fieldtype in ('Text', 'Small Text')"""):
-
-			for item in frappe.db.sql("""select name, serial_no from `tab%s`
-				where serial_no like %s""" % (dt[0], frappe.db.escape('%' + old + '%'))):
-
-				serial_nos = map(lambda i: new if i.upper()==old.upper() else i, item[1].split('\n'))
-				frappe.db.sql("""update `tab%s` set serial_no = %s
-					where name=%s""" % (dt[0], '%s', '%s'),
-					('\n'.join(list(serial_nos)), item[0]))
-
 	def update_serial_no_reference(self, serial_no=None):
 		last_sle = self.get_last_sle(serial_no)
 		self.set_purchase_details(last_sle.get("purchase_sle"))
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 1f30f5a..b1a1614 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -638,7 +638,7 @@
 	if args.get('transaction_date'):
 		conditions += """ and %(transaction_date)s between
 			ifnull(valid_from, '2000-01-01') and ifnull(valid_upto, '2500-12-31')"""
-		
+
 	if args.get('posting_date'):
 		conditions += """ and %(posting_date)s between
 			ifnull(valid_from, '2000-01-01') and ifnull(valid_upto, '2500-12-31')"""
diff --git a/erpnext/stock/report/supplier_wise_sales_analytics/supplier_wise_sales_analytics.py b/erpnext/stock/report/supplier_wise_sales_analytics/supplier_wise_sales_analytics.py
index 6a86889..5873a7a 100644
--- a/erpnext/stock/report/supplier_wise_sales_analytics/supplier_wise_sales_analytics.py
+++ b/erpnext/stock/report/supplier_wise_sales_analytics/supplier_wise_sales_analytics.py
@@ -21,7 +21,7 @@
 			for cd in consumed_details.get(item_code):
 
 				if (cd.voucher_no not in material_transfer_vouchers):
-					if cd.voucher_type=="Delivery Note":
+					if cd.voucher_type in ["Delivery Note", "Sales Invoice"]:
 						delivered_qty += abs(flt(cd.actual_qty))
 						delivered_amount += abs(flt(cd.stock_value_difference))
 					elif cd.voucher_type!="Delivery Note":
diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py
index 5bf85d1..c8e3330 100644
--- a/erpnext/utilities/transaction_base.py
+++ b/erpnext/utilities/transaction_base.py
@@ -121,7 +121,6 @@
 
 	def validate_rate_with_reference_doc(self, ref_details):
 		buying_doctypes = ["Purchase Order", "Purchase Invoice", "Purchase Receipt"]
-		selling_doctypes = ["Sales Invoice", "Delivery Note"]
 
 		if self.doctype in buying_doctypes:
 			to_disable = "Maintain same rate throughout Purchase cycle"
diff --git a/requirements.txt b/requirements.txt
index cfd0ab8..912d61f 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,7 +2,7 @@
 frappe
 gocardless-pro==1.11.0
 googlemaps==3.1.1
-pandas==0.24.2
+pandas==1.0.5
 plaid-python==3.4.0
 pycountry==19.8.18
 PyGithub==1.44.1