Merge branch 'develop' into cancel_frappe_1
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index 643de7d..c5c5483 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -167,9 +167,16 @@
 	make_comment_dialog_and_block_invoice: function(){
 		const me = this;
 
-		const title = __('Add Comment');
+		const title = __('Block Invoice');
 		const fields = [
 			{
+				fieldname: 'release_date',
+				read_only: 0,
+				fieldtype:'Date',
+				label: __('Release Date'),
+				default: me.frm.doc.release_date
+			},
+			{
 				fieldname: 'hold_comment',
 				read_only: 0,
 				fieldtype:'Small Text',
@@ -187,7 +194,11 @@
 			const dialog_data = me.dialog.get_values();
 			frappe.call({
 				'method': 'erpnext.accounts.doctype.purchase_invoice.purchase_invoice.block_invoice',
-				'args': {'name': me.frm.doc.name, 'hold_comment': dialog_data.hold_comment},
+				'args': {
+					'name': me.frm.doc.name,
+					'hold_comment': dialog_data.hold_comment,
+					'release_date': dialog_data.release_date
+				},
 				'callback': (r) => me.frm.reload_doc()
 			});
 			me.dialog.hide();
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 917acba..1a14a2a 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -927,9 +927,10 @@
 	def on_recurring(self, reference_doc, auto_repeat_doc):
 		self.due_date = None
 
-	def block_invoice(self, hold_comment=None):
+	def block_invoice(self, hold_comment=None, release_date=None):
 		self.db_set('on_hold', 1)
 		self.db_set('hold_comment', cstr(hold_comment))
+		self.db_set('release_date', release_date)
 
 	def unblock_invoice(self):
 		self.db_set('on_hold', 0)
@@ -1013,10 +1014,10 @@
 
 
 @frappe.whitelist()
-def block_invoice(name, hold_comment):
+def block_invoice(name, hold_comment, release_date):
 	if frappe.db.exists('Purchase Invoice', name):
 		pi = frappe.get_doc('Purchase Invoice', name)
-		pi.block_invoice(hold_comment)
+		pi.block_invoice(hold_comment, release_date)
 
 @frappe.whitelist()
 def make_inter_company_sales_invoice(source_name, target_doc=None):
diff --git a/erpnext/assets/doctype/asset/asset.js b/erpnext/assets/doctype/asset/asset.js
index f6a7fa2..a53ff88 100644
--- a/erpnext/assets/doctype/asset/asset.js
+++ b/erpnext/assets/doctype/asset/asset.js
@@ -338,25 +338,12 @@
 		})
 	},
 
-	purchase_receipt: function(frm) {
+	purchase_receipt: (frm) => {
 		frm.trigger('toggle_reference_doc');
-
 		if (frm.doc.purchase_receipt) {
 			if (frm.doc.item_code) {
 				frappe.db.get_doc('Purchase Receipt', frm.doc.purchase_receipt).then(pr_doc => {
-					frm.set_value('company', pr_doc.company);
-					frm.set_value('purchase_date', pr_doc.posting_date);
-					const item = pr_doc.items.find(item => item.item_code === frm.doc.item_code);
-					if (!item) {
-						frm.set_value('purchase_receipt', '');
-						frappe.msgprint({
-							title: __('Invalid Purchase Receipt'),
-							message: __("The selected Purchase Receipt doesn't contains selected Asset Item."),
-							indicator: 'red'
-						});
-					}
-					frm.set_value('gross_purchase_amount', item.base_net_rate);
-					frm.set_value('location', item.asset_location);
+					frm.events.set_values_from_purchase_doc(frm, 'Purchase Receipt', pr_doc)
 				});
 			} else {
 				frm.set_value('purchase_receipt', '');
@@ -368,24 +355,12 @@
 		}
 	},
 
-	purchase_invoice: function(frm) {
+	purchase_invoice: (frm) => {
 		frm.trigger('toggle_reference_doc');
 		if (frm.doc.purchase_invoice) {
 			if (frm.doc.item_code) {
 				frappe.db.get_doc('Purchase Invoice', frm.doc.purchase_invoice).then(pi_doc => {
-					frm.set_value('company', pi_doc.company);
-					frm.set_value('purchase_date', pi_doc.posting_date);
-					const item = pi_doc.items.find(item => item.item_code === frm.doc.item_code);
-					if (!item) {
-						frm.set_value('purchase_invoice', '');
-						frappe.msgprint({
-							title: __('Invalid Purchase Invoice'),
-							message: __("The selected Purchase Invoice doesn't contains selected Asset Item."),
-							indicator: 'red'
-						});
-					}
-					frm.set_value('gross_purchase_amount', item.base_net_rate);
-					frm.set_value('location', item.asset_location);
+					frm.events.set_values_from_purchase_doc(frm, 'Purchase Invoice', pi_doc)
 				});
 			} else {
 				frm.set_value('purchase_invoice', '');
@@ -397,6 +372,24 @@
 		}
 	},
 
+	set_values_from_purchase_doc: function(frm, doctype, purchase_doc) {
+		frm.set_value('company', purchase_doc.company);
+		frm.set_value('purchase_date', purchase_doc.posting_date);
+		const item = purchase_doc.items.find(item => item.item_code === frm.doc.item_code);
+		if (!item) {
+			doctype_field = frappe.scrub(doctype)
+			frm.set_value(doctype_field, '');
+			frappe.msgprint({
+				title: __(`Invalid ${doctype}`),
+				message: __(`The selected ${doctype} doesn't contains selected Asset Item.`),
+				indicator: 'red'
+			});
+		}
+		frm.set_value('gross_purchase_amount', item.base_net_rate + item.item_tax_amount);
+		frm.set_value('purchase_receipt_amount', item.base_net_rate + item.item_tax_amount);
+		frm.set_value('location', item.asset_location);
+	},
+
 	set_depreciation_rate: function(frm, row) {
 		if (row.total_number_of_depreciations && row.frequency_of_depreciation
 			&& row.expected_value_after_useful_life) {
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index cea4662..1989f4d 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -645,7 +645,6 @@
 erpnext.patches.v12_0.replace_accounting_with_accounts_in_home_settings
 erpnext.patches.v12_0.set_payment_entry_status
 erpnext.patches.v12_0.update_owner_fields_in_acc_dimension_custom_fields
-erpnext.patches.v12_0.set_default_for_add_taxes_from_item_tax_template
 erpnext.patches.v12_0.add_export_type_field_in_party_master
 erpnext.patches.v12_0.remove_denied_leaves_from_leave_ledger
 erpnext.patches.v12_0.update_price_or_product_discount
diff --git a/erpnext/patches/v12_0/set_default_for_add_taxes_from_item_tax_template.py b/erpnext/patches/v12_0/set_default_for_add_taxes_from_item_tax_template.py
deleted file mode 100644
index 06ee798..0000000
--- a/erpnext/patches/v12_0/set_default_for_add_taxes_from_item_tax_template.py
+++ /dev/null
@@ -1,5 +0,0 @@
-import frappe
-
-def execute():
-	frappe.db.set_value("Accounts Settings", None, "add_taxes_from_item_tax_template", 1)
-	frappe.db.set_default("add_taxes_from_item_tax_template", 1)
\ No newline at end of file
diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.json b/erpnext/selling/doctype/sales_order_item/sales_order_item.json
index 4c8973e..70e534a 100644
--- a/erpnext/selling/doctype/sales_order_item/sales_order_item.json
+++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.json
@@ -1,4 +1,5 @@
 {
+ "actions": [],
  "autoname": "hash",
  "creation": "2013-03-07 11:42:58",
  "doctype": "DocType",
@@ -151,6 +152,7 @@
    "width": "300px"
   },
   {
+   "allow_on_submit": 1,
    "columns": 2,
    "depends_on": "eval: !parent.skip_delivery_note",
    "fieldname": "delivery_date",
@@ -767,7 +769,8 @@
  ],
  "idx": 1,
  "istable": 1,
- "modified": "2019-12-12 18:06:26.238169",
+ "links": [],
+ "modified": "2020-01-13 12:29:03.103797",
  "modified_by": "Administrator",
  "module": "Selling",
  "name": "Sales Order Item",
diff --git a/erpnext/setup/doctype/authorization_control/authorization_control.py b/erpnext/setup/doctype/authorization_control/authorization_control.py
index 0c52b83..fec5c7c 100644
--- a/erpnext/setup/doctype/authorization_control/authorization_control.py
+++ b/erpnext/setup/doctype/authorization_control/authorization_control.py
@@ -76,7 +76,7 @@
 		add_cond = ''
 		auth_value = av_dis
 
-		if val == 1: add_cond += " and system_user = '"+ frappe.db.escape(session['user'])+"'"
+		if val == 1: add_cond += " and system_user = {}".format(frappe.db.escape(session['user']))
 		elif val == 2: add_cond += " and system_role IN %s" % ("('"+"','".join(frappe.get_roles())+"')")
 		else: add_cond += " and ifnull(system_user,'') = '' and ifnull(system_role,'') = ''"
 
@@ -85,7 +85,7 @@
 			if doc_obj:
 				if doc_obj.doctype == 'Sales Invoice': customer = doc_obj.customer
 				else: customer = doc_obj.customer_name
-				add_cond = " and master_name = '"+ frappe.db.escape(customer) +"'"
+				add_cond = " and master_name = {}".format(frappe.db.escape(customer))
 		if based_on == 'Itemwise Discount':
 			if doc_obj:
 				for t in doc_obj.get("items"):
diff --git a/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py b/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py
index eef121e..94ec314 100644
--- a/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py
+++ b/erpnext/stock/report/stock_and_account_value_comparison/stock_and_account_value_comparison.py
@@ -43,7 +43,7 @@
 def get_stock_ledger_data(report_filters, filters):
 	if report_filters.account:
 		warehouses = get_warehouses_based_on_account(report_filters.account,
-			report_filters.warehouse)
+			report_filters.company)
 
 		filters["warehouse"] = ("in", warehouses)