Merge branch 'hotfix'
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index e6c50b5..d871cd5 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -5,7 +5,7 @@
 from erpnext.hooks import regional_overrides
 from frappe.utils import getdate
 
-__version__ = '10.0.4'
+__version__ = '10.0.5'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.py b/erpnext/accounts/doctype/pos_profile/pos_profile.py
index 5710bd4..846d79d 100644
--- a/erpnext/accounts/doctype/pos_profile/pos_profile.py
+++ b/erpnext/accounts/doctype/pos_profile/pos_profile.py
@@ -63,7 +63,11 @@
 
 			if len(default_mode_of_payment) > 1:
 				frappe.throw(_("Multiple default mode of payment is not allowed"))
+
 	def validate_customer_territory_group(self):
+		if not frappe.db.get_single_value('POS Settings', 'use_pos_in_offline_mode'):
+			return
+
 		if not self.territory:
 			frappe.throw(_("Territory is Required in POS Profile"), title="Mandatory Field")
 
@@ -103,7 +107,7 @@
 	if pos_profile.get('item_groups'):
 		# Get items based on the item groups defined in the POS profile
 		for data in pos_profile.get('item_groups'):
-			item_groups.extend(["'%s'"%d.name for d in get_child_nodes('Item Group', data.item_group)])
+			item_groups.extend(["'%s'" % frappe.db.escape(d.name) for d in get_child_nodes('Item Group', data.item_group)])
 
 	return list(set(item_groups))
 
diff --git a/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py b/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py
index 3fcc1d3..93c0308 100644
--- a/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py
+++ b/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py
@@ -66,12 +66,12 @@
 	invoice_list = get_invoices(filters)
 	invoice_list_names = ",".join(['"' + invoice['name'] + '"' for invoice in invoice_list])
 	if invoice_list:
-		inv_mop = frappe.db.sql("""select a.owner,a.posting_date,b.mode_of_payment
+		inv_mop = frappe.db.sql("""select a.owner,a.posting_date, ifnull(b.mode_of_payment, '')
 			from `tabSales Invoice` a, `tabSales Invoice Payment` b
 			where a.name = b.parent
 			and a.name in ({invoice_list_names})
 			union
-			select a.owner,a.posting_date,b.mode_of_payment
+			select a.owner,a.posting_date, ifnull(b.mode_of_payment, '')
 			from `tabSales Invoice` a, `tabPayment Entry` b,`tabPayment Entry Reference` c
 			where a.name = c.reference_name 
 			and b.name = c.parent
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 8cf1f51..e5809fe 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -252,6 +252,9 @@
 	if not ac.parent_account:
 		ac.parent_account = args.get("parent")
 
+	if ac.is_root:
+		ac.parent_account=''
+
 	ac.old_parent = ""
 	ac.freeze_account = "No"
 	if cint(ac.get("is_root")):
diff --git a/erpnext/agriculture/doctype/crop/crop.js b/erpnext/agriculture/doctype/crop/crop.js
index 3f8a7fc..afd84fd 100644
--- a/erpnext/agriculture/doctype/crop/crop.js
+++ b/erpnext/agriculture/doctype/crop/crop.js
@@ -25,7 +25,7 @@
 	let material_list = ['materials_required', 'produce', 'byproducts'];
 	material_list.forEach((material) => {
 		frm.doc[material].forEach((item, index) => {
-			if (item.name == cdn){
+			if (item.name == cdn && item.item_code){
 				frappe.call({
 					method:'erpnext.agriculture.doctype.crop.crop.get_item_details',
 					args: {
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index e450f0b..f00f6cc 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -431,7 +431,7 @@
 					d.schedule_date = self.schedule_date
 
 				if d.schedule_date and getdate(d.schedule_date) < getdate(self.transaction_date):
-					frappe.throw(_("Expected Date cannot be before Transaction Date"))
+					frappe.throw(_("Row #{0}: Reqd by Date cannot be before Transaction Date").format(d.idx))
 		else:
-			frappe.throw(_("Please enter Schedule Date"))
+			frappe.throw(_("Please enter Reqd by Date"))
 
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index 1e723b1..a06645a 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -591,7 +591,7 @@
 		frappe.throw(_("BOM {0} does not belong to Item {1}").format(bom_no, item))
 
 @frappe.whitelist()
-def get_children(doctype, parent=None, is_tree=False):
+def get_children(doctype, parent=None, is_root=False, **filters):
 	if not parent:
 		frappe.msgprint(_('Please select a BOM'))
 		return
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 1814061..483736e 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -521,6 +521,7 @@
 						if(r.message) {
 							me.frm.set_value("due_date", r.message);
 							frappe.ui.form.trigger(me.frm.doc.doctype, "currency");
+							me.recalculate_terms();
 						}
 					}
 				})
@@ -530,6 +531,29 @@
 		}
 	},
 
+	recalculate_terms: function() {
+		const doc = this.frm.doc;
+
+		if (doc.payment_terms_template) {
+			this.payment_terms_template();
+		} else if (doc.payment_schedule) {
+			const me = this;
+
+			doc.payment_schedule.forEach(
+				function(term) {
+					if (term.payment_term) {
+						me.payment_term(doc, term.doctype, term.name);
+					} else {
+						frappe.model.set_value(
+							term.doctype, term.name, 'due_date',
+							doc.posting_date || doc.transaction_date
+						);
+					}
+				}
+			);
+		}
+	},
+
 	get_company_currency: function() {
 		return erpnext.get_currency(this.frm.doc.company);
 	},
diff --git a/erpnext/regional/united_arab_emirates/utils.py b/erpnext/regional/united_arab_emirates/utils.py
index 3ba2030..61ffadb 100644
--- a/erpnext/regional/united_arab_emirates/utils.py
+++ b/erpnext/regional/united_arab_emirates/utils.py
@@ -7,7 +7,9 @@
 	itemised_tax = get_itemised_tax(doc.taxes)
 
 	for row in doc.items:
-		tax_rate = sum([tax.get('tax_rate', 0) for d, tax in itemised_tax.get(row.item_code).items()])
+		tax_rate = 0.0
+		if 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"))
 		row.tax_amount = flt((row.net_amount * tax_rate) / 100, row.precision("net_amount"))