Merge pull request #12099 from pratu16x7/user-progress-items-fix

Create item price only if item created
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js
index e25abfb..c92a728 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.js
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js
@@ -61,6 +61,16 @@
 				}
 			}
 		});
+	},
+
+	accounts_on_form_rendered: function(frm) {
+		const options = frm.doc.__onload;
+
+		if (options && frm.cur_grid) {
+			frm.cur_grid.get_field("reference_due_date")
+				.df.options = options[frm.cur_grid.get_field('reference_name').value];
+			frm.cur_grid.refresh_field('reference_due_date');
+		}
 	}
 });
 
@@ -248,7 +258,6 @@
 
 		if (d.reference_type && d.reference_name && d.reference_due_date) {
 			if (in_list(["Sales Invoice", "Purchase Invoice"], d.reference_type)) {
-				console.log('cdt:', cdt, cdn);
 				frappe.model.set_value(cdt, cdn, 'debit_in_account_currency', '');
 				frappe.model.set_value(cdt, cdn, 'credit_in_account_currency', '');
 			}
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index a298ae3..0c3503b 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -3,7 +3,7 @@
 
 from __future__ import unicode_literals
 import frappe, erpnext, json
-from frappe.utils import cstr, flt, fmt_money, formatdate, getdate
+from frappe.utils import cstr, flt, fmt_money, formatdate, getdate, DATE_FORMAT
 from frappe import msgprint, _, scrub
 from erpnext.controllers.accounts_controller import AccountsController
 from erpnext.accounts.utils import get_balance_on, get_account_currency
@@ -647,9 +647,8 @@
 		party_type = "Supplier"
 		party_account = ref_doc.credit_to
 
-
-	if (dt=="Sales Invoice" and ref_doc.outstanding_amount > 0) \
-		or (dt=="Purchase Invoice" and ref_doc.outstanding_amount < 0):
+	if (dt == "Sales Invoice" and ref_doc.outstanding_amount > 0) \
+		or (dt == "Purchase Invoice" and ref_doc.outstanding_amount < 0):
 			amount_field_party = "credit_in_account_currency"
 			amount_field_bank = "debit_in_account_currency"
 	else:
@@ -670,6 +669,7 @@
 		"journal_entry": journal_entry
 	})
 
+
 def get_payment_entry(ref_doc, args):
 	cost_center = frappe.db.get_value("Company", ref_doc.company, "cost_center")
 	exchange_rate = 1
@@ -687,26 +687,58 @@
 		"remark": args.get("remarks")
 	})
 
-	party_row = je.append("accounts", {
-		"account": args.get("party_account"),
-		"party_type": args.get("party_type"),
-		"party": ref_doc.get(args.get("party_type").lower()),
-		"cost_center": cost_center,
-		"account_type": frappe.db.get_value("Account", args.get("party_account"), "account_type"),
-		"account_currency": args.get("party_account_currency") or \
-			get_account_currency(args.get("party_account")),
-		"balance": get_balance_on(args.get("party_account")),
-		"party_balance": get_balance_on(party=args.get("party"), party_type=args.get("party_type")),
-		"exchange_rate": exchange_rate,
-		args.get("amount_field_party"): args.get("amount"),
-		"is_advance": args.get("is_advance"),
-		"reference_type": ref_doc.doctype,
-		"reference_name": ref_doc.name
-	})
+	if not ref_doc.payment_schedule:
+		je.append("accounts", {
+			"account": args.get("party_account"),
+			"party_type": args.get("party_type"),
+			"party": ref_doc.get(args.get("party_type").lower()),
+			"cost_center": cost_center,
+			"account_type": frappe.db.get_value("Account", args.get("party_account"), "account_type"),
+			"account_currency": args.get("party_account_currency") or \
+								get_account_currency(args.get("party_account")),
+			"balance": get_balance_on(args.get("party_account")),
+			"party_balance": get_balance_on(party=args.get("party"), party_type=args.get("party_type")),
+			"exchange_rate": exchange_rate,
+			args.get("amount_field_party"): args.get("amount"),
+			"is_advance": args.get("is_advance"),
+			"reference_type": ref_doc.doctype,
+			"reference_name": ref_doc.name
+		})
+
+	else:
+		options_ref_name_list = [
+			d.due_date.strftime(DATE_FORMAT) for d in ref_doc.payment_schedule
+			if d.get('due_date')
+		]
+
+		for payment_term in ref_doc.payment_schedule:
+			je.append("accounts", {
+				"account": args.get("party_account"),
+				"party_type": args.get("party_type"),
+				"party": ref_doc.get(args.get("party_type").lower()),
+				"cost_center": cost_center,
+				"account_type": frappe.db.get_value("Account", args.get("party_account"), "account_type"),
+				"account_currency": args.get("party_account_currency") or \
+									get_account_currency(args.get("party_account")),
+				"balance": get_balance_on(args.get("party_account")),
+				"party_balance": get_balance_on(party=args.get("party"), party_type=args.get("party_type")),
+				"exchange_rate": exchange_rate,
+				args.get("amount_field_party"): payment_term.payment_amount,
+				"is_advance": args.get("is_advance"),
+				"reference_type": ref_doc.doctype,
+				"reference_name": ref_doc.name,
+				"reference_due_date": payment_term.due_date
+			})
+			je.set_onload(ref_doc.name, '\n'.join(options_ref_name_list))
+
+	# First multi currency check
+	for row in je.accounts:
+		if row.account_currency != ref_doc.company_currency:
+			je.multi_currency = 1
 
 	bank_row = je.append("accounts")
 
-	#make it bank_details
+	# Make it bank_details
 	bank_account = get_default_bank_cash_account(ref_doc.company, "Bank", account=args.get("bank_account"))
 	if bank_account:
 		bank_row.update(bank_account)
@@ -725,9 +757,9 @@
 	else:
 		bank_row.set(args.get("amount_field_bank"), amount * exchange_rate)
 
-	# set multi currency check
-	if party_row.account_currency != ref_doc.company_currency \
-		or (bank_row.account_currency and bank_row.account_currency != ref_doc.company_currency):
+	# Multi currency check again
+	if not je.multi_currency:
+		if bank_row.account_currency and bank_row.account_currency != ref_doc.company_currency:
 			je.multi_currency = 1
 
 	je.set_amounts_in_company_currency()
@@ -735,6 +767,7 @@
 
 	return je if args.get("journal_entry") else je.as_dict()
 
+
 @frappe.whitelist()
 def get_opening_accounts(company):
 	"""get all balance sheet accounts for opening entry"""
@@ -757,6 +790,7 @@
 		and jv.docstatus = 1 and jv.`{0}` like %s order by jv.name desc limit %s, %s""".format(frappe.db.escape(searchfield)),
 		(filters.get("account"), cstr(filters.get("party")), "%{0}%".format(txt), start, page_len))
 
+
 @frappe.whitelist()
 def get_outstanding(args):
 	if not frappe.has_permission("Account"):
@@ -809,6 +843,7 @@
 			"party": invoice.get(scrub(party_type))
 		}
 
+
 @frappe.whitelist()
 def get_party_account_and_balance(company, party_type, party):
 	if not frappe.has_permission("Account"):
@@ -826,6 +861,7 @@
 		"account_currency": frappe.db.get_value("Account", account, "account_currency")
 	}
 
+
 @frappe.whitelist()
 def get_account_balance_and_party_type(account, date, company, debit=None, credit=None, exchange_rate=None):
 	"""Returns dict of account balance and party type to be set in Journal Entry on selection of account."""
@@ -863,7 +899,7 @@
 
 	return grid_values
 
-# Added posting_date as one of the parameters of get_exchange_rate
+
 @frappe.whitelist()
 def get_exchange_rate(posting_date, account=None, account_currency=None, company=None,
 		reference_type=None, reference_name=None, debit=None, credit=None, exchange_rate=None):
@@ -896,6 +932,7 @@
 	# don't return None or 0 as it is multipled with a value and that value could be lost
 	return exchange_rate or 1
 
+
 @frappe.whitelist()
 def get_average_exchange_rate(account):
 	exchange_rate = 0
diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py
index f173376..f09e8db 100644
--- a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py
+++ b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py
@@ -4,7 +4,7 @@
 
 from __future__ import unicode_literals
 import frappe
-from frappe import _
+from frappe import _, scrub
 from frappe.utils import flt
 from frappe.model.document import Document
 
@@ -68,29 +68,18 @@
 		for row in self.invoices:
 			if not row.qty:
 				row.qty = 1.0
-			if not row.party:
-				frappe.throw(mandatory_error_msg.format(
-					idx=row.idx,
-					field=_("Party"),
-					invoice_type=self.invoice_type
-				))
+
 			# set party type if not available
 			if not row.party_type:
 				row.party_type = "Customer" if self.invoice_type == "Sales" else "Supplier"
 
-			if not row.posting_date:
-				frappe.throw(mandatory_error_msg.format(
-					idx=row.idx,
-					field=_("Party"),
-					invoice_type=self.invoice_type
-				))
-
-			if not row.outstanding_amount:
-				frappe.throw(mandatory_error_msg.format(
-					idx=row.idx,
-					field=_("Outstanding Amount"),
-					invoice_type=self.invoice_type
-				))
+			for d in ("Party", "Posting Date", "Outstanding Amount", "Due Date", "Temporary Opening Account"):
+				if not row.get(scrub(d)):
+					frappe.throw(mandatory_error_msg.format(
+						idx=row.idx,
+						field=_(d),
+						invoice_type=self.invoice_type
+					))
 
 			args = self.get_invoice_dict(row=row)
 			if not args:
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 197f1af..72ebce2 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -508,13 +508,18 @@
 
 	# Get negative outstanding sales /purchase invoices
 	negative_outstanding_invoices = []
-	if args.get("party_type") not in ["Student", "Employee"]:
+	if args.get("party_type") not in ["Student", "Employee"] and not args.get("voucher_no"):
 		negative_outstanding_invoices = get_negative_outstanding_invoices(args.get("party_type"),
 			args.get("party"), args.get("party_account"), party_account_currency, company_currency)
 
 	# Get positive outstanding sales /purchase invoices/ Fees
+	condition = ""
+	if args.get("voucher_type") and args.get("voucher_no"):
+		condition = " and voucher_type='{0}' and voucher_no='{1}'"\
+			.format(frappe.db.escape(args["voucher_type"]), frappe.db.escape(args["voucher_no"]))
+
 	outstanding_invoices = get_outstanding_invoices(args.get("party_type"), args.get("party"),
-		args.get("party_account"))
+		args.get("party_account"), condition=condition)
 
 	for d in outstanding_invoices:
 		d["exchange_rate"] = 1
@@ -803,8 +808,13 @@
 		})
 	else:
 		args = {
-			'party_account': party_account, 'company': pe.company, 'party_type': pe.party_type,
-			'party': pe.party, 'posting_date': pe.posting_date
+			'party_account': party_account,
+			'company': pe.company,
+			'party_type': pe.party_type,
+			'party': pe.party,
+			'posting_date': pe.posting_date,
+			'voucher_type': dt,
+			'voucher_no': dn
 		}
 		references = get_outstanding_reference_documents(args=args)
 
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
index 7247323..59b7c96 100755
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
@@ -147,7 +147,7 @@
    "collapsible": 0, 
    "columns": 0, 
    "fieldname": "tax_id", 
-   "fieldtype": "Data", 
+   "fieldtype": "Read Only", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -158,6 +158,7 @@
    "label": "Tax Id", 
    "length": 0, 
    "no_copy": 0, 
+   "options": "supplier.tax_id", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 1, 
@@ -3913,7 +3914,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2017-12-07 15:37:30.173811", 
+ "modified": "2017-12-15 17:49:51.230092", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Purchase Invoice", 
diff --git a/erpnext/accounts/print_format/gst_pos_invoice/gst_pos_invoice.json b/erpnext/accounts/print_format/gst_pos_invoice/gst_pos_invoice.json
index 5debb5c..009ed4d 100644
--- a/erpnext/accounts/print_format/gst_pos_invoice/gst_pos_invoice.json
+++ b/erpnext/accounts/print_format/gst_pos_invoice/gst_pos_invoice.json
@@ -2,7 +2,7 @@
  "align_labels_right": 0, 
  "creation": "2017-08-08 12:33:04.773099", 
  "custom_format": 1, 
- "disabled": 0, 
+ "disabled": 1, 
  "doc_type": "Sales Invoice", 
  "docstatus": 0, 
  "doctype": "Print Format", 
@@ -10,7 +10,7 @@
  "html": "<style>\n\t.print-format table, .print-format tr, \n\t.print-format td, .print-format div, .print-format p {\n\t\tfont-family: Monospace;\n\t\tline-height: 200%;\n\t\tvertical-align: middle;\n\t}\n\t@media screen {\n\t\t.print-format {\n\t\t\twidth: 4in;\n\t\t\tpadding: 0.25in;\n\t\t\tmin-height: 8in;\n\t\t}\n\t}\n</style>\n\n<p class=\"text-center\">\n\t{{ doc.company }}<br>\n\t{% if doc.company_address_display %}\n\t\t{% set company_address = doc.company_address_display.replace(\"\\n\", \" \").replace(\"<br>\", \" \") %}\n\t\t{% if \"GSTIN\" not in company_address %}\n\t\t\t{{ company_address }}\n\t\t\t<b>{{ _(\"GSTIN\") }}:</b>{{ doc.company_gstin }}\n\t\t{% else %}\n\t\t\t{{ company_address.replace(\"GSTIN\", \"<br>GSTIN\") }}\n\t\t{% endif %}\n\t{% endif %}\n\t<br>\n\t<b>{{ doc.select_print_heading or _(\"Invoice\") }}</b><br>\n</p>\n<p>\n\t<b>{{ _(\"Receipt No\") }}:</b> {{ doc.name }}<br>\n\t<b>{{ _(\"Date\") }}:</b> {{ doc.get_formatted(\"posting_date\") }}<br>\n\t{% if doc.grand_total > 50000 %}\n\t\t{% set customer_address = doc.address_display.replace(\"\\n\", \" \").replace(\"<br>\", \" \") %}\n\t\t<b>{{ _(\"Customer\") }}:</b><br>\n\t\t{{ doc.customer_name }}<br>\n\t\t{{ customer_address }}\n\t{% endif %}\n</p>\n\n<hr>\n<table class=\"table table-condensed cart no-border\">\n\t<thead>\n\t\t<tr>\n\t\t\t<th width=\"40%\">{{ _(\"Item\") }}</b></th>\n\t\t\t<th width=\"30%\" class=\"text-right\">{{ _(\"Qty\") }}</th>\n\t\t\t<th width=\"30%\" class=\"text-right\">{{ _(\"Amount\") }}</th>\n\t\t</tr>\n\t</thead>\n\t<tbody>\n\t\t{%- for item in doc.items -%}\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\t{{ item.item_code }}\n\t\t\t\t{%- if item.item_name != item.item_code -%}\n\t\t\t\t\t<br>{{ item.item_name }}\n\t\t\t\t{%- endif -%}\n\t\t\t\t{%- if item.gst_hsn_code -%}\n\t\t\t\t\t<br><b>{{ _(\"HSN/SAC\") }}:</b> {{ item.gst_hsn_code }}\n\t\t\t\t{%- endif -%}\n\t\t\t\t{%- if item.serial_no -%}\n\t\t\t\t\t<br><b>{{ _(\"Serial No\") }}:</b> {{ item.serial_no }}\n\t\t\t\t{%- endif -%}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">{{ item.qty }}<br>@ {{ item.rate }}</td>\n\t\t\t<td class=\"text-right\">{{ item.get_formatted(\"amount\") }}</td>\n\t\t</tr>\n\t\t{%- endfor -%}\n\t</tbody>\n</table>\n<table class=\"table table-condensed no-border\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 70%\">\n\t\t\t\t{{ _(\"Net Total\") }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ doc.get_formatted(\"net_total\") }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{%- for row in doc.taxes -%}\n\t\t{%- if not row.included_in_print_rate -%}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 70%\">\n\t\t\t\t{{ row.description }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ row.get_formatted(\"tax_amount\", doc) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{%- endif -%}\n\t\t{%- endfor -%}\n\t\t{%- if doc.discount_amount -%}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 75%\">\n\t\t\t\t{{ _(\"Discount\") }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ doc.get_formatted(\"discount_amount\") }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{%- endif -%}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 75%\">\n\t\t\t\t<b>{{ _(\"Grand Total\") }}</b>\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ doc.get_formatted(\"grand_total\") }}\n\t\t\t</td>\n\t\t</tr>\n\t</tbody>\n</table>\n<p><b>Tax Breakup:</b></p>\n<div style=\"font-size: 8px\">\n\t{{ doc.other_charges_calculation }}\n</div>\n<p>{{ doc.terms or \"\" }}</p>\n<p class=\"text-center\">{{ _(\"Thank you, please visit again.\") }}</p>", 
  "idx": 0, 
  "line_breaks": 0, 
- "modified": "2017-09-14 15:54:19.467642", 
+ "modified": "2017-12-15 11:57:11.712191", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "GST POS Invoice", 
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py
index c275c04..f169b99 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.py
+++ b/erpnext/accounts/report/general_ledger/general_ledger.py
@@ -245,6 +245,9 @@
 		if gle.posting_date < from_date or cstr(gle.is_opening) == "Yes":
 			update_value_in_dict(gle_map[gle.account].totals, 'opening', gle)
 			update_value_in_dict(totals, 'opening', gle)
+			
+			update_value_in_dict(gle_map[gle.account].totals, 'closing', gle)
+			update_value_in_dict(totals, 'closing', gle)
 
 		elif gle.posting_date <= to_date:
 			update_value_in_dict(gle_map[gle.account].totals, 'total', gle)
@@ -254,8 +257,8 @@
 			else:
 				entries.append(gle)
 
-		update_value_in_dict(gle_map[gle.account].totals, 'closing', gle)
-		update_value_in_dict(totals, 'closing', gle)
+			update_value_in_dict(gle_map[gle.account].totals, 'closing', gle)
+			update_value_in_dict(totals, 'closing', gle)
 
 	return totals, entries
 
diff --git a/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.py b/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.py
index 2ab3053c..73e8b25 100644
--- a/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.py
+++ b/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.py
@@ -15,12 +15,12 @@
 def get_column():
 	return [
 		_("Purchase Receipt") + ":Link/Purchase Receipt:120", _("Date") + ":Date:100",
-		_("Suplier") + ":Link/Supplier:120", _("Suplier Name") + "::120",
-		_("Project") + ":Link/Project:120", _("Item Code") + ":Link/Item:120", 
+		_("Supplier") + ":Link/Supplier:120", _("Supplier Name") + "::120",
+		_("Project") + ":Link/Project:120", _("Item Code") + ":Link/Item:120",
 		_("Amount") + ":Currency:100", _("Billed Amount") + ":Currency:100", _("Amount to Bill") + ":Currency:100",
 		_("Item Name") + "::120", _("Description") + "::120", _("Company") + ":Link/Company:120",
 	]
 
 def get_args():
-	return {'doctype': 'Purchase Receipt', 'party': 'supplier', 
+	return {'doctype': 'Purchase Receipt', 'party': 'supplier',
 		'date': 'posting_date', 'order': 'name', 'order_by': 'desc'}
\ No newline at end of file
diff --git a/erpnext/agriculture/doctype/crop_cycle/crop_cycle.js b/erpnext/agriculture/doctype/crop_cycle/crop_cycle.js
index 98dd056..ae28bb7 100644
--- a/erpnext/agriculture/doctype/crop_cycle/crop_cycle.js
+++ b/erpnext/agriculture/doctype/crop_cycle/crop_cycle.js
@@ -15,7 +15,7 @@
 					output[doctype].forEach( (analysis_doc) => {
 						let point_to_be_tested = JSON.parse(analysis_doc.location).features[0].geometry.coordinates;
 						let poly_of_land = JSON.parse(land_doc.location).features[0].geometry.coordinates[0];
-						if (test_analysis_position(point_to_be_tested, poly_of_land)){
+						if (is_in_land_unit(point_to_be_tested, poly_of_land)){
 							obj_to_append[analysis_doctypes_docs[analysis_doctypes.indexOf(doctype)]].push(analysis_doc.name);
 						}
 					});
@@ -28,7 +28,7 @@
 	}
 });
 
-function test_analysis_position(point, vs) {
+function is_in_land_unit(point, vs) {
 	// ray-casting algorithm based on
 	// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
 	
diff --git a/erpnext/agriculture/doctype/crop_cycle/crop_cycle.json b/erpnext/agriculture/doctype/crop_cycle/crop_cycle.json
index 410a0d4..e508888 100644
--- a/erpnext/agriculture/doctype/crop_cycle/crop_cycle.json
+++ b/erpnext/agriculture/doctype/crop_cycle/crop_cycle.json
@@ -599,6 +599,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "depends_on": "eval:!doc.__islocal", 
    "description": "List of diseases detected on the field. When selected it'll automatically add a list of tasks to deal with the disease ", 
    "fieldname": "section_break_14", 
    "fieldtype": "Section Break", 
@@ -790,7 +791,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-12-06 01:47:26.656870", 
+ "modified": "2017-12-18 12:54:29.071743", 
  "modified_by": "Administrator", 
  "module": "Agriculture", 
  "name": "Crop Cycle", 
diff --git a/erpnext/agriculture/doctype/crop_cycle/crop_cycle.py b/erpnext/agriculture/doctype/crop_cycle/crop_cycle.py
index 8912f59..819315c 100644
--- a/erpnext/agriculture/doctype/crop_cycle/crop_cycle.py
+++ b/erpnext/agriculture/doctype/crop_cycle/crop_cycle.py
@@ -12,11 +12,32 @@
 		if self.is_new():
 			crop = frappe.get_doc('Crop', self.crop)
 			self.create_project(crop.period, crop.agriculture_task)
-		if not self.project:
-			self.project = self.name
-		for detected_disease in self.detected_disease:
-			disease = frappe.get_doc('Disease', detected_disease.disease)
-			self.create_task(disease.treatment_task, self.name, detected_disease.start_date)
+			if not self.crop_spacing_uom:
+				self.crop_spacing_uom = crop.crop_spacing_uom
+			if not self.row_spacing_uom:
+				self.row_spacing_uom = crop.row_spacing_uom
+			if not self.project:
+				self.project = self.name
+		else:
+			old_disease, new_disease = [], []
+			for detected_disease in self.detected_disease:
+				new_disease.append(detected_disease.name)
+			for detected_disease in self.get_doc_before_save().get('detected_disease'):
+				old_disease.append(detected_disease.name)
+			if list(set(new_disease)-set(old_disease)) != []:
+				self.update_disease(list(set(new_disease)-set(old_disease)))
+				frappe.msgprint("All tasks for the detected diseases were imported")
+
+	def update_disease(self, disease_hashes):
+		new_disease = []
+		for disease in self.detected_disease:
+			for disease_hash in disease_hashes:
+				if disease.name == disease_hash:
+					self.import_disease_tasks(disease.disease, disease.start_date)
+
+	def import_disease_tasks(self, disease, start_date):
+		disease_doc = frappe.get_doc('Disease', disease)
+		self.create_task(disease_doc.treatment_task, self.name, start_date)
 
 	def create_project(self, period, crop_tasks):
 		project = frappe.new_doc("Project")
@@ -59,4 +80,19 @@
 		return ast.literal_eval(doc.location).get('features')[0].get('geometry').get('coordinates')
 
 	def get_geometry_type(self, doc):
-		return ast.literal_eval(doc.location).get('features')[0].get('geometry').get('type')
\ No newline at end of file
+		return ast.literal_eval(doc.location).get('features')[0].get('geometry').get('type')
+
+	def is_in_land_unit(self, point, vs):
+		x, y = point
+		inside = False
+		j = len(vs)-1
+		i = 0
+		while i < len(vs):
+			xi, yi = vs[i]
+			xj, yj = vs[j]
+			intersect = ((yi > y) != (yj > y)) and (x < (xj - xi) * (y - yi) / (yj - yi) + xi)
+			if intersect:
+				inside = not inside
+			i = j
+			j += 1
+		return inside
\ No newline at end of file
diff --git a/erpnext/agriculture/doctype/land_unit/land_unit.js b/erpnext/agriculture/doctype/land_unit/land_unit.js
index c9ab348..3bf1434 100644
--- a/erpnext/agriculture/doctype/land_unit/land_unit.js
+++ b/erpnext/agriculture/doctype/land_unit/land_unit.js
@@ -9,6 +9,13 @@
 	setup: function(frm) {
 		frm.add_fetch("parent_land_unit", "latitude", "latitude");
 		frm.add_fetch("parent_land_unit", "longitude", "longitude");
+		frm.set_query("parent_land_unit", function() {
+			return {
+				"filters": {
+					"is_group": 1
+				}
+			};
+		});
 	},
 
 	onload_post_render(frm){
@@ -20,12 +27,4 @@
 			frm.doc.longitude = frm.fields_dict.location.map.getCenter()['lng'];
 		}
 	},
-	refresh: function(frm) {
-		if(!frm.doc.parent_land_unit) {
-			frm.set_read_only();
-			frm.set_intro(__("This is a root land unit and cannot be edited."));
-		} else {
-			frm.set_intro(null);
-		}
-	},
 });
diff --git a/erpnext/agriculture/doctype/land_unit/land_unit.json b/erpnext/agriculture/doctype/land_unit/land_unit.json
index e5f6c0d..94d350f 100644
--- a/erpnext/agriculture/doctype/land_unit/land_unit.json
+++ b/erpnext/agriculture/doctype/land_unit/land_unit.json
@@ -431,7 +431,7 @@
    "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
-   "read_only": 0, 
+   "read_only": 1, 
    "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -632,7 +632,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-12-13 16:50:18.581137", 
+ "modified": "2017-12-14 18:16:15.124188", 
  "modified_by": "Administrator", 
  "module": "Agriculture", 
  "name": "Land Unit", 
@@ -680,7 +680,7 @@
    "write": 1
   }
  ], 
- "quick_entry": 0, 
+ "quick_entry": 1, 
  "read_only": 0, 
  "read_only_onload": 0, 
  "show_name_in_global_search": 1, 
diff --git a/erpnext/agriculture/doctype/land_unit/land_unit.py b/erpnext/agriculture/doctype/land_unit/land_unit.py
index 634cb75..42a9b33 100644
--- a/erpnext/agriculture/doctype/land_unit/land_unit.py
+++ b/erpnext/agriculture/doctype/land_unit/land_unit.py
@@ -10,6 +10,7 @@
 from  frappe import _
 
 from frappe.utils.nestedset import NestedSet
+from frappe.utils import flt
 # from frappe.model.document import Document
 
 RADIUS = 6378137
@@ -31,6 +32,7 @@
 				ancestor_features[index] = json.loads(feature)
 			ancestor_doc.set_location_value(features = ancestor_features)	
 			ancestor_doc.db_set(fieldname='area', value=ancestor_doc.get('area')-self.get('area'),commit=True)
+		super(LandUnit, self).on_update()
 
 	def validate(self):
 		if not self.is_new():
@@ -39,10 +41,10 @@
 			else:
 				features = json.loads(self.get('location')).get('features')
 			new_area = compute_area(features)
-			self.area_difference = new_area - self.area
+			self.area_difference = new_area - flt(self.area)
 			self.area = new_area	
 
-			if self.get('parent'): 
+			if self.get('parent_land_unit'):
 				ancestors = self.get_ancestors()
 				self_features = self.add_child_property()
 				self_features = set(self_features)
@@ -78,7 +80,6 @@
 
 	def on_update(self):
 		super(LandUnit, self).on_update()
-		self.validate_one_root()
 
 	def add_child_property(self):
 		location = self.get('location')
@@ -118,7 +119,7 @@
 			layer_area += polygon_area(coords = feature.get('geometry').get('coordinates'))
 		elif feature.get('geometry').get('type') == 'Point' and feature.get('properties').get('point_type') == 'circle':
 			layer_area += math.pi * math.pow(feature.get('properties').get('radius'), 2)
-	return layer_area
+	return flt(layer_area)
 
 def rad(angle_in_degrees):
 	return angle_in_degrees*math.pi/180
@@ -162,4 +163,18 @@
 
 		area = area * RADIUS * RADIUS / 2
 	return area
+
+@frappe.whitelist()
+def get_children(doctype, parent, is_root=False):
+	if is_root:
+		parent = ''
+
+	land_units = frappe.db.sql("""select name as value,
+		is_group as expandable
+		from `tabLand Unit`
+		where ifnull(`parent_land_unit`,'') = %s
+		order by name""", (parent), as_dict=1)
+
+	# return nodes
+	return land_units
 		
\ No newline at end of file
diff --git a/erpnext/agriculture/doctype/land_unit/land_unit_tree.js b/erpnext/agriculture/doctype/land_unit/land_unit_tree.js
index 0d7a53e..bf64126 100644
--- a/erpnext/agriculture/doctype/land_unit/land_unit_tree.js
+++ b/erpnext/agriculture/doctype/land_unit/land_unit_tree.js
@@ -1,15 +1,30 @@
 frappe.treeview_settings["Land Unit"] = {
+	get_tree_nodes: "erpnext.agriculture.doctype.land_unit.land_unit.get_children",
 	ignore_fields:["parent_land_unit"],
+	get_tree_root: false,
 	disable_add_node: true,
+	root_label: "All Land Units",
+	onload: function(me) {
+		me.make_tree();
+	},
 	toolbar: [
 		{ toggle_btn: true },
 		{
-			label:__("Add Child"),
+			label:__("Edit"),
+			condition: function(node) { return (node.label!='All Land Units'); },
 			click: function(node) {
+				frappe.set_route('Form', 'Land Unit', node.data.value);
+			}
+		},
+		{
+			label:__("Add Child"),
+			condition: function(node) { return node.expandable; },
+			click: function(node) {
+				if(node.label=='All Land Units') node.label='';
 				var lu = frappe.new_doc("Land Unit", {
 					"parent_land_unit": node.label
-				})
+				});
 			}
 		}
 	],
-}
\ No newline at end of file
+};
\ No newline at end of file
diff --git a/erpnext/agriculture/doctype/land_unit/test_land_unit.js b/erpnext/agriculture/doctype/land_unit/test_land_unit.js
index c23db77..f9d3566 100644
--- a/erpnext/agriculture/doctype/land_unit/test_land_unit.js
+++ b/erpnext/agriculture/doctype/land_unit/test_land_unit.js
@@ -12,7 +12,6 @@
 		// insert a new Land Unit
 		() => frappe.tests.make('Land Unit', [
 			// values to be set
-			{parent_land_unit: 'All Land Units'},
 			{land_unit_name: 'Basil Farm'}
 		]),
 		() => {
diff --git a/erpnext/agriculture/doctype/land_unit/test_land_unit.py b/erpnext/agriculture/doctype/land_unit/test_land_unit.py
index cf08f98..c45ad5e 100644
--- a/erpnext/agriculture/doctype/land_unit/test_land_unit.py
+++ b/erpnext/agriculture/doctype/land_unit/test_land_unit.py
@@ -21,6 +21,6 @@
 			temp['features'][0]['properties']['feature_of'] =	land_unit 
 			formatted_land_units.extend(temp['features'])
 		formatted_land_unit_string = str(formatted_land_units)
-		all_land_units = frappe.get_doc('Land Unit', 'All Land Units')
-		self.assertEquals(formatted_land_unit_string, str(json.loads(all_land_units.get('location'))['features']))
-		self.assertEquals(area, all_land_units.get('area'))
+		test_land = frappe.get_doc('Land Unit', 'Test Land')
+		self.assertEquals(formatted_land_unit_string, str(json.loads(test_land.get('location'))['features']))
+		self.assertEquals(area, test_land.get('area'))
diff --git a/erpnext/agriculture/doctype/land_unit/test_records.json b/erpnext/agriculture/doctype/land_unit/test_records.json
index 6baaf27..e7fed9f 100644
--- a/erpnext/agriculture/doctype/land_unit/test_records.json
+++ b/erpnext/agriculture/doctype/land_unit/test_records.json
@@ -1,10 +1,16 @@
 [
 	{
 		"doctype": "Land Unit",
+		"land_unit_name": "Test Land",
+		"is_group": 1,
+		"is_container": 1
+	},
+	{
+		"doctype": "Land Unit",
 		"land_unit_name": "Basil Farm",
 		"location": "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"point_type\":\"circle\",\"radius\":884.5625420736483},\"geometry\":{\"type\":\"Point\",\"coordinates\":[72.875834,19.100566]}}]}",
-		"parent_land_unit": "All Land Units",
-		"parent": "All Land Units",
+		"parent_land_unit": "Test Land",
+		"parent": "Test Land",
 		"is_group": 1,
 		"is_container": 1
 	},
diff --git a/erpnext/agriculture/setup.py b/erpnext/agriculture/setup.py
index 9044e09..ab91343 100644
--- a/erpnext/agriculture/setup.py
+++ b/erpnext/agriculture/setup.py
@@ -4,7 +4,7 @@
 from erpnext.setup.utils import insert_record
 
 def setup_agriculture():
-	if frappe.db.exists('Land Unit', 'All Land Units'):
+	if frappe.get_all('Agriculture Analysis Criteria'):
 		# already setup
 		return
 	create_agriculture_data()
@@ -12,11 +12,6 @@
 def create_agriculture_data():
 	records = [
 		dict(
-			doctype="Land Unit",
-			land_unit_name="All Land Units",
-			is_group=1,
-			is_container=1),
-		dict(
 			doctype='Item Group',
 			item_group_name='Fertilizer',
 			is_group=0,
diff --git a/erpnext/config/desktop.py b/erpnext/config/desktop.py
index 5926838..36d2b40 100644
--- a/erpnext/config/desktop.py
+++ b/erpnext/config/desktop.py
@@ -292,12 +292,14 @@
 			"label": _("Hub")
 		},
 		{
-			"module_name": "Data Import Tool",
-			"color": "#7f8c8d",
+			"module_name": "Data Import",
+			"color": "#FFF168",
+			"reverse": 1,
+			"doctype": "Data Import",
 			"icon": "octicon octicon-cloud-upload",
-			"type": "page",
-			"link": "data-import-tool",
-			"label": _("Data Import Tool")
+			"label": _("Data Import"),
+			"link": "List/Data Import",
+			"type": "list"
 		},
 		{
 			"module_name": "Restaurant",
diff --git a/erpnext/config/learn.py b/erpnext/config/learn.py
index 86db808..c5c41d0 100644
--- a/erpnext/config/learn.py
+++ b/erpnext/config/learn.py
@@ -24,7 +24,7 @@
 				{
 					"type": "help",
 					"label": _("Report Builder"),
-					"youtube_id": "y0o5iYZOioU"
+					"youtube_id": "TxJGUNarcQs"
 				},
 			]
 
@@ -40,7 +40,7 @@
 				{
 					"type": "help",
 					"label": _("Opening Stock Balance"),
-					"youtube_id": "0yPgrtfeCTs"
+					"youtube_id": "nlHX0ZZ84Lw"
 				},
 				{
 					"type": "help",
@@ -55,7 +55,7 @@
 				{
 					"type": "help",
 					"label": _("Users and Permissions"),
-					"youtube_id": "fnBoRhBrwR4"
+					"youtube_id": "8Slw1hsTmUI"
 				},
 				{
 					"type": "help",
@@ -120,7 +120,7 @@
 				{
 					"type": "help",
 					"label": _("Sales Order to Payment"),
-					"youtube_id": "7AMq4lqkN4A"
+					"youtube_id": "1eP90MWoDQM"
 				},
 				{
 					"type": "help",
@@ -195,12 +195,12 @@
 				{
 					"type": "help",
 					"label": _("Material Request to Purchase Order"),
-					"youtube_id": "4TN9kPyfIqM"
+					"youtube_id": "55Gk2j7Q8Zw"
 				},
 				{
 					"type": "help",
 					"label": _("Purchase Order to Payment"),
-					"youtube_id": "EK65tLdVUDk"
+					"youtube_id": "efFajTTQBa8"
 				},
 				{
 					"type": "help",
@@ -261,7 +261,7 @@
 				{
 					"type": "help",
 					"label": _("Managing Projects"),
-					"youtube_id": "egxIGwtoKI4"
+					"youtube_id": "gCzShu9Niu4"
 				},
 			]
 		},
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index c8d30c8..10e1d92 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -693,8 +693,9 @@
 			total = 0
 			for d in self.get("payment_schedule"):
 				total += flt(d.payment_amount)
+			total = flt(total, self.precision("grand_total"))
 
-			grand_total = self.get("rounded_total") or self.grand_total
+			grand_total = flt(self.get("rounded_total") or self.grand_total, self.precision('grand_total'))
 			if total != grand_total:
 				frappe.throw(_("Total Payment Amount in Payment Schedule must be equal to Grand / Rounded Total"))
 
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js
index c6333db..65d1065 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.js
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.js
@@ -168,6 +168,16 @@
 		frm.trigger("set_query_for_payable_account");
 		frm.add_fetch("company", "cost_center", "cost_center");
 		frm.add_fetch("company", "default_payable_account", "payable_account");
+		frm.set_query("employee_advance", "advances", function(doc) {
+			return {
+				filters: [
+					['docstatus', '=', 1],
+					['employee', '=', doc.employee],
+					['paid_amount', '>', 0],
+					['paid_amount', '>', 'claimed_amount']
+				]
+			};
+		});
 	},
 
 	refresh: function(frm) {
@@ -294,10 +304,41 @@
 	}
 });
 
+frappe.ui.form.on("Expense Claim Advance", {
+	employee_advance: function(frm, cdt, cdn) {
+		var child = locals[cdt][cdn];
+		if(!frm.doc.employee){
+			frappe.msgprint('Select an employee to get the employee advance.');
+			frm.doc.advances = [];
+			refresh_field("advances");
+		}
+		else {
+			return frappe.call({
+				method: "erpnext.hr.doctype.expense_claim.expense_claim.get_advances",
+				args: {
+					employee: frm.doc.employee,
+					advance_id: child.employee_advance
+				},
+				callback: function(r, rt) {
+					if(r.message) {
+						child.employee_advance = r.message[0].name;
+						child.posting_date = r.message[0].posting_date;
+						child.advance_account = r.message[0].advance_account;
+						child.advance_paid = r.message[0].paid_amount;
+						child.unclaimed_amount = flt(r.message[0].paid_amount) - flt(r.message[0].claimed_amount);
+						child.allocated_amount = flt(r.message[0].paid_amount) - flt(r.message[0].claimed_amount);
+						refresh_field("advances");
+					}
+				}
+			});
+		}
+	}
+});
+
 cur_frm.fields_dict['task'].get_query = function(doc) {
 	return {
 		filters:{
 			'project': doc.project
 		}
 	};
-};
+};
\ No newline at end of file
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py
index d27675c..9462211 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.py
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.py
@@ -310,9 +310,16 @@
 	}
 
 @frappe.whitelist()
-def get_advances(employee):
+def get_advances(employee, advance_id=None):
+	if not advance_id:
+		condition = 'docstatus=1 and employee="{0}" and paid_amount > 0 and paid_amount > claimed_amount'.format(frappe.db.escape(employee))
+	else:
+		condition = 'name="{0}"'.format(frappe.db.escape(advance_id))
+
 	return frappe.db.sql("""
-		select name, posting_date, paid_amount, claimed_amount, advance_account
-		from `tabEmployee Advance`
-		where docstatus=1 and employee=%s and paid_amount > 0 and paid_amount > claimed_amount
-	""", employee, as_dict=1)
\ No newline at end of file
+		select 
+			name, posting_date, paid_amount, claimed_amount, advance_account
+		from 
+			`tabEmployee Advance`
+		where {0}
+	""".format(condition), as_dict=1)
\ No newline at end of file
diff --git a/erpnext/hr/doctype/payroll_entry/payroll_entry.js b/erpnext/hr/doctype/payroll_entry/payroll_entry.js
index 3f00166..cf15846 100644
--- a/erpnext/hr/doctype/payroll_entry/payroll_entry.js
+++ b/erpnext/hr/doctype/payroll_entry/payroll_entry.js
@@ -37,7 +37,7 @@
 		if (!slip_status.draft && !slip_status.submitted) {
 			return;
 		} else {
-			frm.add_custom_button("View Salary Slips",
+			frm.add_custom_button(__("View Salary Slips"),
 				function() {
 					frappe.set_route(
 						'List', 'Salary Slip', {posting_date: frm.doc.posting_date}
@@ -47,13 +47,11 @@
 		}
 
 		if (slip_status.draft) {
-			frm.add_custom_button("Submit Salary Slip",
+			frm.add_custom_button(__("Submit Salary Slip"),
 				function() {
 					submit_salary_slip(frm);
-				},
-				__('Make')
-			);
-			frm.page.set_inner_btn_group_as_primary(__('Make'));
+				}
+			).addClass("btn-primary");
 		}
 	},
 
@@ -182,7 +180,7 @@
 // Submit salary slips
 
 const submit_salary_slip = function (frm) {
-	frappe.confirm(__('This will create a Journal Entry. Do you want to proceed?'),
+	frappe.confirm(__('This will submit Salary Slips and create accrual Journal Entry. Do you want to proceed?'),
 		function() {
 			frappe.call({
 				method: 'submit_salary_slips',
@@ -190,7 +188,7 @@
 				callback: function() {frm.events.refresh(frm);},
 				doc: frm.doc,
 				freeze: true,
-				freeze_message: 'Creating Journal Entries...'
+				freeze_message: 'Submitting Salary Slips and creating Journal Entry...'
 			});
 		},
 		function() {
diff --git a/erpnext/hr/doctype/payroll_entry/test_payroll_entry.js b/erpnext/hr/doctype/payroll_entry/test_payroll_entry.js
index 05cd66f..d24f243 100644
--- a/erpnext/hr/doctype/payroll_entry/test_payroll_entry.js
+++ b/erpnext/hr/doctype/payroll_entry/test_payroll_entry.js
@@ -30,7 +30,7 @@
 		() => frappe.click_button('Submit'),
 		() => frappe.timeout(1),
 		() => frappe.click_button('Yes'),
-		() => frappe.timeout(2),
+		() => frappe.timeout(5),
 
 		() => frappe.click_button('View Salary Slip'),
 		() => frappe.timeout(2),
@@ -38,8 +38,8 @@
 
 		() => frappe.set_route('Form', 'Payroll Entry', docname),
 		() => frappe.timeout(2),
-		() => frappe.click_button('Make'),
-		() => frappe.click_dropdown_item('Submit Salary Slip'),
+		() => frappe.click_button('Submit Salary Slip'),
+		() => frappe.click_button('Yes'),
 		() => frappe.timeout(5),
 
 		() => frappe.click_button('Close'),
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index 3062efc..848f46e 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -225,6 +225,9 @@
 
 			valuation_rate = flt(last_valuation_rate[0][0]) if last_valuation_rate else 0
 
+		if not valuation_rate:
+			valuation_rate = frappe.db.get_value("Item", args['item_code'], "valuation_rate")
+
 		return valuation_rate
 
 	def manage_default_bom(self):
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 530cc5c..9a7ec7c 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -440,7 +440,7 @@
 erpnext.patches.v8_7.fix_purchase_receipt_status
 erpnext.patches.v8_6.rename_bom_update_tool
 erpnext.patches.v8_7.set_offline_in_pos_settings #11-09-17
-erpnext.patches.v8_9.add_setup_progress_actions #08-09-2017 #26-09-2017 #22-11-2017
+erpnext.patches.v8_9.add_setup_progress_actions #08-09-2017 #26-09-2017 #22-11-2017 #15-12-2017
 erpnext.patches.v8_9.rename_company_sales_target_field
 erpnext.patches.v8_8.set_bom_rate_as_per_uom
 erpnext.patches.v8_8.add_new_fields_in_accounts_settings
@@ -463,7 +463,6 @@
 erpnext.patches.v9_0.set_pos_profile_name
 erpnext.patches.v9_0.remove_non_existing_warehouse_from_stock_settings
 execute:frappe.delete_doc_if_exists("DocType", "Program Fee")
-erpnext.patches.v8_10.update_gl_due_date_for_pi_and_si
 erpnext.patches.v8_10.change_default_customer_credit_days
 erpnext.patches.v9_0.update_employee_loan_details
 erpnext.patches.v9_2.delete_healthcare_domain_default_items
@@ -482,3 +481,8 @@
 erpnext.patches.v10_0.setup_vat_for_uae_and_saudi_arabia
 erpnext.patches.v10_0.set_primary_contact_for_customer
 erpnext.patches.v10_0.copy_projects_renamed_fields
+erpnext.patches.v10_0.enabled_regional_print_format_based_on_country
+erpnext.patches.v10_0.update_asset_calculate_depreciation
+erpnext.patches.v10_0.enabled_regional_print_format_based_on_country
+erpnext.patches.v10_0.update_asset_calculate_depreciation
+erpnext.patches.v10_0.update_due_date_in_gle_and_payment_entries
diff --git a/erpnext/patches/v10_0/enabled_regional_print_format_based_on_country.py b/erpnext/patches/v10_0/enabled_regional_print_format_based_on_country.py
new file mode 100644
index 0000000..37e6707
--- /dev/null
+++ b/erpnext/patches/v10_0/enabled_regional_print_format_based_on_country.py
@@ -0,0 +1,22 @@
+# Copyright (c) 2017, Frappe and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+	print_format_mapper = {
+		'India': ['GST POS Invoice', 'GST Tax Invoice'],
+		'Saudi Arabia': ['Simplified Tax Invoice', 'Detailed Tax Invoice'],
+		'United Arab Emirates': ['Simplified Tax Invoice', 'Detailed Tax Invoice']
+	}
+
+	frappe.db.sql(""" update `tabPrint Format` set disabled = 1 where name
+		in ('GST POS Invoice', 'GST Tax Invoice', 'Simplified Tax Invoice', 'Detailed Tax Invoice')""")
+
+	for d in frappe.get_all('Company', fields = ["country"],
+		filters={'country': ('in', ['India', 'Saudi Arabia', 'United Arab Emirates'])}):
+		if print_format_mapper.get(d.country):
+			print_formats = print_format_mapper.get(d.country)
+			frappe.db.sql(""" update `tabPrint Format` set disabled = 0
+				where name in (%s)""" % ", ".join(["%s"]*len(print_formats)), tuple(print_formats))
\ No newline at end of file
diff --git a/erpnext/patches/v10_0/update_asset_calculate_depreciation.py b/erpnext/patches/v10_0/update_asset_calculate_depreciation.py
new file mode 100644
index 0000000..44b8c7f
--- /dev/null
+++ b/erpnext/patches/v10_0/update_asset_calculate_depreciation.py
@@ -0,0 +1,11 @@
+import frappe
+
+def execute():
+	frappe.reload_doc('assets', 'doctype', 'asset')
+	frappe.reload_doc('assets', 'doctype', 'depreciation_schedule')
+
+	frappe.db.sql("""
+		update tabAsset a
+		set calculate_depreciation = 1
+		where exists(select ds.name from `tabDepreciation Schedule` ds where ds.parent=a.name)
+	""")
\ No newline at end of file
diff --git a/erpnext/patches/v10_0/update_due_date_in_gle_and_payment_entries.py b/erpnext/patches/v10_0/update_due_date_in_gle_and_payment_entries.py
new file mode 100644
index 0000000..268b843
--- /dev/null
+++ b/erpnext/patches/v10_0/update_due_date_in_gle_and_payment_entries.py
@@ -0,0 +1,100 @@
+from __future__ import unicode_literals
+import frappe
+from frappe.utils import update_progress_bar
+
+def execute():
+	frappe.reload_doc("accounts", "doctype", "gl_entry")
+	frappe.reload_doc("accounts", "doctype", "payment_entry_reference")
+	frappe.reload_doc("accounts", "doctype", "journal_entry_account")
+	
+	print "Updating Due Date in GL Entry, Journal Entry and Payment Entry"
+	for doctype in ("Sales Invoice", "Purchase Invoice"):
+		invoice_due_dates = frappe.db.sql("""select name, due_date from `tab{0}`
+			where docstatus=1 order by name""".format(doctype))
+
+		# update gle
+		count = 0
+		total_count = len(invoice_due_dates)
+		batch_size = 1000
+		
+		while(count < total_count):
+			update_progress_bar("Based on {0}".format(doctype), count, total_count)
+			sub_set = invoice_due_dates[count:count+batch_size]
+			invoices = [d[0] for d in sub_set]
+
+			update_gl_entries(doctype, invoices, sub_set)
+			update_payment_entries(doctype, invoices, sub_set)
+		
+			count += batch_size
+
+def update_gl_entries(doctype, invoices, invoice_due_dates):
+	when_then = get_when_then_for_gle(doctype, invoice_due_dates)
+
+	frappe.db.sql("""
+		UPDATE `tabGL Entry`
+		SET due_date = CASE
+			%s
+			ELSE `due_date` END
+		WHERE
+			(
+				(voucher_type = %s and voucher_no in (%s))
+				or (voucher_type in ('Journal Entry', 'Payment Entry')
+					and against_voucher in (%s))
+			)
+			and ifnull(party, '') != ''
+			and ifnull(due_date, '') = ''
+	""" % (when_then, '%s', ', '.join(['%s']*len(invoices)), ', '.join(['%s']*len(invoices))),
+		tuple([doctype] + invoices + invoices))
+
+def get_when_then_for_gle(doctype, data):
+	cond = ""
+	for d in data:
+		cond += """
+		 	WHEN (
+				(voucher_type = '{voucher_type}' and voucher_no = '{voucher_no}')
+				or (voucher_type in ('Journal Entry', 'Payment Entry')
+					and against_voucher = '{voucher_no}')
+			) THEN '{date}'
+		""".format(voucher_type=doctype, voucher_no=frappe.db.escape(d[0]), date=d[1])
+
+	return cond
+
+def update_payment_entries(ref_doctype, invoices, invoice_due_dates):
+	for d in (
+		("Payment Entry Reference", "reference_doctype", "due_date"),
+		("Journal Entry Account", "reference_type", "reference_due_date")):
+
+		when_then = get_when_then_for_payment_entries(ref_doctype, d[1], invoice_due_dates)
+
+		frappe.db.sql("""
+			UPDATE `tab{doctype}`
+			SET {due_date_field} = CASE
+				{when_then}
+				ELSE `{due_date_field}` END
+			WHERE
+				{ref_doctype_fieldname} = '{ref_doctype}'
+				and reference_name in ({reference_names})
+				and ifnull({due_date_field}, '') = ''
+		""".format(
+			doctype = d[0],
+			due_date_field = d[2],
+			when_then = when_then,
+			ref_doctype_fieldname = d[1],
+			ref_doctype = ref_doctype,
+			reference_names = ', '.join(['%s']*len(invoices))
+		), tuple(invoices))
+
+def get_when_then_for_payment_entries(ref_doctype, ref_doctype_fieldname, data):
+	cond = ""
+	for d in data:
+		cond += """
+		 	WHEN {ref_doctype_fieldname} = '{ref_doctype}'
+				and reference_name = '{voucher_no}'
+			THEN '{date}'
+		""".format(
+			ref_doctype_fieldname=ref_doctype_fieldname,
+			ref_doctype=ref_doctype,
+			voucher_no=frappe.db.escape(d[0]),
+			date=d[1])
+
+	return cond
\ No newline at end of file
diff --git a/erpnext/patches/v8_0/create_domain_docs.py b/erpnext/patches/v8_0/create_domain_docs.py
index cdd3117..4710287 100644
--- a/erpnext/patches/v8_0/create_domain_docs.py
+++ b/erpnext/patches/v8_0/create_domain_docs.py
@@ -10,6 +10,7 @@
 	frappe.reload_doc("core", "doctype", "domain")
 	frappe.reload_doc("core", "doctype", "domain_settings")
 	frappe.reload_doc("core", "doctype", "has_domain")
+	frappe.reload_doc("core", "doctype", "role")
 
 	for domain in ("Distribution", "Manufacturing", "Retail", "Services", "Education"):
 		if not frappe.db.exists({"doctype": "Domain", "domain": domain}):
diff --git a/erpnext/patches/v8_1/setup_gst_india.py b/erpnext/patches/v8_1/setup_gst_india.py
index f329916..a9133ae 100644
--- a/erpnext/patches/v8_1/setup_gst_india.py
+++ b/erpnext/patches/v8_1/setup_gst_india.py
@@ -4,6 +4,9 @@
 def execute():
 	frappe.reload_doc('stock', 'doctype', 'item')
 	frappe.reload_doc("stock", "doctype", "customs_tariff_number")
+	frappe.reload_doc("hub_node", "doctype", "hub_category")
+	frappe.reload_doc("accounts", "doctype", "payment_terms_template")
+	frappe.reload_doc("accounts", "doctype", "payment_schedule")
 
 	company = frappe.get_all('Company', filters = {'country': 'India'})
 	if not company:
diff --git a/erpnext/patches/v8_10/update_gl_due_date_for_pi_and_si.py b/erpnext/patches/v8_10/update_gl_due_date_for_pi_and_si.py
deleted file mode 100644
index 8596e66..0000000
--- a/erpnext/patches/v8_10/update_gl_due_date_for_pi_and_si.py
+++ /dev/null
@@ -1,138 +0,0 @@
-from __future__ import unicode_literals
-import frappe
-
-# This will update existing GL Entries by saving its linked Purchase/Sales Invoice's
-# Journal Entry's due date as the due date for the GL Entry
-
-
-def execute():
-	frappe.reload_doc("accounts", "doctype", "gl_entry")
-
-	kwargs = get_query_kwargs()
-
-	for kwarg in kwargs:
-		for batch in get_result_in_batches(**kwarg):
-			voucher_num_col = kwarg.get('voucher_num_col', 'voucher_no')
-			voucher_type = kwarg.get('use_voucher_type') or kwarg.get('voucher_type')
-			conditions, names = build_conditions(batch, voucher_type, voucher_num_col)
-			if conditions and names:
-				start = 'UPDATE `tabGL Entry` SET `due_date` = CASE '
-				cond = ' '.join(conditions)
-				else_cond = ' ELSE `due_date` END WHERE '
-
-				frappe.db.sql(
-					start + cond + else_cond + voucher_num_col + ' IN %s',
-					values=(names,)
-				)
-
-
-def get_result_in_batches(**kwargs):
-	"""A simple generator to yield slices of GL Entry records"""
-	while True:
-		batch = get_gle_batch(**kwargs)
-		if batch:
-			yield batch
-		else:
-			return
-
-
-def get_gle_batch(**kwargs):
-	"""Returns a slice of records in GL Entry"""
-	doctype = kwargs.get('doctype')
-	fields = kwargs.get('fields')
-	limit_start = kwargs.get('limit_start')
-	limit_page_length = kwargs.get('limit_page_length')
-	filters = kwargs.get('filters')
-	or_filters = kwargs.get('or_filters')
-
-	results = frappe.get_list(
-		doctype, fields=fields, limit_start=limit_start, limit_page_length=limit_page_length,
-		filters=filters, or_filters=or_filters
-	)
-
-	return results
-
-
-def build_conditions(query_results, voucher_type, voucher_num_col):
-	"""
-	builds the string to be used is sql CASE statement. Returns the a tuple of
-	the string for the CASE statement and a tuple of applicable voucher names
-	"""
-	conditions = []
-	invoice_names = []
-
-	for result in query_results:
-		voucher_no = result.get(voucher_num_col)
-		if voucher_no:
-			invoice_names.append("%s" % (voucher_no,))
-
-	# get invoice details
-	invoice_details = frappe.get_list(
-		voucher_type, fields=['name', 'due_date'], filters={'name': ('in', invoice_names)}
-	)
-
-	if invoice_details:
-		for d in invoice_details:
-			conditions.append('WHEN `{voucher_no}`="{number}" THEN "{date}"'.format(
-				number=d.name, date=d.due_date, voucher_no=voucher_num_col))
-
-	return conditions, invoice_names
-
-
-def get_query_kwargs():
-	pi_kwargs = dict(
-		voucher_type='Purchase Invoice', doctype='GL Entry', fields=['voucher_no'],
-		limit_start=0, limit_page_length=5, filters={
-			"ifnull(due_date, '')": ('=', ''), "ifnull(party, '')": ('!=', ''),
-			'voucher_type': 'Purchase Invoice', 'credit': ('!=', '0')
-		}
-	)
-
-	si_kwargs = dict(
-		voucher_type='Sales Invoice', doctype='GL Entry', fields=['voucher_no'],
-		limit_start=0, limit_page_length=5, filters={
-			"ifnull(due_date, '')": ('=', ''), "ifnull(party, '')": ('!=', ''),
-			'voucher_type': 'Sales Invoice', 'debit': ('!=', '0')
-		}
-	)
-
-	journal_kwargs_si = dict(
-		voucher_type='Journal Entry', doctype='GL Entry', fields=['against_voucher'],
-		limit_start=0, limit_page_length=5, filters={
-			"ifnull(due_date, '')": ('=', ''), "ifnull(party, '')": ('!=', ''),
-			'voucher_type': 'Journal Entry', 'against_voucher_type': 'Sales Invoice'
-		},
-		voucher_num_col='against_voucher', use_voucher_type='Sales Invoice',
-	)
-
-	journal_kwargs_pi = dict(
-		voucher_type='Journal Entry', doctype='GL Entry', fields=['against_voucher'],
-		limit_start=0, limit_page_length=5, filters={
-			"ifnull(due_date, '')": ('=', ''), "ifnull(party, '')": ('!=', ''),
-			'voucher_type': 'Journal Entry', 'against_voucher_type': 'Purchase Invoice'
-		},
-		voucher_num_col='against_voucher', use_voucher_type='Purchase Invoice',
-	)
-
-	payment_entry_kwargs_pi = dict(
-		voucher_type='Payment Entry', doctype='GL Entry', fields=['against_voucher'],
-		limit_start=0, limit_page_length=5, filters={
-			"ifnull(due_date, '')": ('=', ''), "ifnull(party, '')": ('!=', ''),
-			'voucher_type': 'Payment Entry', 'against_voucher_type': 'Purchase Invoice'
-		},
-		voucher_num_col='against_voucher', use_voucher_type='Purchase Invoice',
-	)
-
-	payment_entry_kwargs_si = dict(
-		voucher_type='Payment Entry', doctype='GL Entry', fields=['against_voucher'],
-		limit_start=0, limit_page_length=5, filters={
-			"ifnull(due_date, '')": ('=', ''), "ifnull(party, '')": ('!=', ''),
-			'voucher_type': 'Payment Entry', 'against_voucher_type': 'Sales Invoice'
-		},
-		voucher_num_col='against_voucher', use_voucher_type='Sales Invoice',
-	)
-
-	return [
-		pi_kwargs, si_kwargs, journal_kwargs_pi, journal_kwargs_si,
-		payment_entry_kwargs_pi, payment_entry_kwargs_si
-	]
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 5cb1973..f1d274d 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -243,10 +243,14 @@
 						frappe.run_serially([
 							() => {
 								// directly set in doc, so as not to call triggers
-								me.frm.doc.taxes_and_charges = r.message.taxes_and_charges;
+								if(r.message.taxes_and_charges) {
+									me.frm.doc.taxes_and_charges = r.message.taxes_and_charges;
+								}
 
 								// set taxes table
-								me.frm.set_value("taxes", r.message.taxes);
+								if(r.message.taxes) {
+									me.frm.set_value("taxes", r.message.taxes);
+								}
 							},
 							() => me.calculate_taxes_and_totals()
 						]);
diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py
index 68a52cc..4ef9b11 100644
--- a/erpnext/regional/india/setup.py
+++ b/erpnext/regional/india/setup.py
@@ -76,6 +76,10 @@
 
 def add_print_formats():
 	frappe.reload_doc("regional", "print_format", "gst_tax_invoice")
+	frappe.reload_doc("accounts", "print_format", "gst_pos_invoice")
+
+	frappe.db.sql(""" update `tabPrint Format` set disabled = 0 where
+		name in('GST POS Invoice', 'GST Tax Invoice') """)
 
 def make_custom_fields():
 	hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC',
diff --git a/erpnext/regional/print_format/detailed_tax_invoice/detailed_tax_invoice.json b/erpnext/regional/print_format/detailed_tax_invoice/detailed_tax_invoice.json
index d5f63f4..b90520b 100644
--- a/erpnext/regional/print_format/detailed_tax_invoice/detailed_tax_invoice.json
+++ b/erpnext/regional/print_format/detailed_tax_invoice/detailed_tax_invoice.json
@@ -2,15 +2,15 @@
  "align_labels_right": 0, 
  "creation": "2017-12-07 16:26:06.648472", 
  "custom_format": 0, 
- "disabled": 0, 
+ "disabled": 1, 
  "doc_type": "Sales Invoice", 
  "docstatus": 0, 
  "doctype": "Print Format", 
  "font": "Default", 
- "format_data": "[{\"fieldname\": \"print_heading_template\", \"fieldtype\": \"Custom HTML\", \"options\": \"<div class=\\\"print-heading\\\">\\t\\t\\t\\t<h2>TAX Invoice<br><small>{{ doc.name }}</small>\\t\\t\\t\\t</h2></div>\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"customer_name\", \"label\": \"Customer Name\"}, {\"print_hide\": 0, \"fieldname\": \"customer_name_in_arabic\", \"label\": \"Customer Name in Arabic\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"posting_date\", \"label\": \"Date\"}, {\"print_hide\": 0, \"fieldname\": \"project\", \"align\": \"left\", \"label\": \"Reverse Charge Applicable\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Address\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"address_display\", \"label\": \"Address\"}, {\"print_hide\": 0, \"fieldname\": \"tax_id\", \"label\": \"Tax Id\"}, {\"print_hide\": 0, \"fieldname\": \"contact_display\", \"label\": \"Contact\"}, {\"print_hide\": 0, \"fieldname\": \"contact_mobile\", \"label\": \"Mobile No\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"company\", \"label\": \"Company\"}, {\"print_hide\": 0, \"fieldname\": \"company_address_display\", \"label\": \"Company Address\"}, {\"print_hide\": 0, \"fieldname\": \"company_trn\", \"label\": \"Company TRN\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"visible_columns\": [{\"print_hide\": 0, \"fieldname\": \"item_code\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"description\", \"print_width\": \"200px\"}, {\"print_hide\": 0, \"fieldname\": \"image\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"qty\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"uom\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"rate\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"tax_code\", \"print_width\": \"\"}], \"print_hide\": 0, \"fieldname\": \"items\", \"label\": \"Items\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"total\", \"label\": \"Total\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"visible_columns\": [{\"print_hide\": 0, \"fieldname\": \"charge_type\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"row_id\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"account_head\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"cost_center\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"description\", \"print_width\": \"300px\"}, {\"print_hide\": 0, \"fieldname\": \"rate\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"tax_amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"total\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"tax_amount_after_discount_amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"base_tax_amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"base_total\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"base_tax_amount_after_discount_amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"item_wise_tax_detail\", \"print_width\": \"\"}], \"print_hide\": 0, \"fieldname\": \"taxes\", \"label\": \"Sales Taxes and Charges\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"grand_total\", \"label\": \"Grand Total\"}, {\"print_hide\": 0, \"fieldname\": \"rounded_total\", \"label\": \"Rounded Total\"}, {\"print_hide\": 0, \"fieldname\": \"in_words\", \"align\": \"left\", \"label\": \"In Words\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"other_charges_calculation\", \"label\": \"Taxes and Charges Calculation\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Terms\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"terms\", \"label\": \"Terms and Conditions Details\"}]", 
+ "format_data": "[{\"fieldname\": \"print_heading_template\", \"fieldtype\": \"Custom HTML\", \"options\": \"<div class=\\\"print-heading\\\">\\t\\t\\t\\t<h2>TAX Invoice<br><small>{{ doc.name }}</small>\\t\\t\\t\\t</h2></div>\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"customer_name\", \"label\": \"Customer Name\"}, {\"print_hide\": 0, \"fieldname\": \"customer_name_in_arabic\", \"label\": \"Customer Name in Arabic\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"posting_date\", \"label\": \"Date\"}, {\"print_hide\": 0, \"fieldname\": \"project\", \"align\": \"left\", \"label\": \"Reverse Charge Applicable\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Address\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"address_display\", \"label\": \"Address\"}, {\"print_hide\": 0, \"fieldname\": \"tax_id\", \"label\": \"Tax Id\"}, {\"print_hide\": 0, \"fieldname\": \"contact_display\", \"label\": \"Contact\"}, {\"print_hide\": 0, \"fieldname\": \"contact_mobile\", \"label\": \"Mobile No\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"company\", \"label\": \"Company\"}, {\"print_hide\": 0, \"fieldname\": \"company_address_display\", \"label\": \"Company Address\"}, {\"print_hide\": 0, \"fieldname\": \"company_trn\", \"label\": \"Company TRN\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"visible_columns\": [{\"print_hide\": 0, \"fieldname\": \"item_code\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"description\", \"print_width\": \"200px\"}, {\"print_hide\": 0, \"fieldname\": \"image\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"qty\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"uom\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"rate\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"tax_code\", \"print_width\": \"\"}], \"print_hide\": 0, \"fieldname\": \"items\", \"label\": \"Items\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"total\", \"label\": \"Total\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"visible_columns\": [{\"print_hide\": 0, \"fieldname\": \"charge_type\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"row_id\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"account_head\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"cost_center\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"description\", \"print_width\": \"300px\"}, {\"print_hide\": 0, \"fieldname\": \"rate\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"tax_amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"total\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"tax_amount_after_discount_amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"base_tax_amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"base_total\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"base_tax_amount_after_discount_amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"item_wise_tax_detail\", \"print_width\": \"\"}], \"print_hide\": 0, \"fieldname\": \"taxes\", \"label\": \"Sales Taxes and Charges\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"grand_total\", \"label\": \"Grand Total\"}, {\"print_hide\": 0, \"fieldname\": \"rounded_total\", \"label\": \"Rounded Total\"}, {\"print_hide\": 0, \"fieldname\": \"in_words\", \"align\": \"left\", \"label\": \"Tax Breakup\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"other_charges_calculation\", \"label\": \"Taxes and Charges Calculation\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Terms\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"terms\", \"label\": \"Terms and Conditions Details\"}]", 
  "idx": 0, 
  "line_breaks": 0, 
- "modified": "2017-12-11 12:16:02.774997", 
+ "modified": "2017-12-15 11:57:16.661876", 
  "modified_by": "Administrator", 
  "module": "Regional", 
  "name": "Detailed Tax Invoice", 
@@ -19,4 +19,4 @@
  "print_format_type": "Server", 
  "show_section_headings": 0, 
  "standard": "Yes"
-}
+}
\ No newline at end of file
diff --git a/erpnext/regional/print_format/gst_tax_invoice/gst_tax_invoice.json b/erpnext/regional/print_format/gst_tax_invoice/gst_tax_invoice.json
index 55d870f..7d8e675 100644
--- a/erpnext/regional/print_format/gst_tax_invoice/gst_tax_invoice.json
+++ b/erpnext/regional/print_format/gst_tax_invoice/gst_tax_invoice.json
@@ -2,15 +2,15 @@
  "align_labels_right": 0, 
  "creation": "2017-07-04 16:26:21.120187", 
  "custom_format": 0, 
- "disabled": 0, 
+ "disabled": 1, 
  "doc_type": "Sales Invoice", 
  "docstatus": 0, 
  "doctype": "Print Format", 
  "font": "Default", 
- "format_data": "[{\"fieldname\": \"print_heading_template\", \"fieldtype\": \"Custom HTML\", \"options\": \"<div class=\\\"print-heading\\\">\\n\\t<h2>\\n\\t\\tTAX INVOICE<br>\\n\\t\\t<small>{{ doc.name }}</small>\\n\\t</h2>\\n</div>\\n<h2 class=\\\"text-center\\\">\\n\\t{% if doc.invoice_copy -%}\\n\\t\\t<small>{{ doc.invoice_copy }}</small>\\n\\t{% endif -%}\\n</h2>\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"company\", \"label\": \"Company\"}, {\"print_hide\": 0, \"fieldname\": \"company_address_display\", \"label\": \"Company Address\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"posting_date\", \"label\": \"Date\"}, {\"print_hide\": 0, \"fieldname\": \"due_date\", \"label\": \"Payment Due Date\"}, {\"print_hide\": 0, \"fieldname\": \"reverse_charge\", \"label\": \"Reverse Charge\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"options\": \"<hr>\", \"fieldname\": \"_custom_html\", \"fieldtype\": \"HTML\", \"label\": \"Custom HTML\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Address\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"customer_name\", \"label\": \"Customer Name\"}, {\"print_hide\": 0, \"fieldname\": \"address_display\", \"label\": \"Address\"}, {\"print_hide\": 0, \"fieldname\": \"contact_display\", \"label\": \"Contact\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"shipping_address\", \"label\": \"Shipping Address\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"visible_columns\": [{\"print_hide\": 0, \"fieldname\": \"item_code\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"description\", \"print_width\": \"200px\"}, {\"print_hide\": 0, \"fieldname\": \"gst_hsn_code\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"serial_no\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"qty\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"uom\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"rate\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"amount\", \"print_width\": \"\"}], \"print_hide\": 0, \"fieldname\": \"items\", \"label\": \"Items\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"total\", \"label\": \"Total\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"visible_columns\": [{\"print_hide\": 0, \"fieldname\": \"description\", \"print_width\": \"300px\"}], \"print_hide\": 0, \"fieldname\": \"taxes\", \"label\": \"Sales Taxes and Charges\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"grand_total\", \"label\": \"Grand Total\"}, {\"print_hide\": 0, \"fieldname\": \"rounded_total\", \"label\": \"Rounded Total\"}, {\"print_hide\": 0, \"fieldname\": \"in_words\", \"label\": \"In Words\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"other_charges_calculation\", \"align\": \"left\", \"label\": \"Tax Breakup\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Terms\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"terms\", \"label\": \"Terms and Conditions Details\"}]", 
+ "format_data": "[{\"fieldname\": \"print_heading_template\", \"fieldtype\": \"Custom HTML\", \"options\": \"<div class=\\\"print-heading\\\">\\n\\t<h2>\\n\\t\\tTAX INVOICE<br>\\n\\t\\t<small>{{ doc.name }}</small>\\n\\t</h2>\\n</div>\\n<h2 class=\\\"text-center\\\">\\n\\t{% if doc.invoice_copy -%}\\n\\t\\t<small>{{ doc.invoice_copy }}</small>\\n\\t{% endif -%}\\n</h2>\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"company\", \"label\": \"Company\"}, {\"print_hide\": 0, \"fieldname\": \"company_address_display\", \"label\": \"Company Address\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"posting_date\", \"label\": \"Date\"}, {\"print_hide\": 0, \"fieldname\": \"due_date\", \"label\": \"Payment Due Date\"}, {\"print_hide\": 0, \"fieldname\": \"reverse_charge\", \"label\": \"Reverse Charge\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"label\": \"Custom HTML\", \"fieldname\": \"_custom_html\", \"options\": \"<hr>\", \"fieldtype\": \"HTML\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Address\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"customer_name\", \"label\": \"Customer Name\"}, {\"print_hide\": 0, \"fieldname\": \"address_display\", \"label\": \"Address\"}, {\"print_hide\": 0, \"fieldname\": \"contact_display\", \"label\": \"Contact\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"shipping_address\", \"label\": \"Shipping Address\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"visible_columns\": [{\"print_hide\": 0, \"fieldname\": \"item_code\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"description\", \"print_width\": \"200px\"}, {\"print_hide\": 0, \"fieldname\": \"gst_hsn_code\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"serial_no\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"qty\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"uom\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"rate\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"amount\", \"print_width\": \"\"}], \"print_hide\": 0, \"fieldname\": \"items\", \"label\": \"Items\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"total\", \"label\": \"Total\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"visible_columns\": [{\"print_hide\": 0, \"fieldname\": \"description\", \"print_width\": \"300px\"}], \"print_hide\": 0, \"fieldname\": \"taxes\", \"label\": \"Sales Taxes and Charges\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"grand_total\", \"label\": \"Grand Total\"}, {\"print_hide\": 0, \"fieldname\": \"rounded_total\", \"label\": \"Rounded Total\"}, {\"print_hide\": 0, \"fieldname\": \"in_words\", \"label\": \"In Words\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"other_charges_calculation\", \"align\": \"left\", \"label\": \"Tax Breakup\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Terms\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"terms\", \"label\": \"Terms and Conditions Details\"}]", 
  "idx": 0, 
  "line_breaks": 0, 
- "modified": "2017-09-11 14:56:25.303797", 
+ "modified": "2017-12-15 11:57:25.477278", 
  "modified_by": "Administrator", 
  "module": "Regional", 
  "name": "GST Tax Invoice", 
diff --git a/erpnext/regional/print_format/simplified_tax_invoice/simplified_tax_invoice.json b/erpnext/regional/print_format/simplified_tax_invoice/simplified_tax_invoice.json
index 9609b87..b324f6e 100644
--- a/erpnext/regional/print_format/simplified_tax_invoice/simplified_tax_invoice.json
+++ b/erpnext/regional/print_format/simplified_tax_invoice/simplified_tax_invoice.json
@@ -2,7 +2,7 @@
  "align_labels_right": 0, 
  "creation": "2017-12-07 16:09:44.321242", 
  "custom_format": 0, 
- "disabled": 0, 
+ "disabled": 1, 
  "doc_type": "Sales Invoice", 
  "docstatus": 0, 
  "doctype": "Print Format", 
@@ -10,7 +10,7 @@
  "format_data": "[{\"fieldname\": \"print_heading_template\", \"fieldtype\": \"Custom HTML\", \"options\": \"<div class=\\\"print-heading\\\">\\t\\t\\t\\t<h2>TAX Invoice<br><small>{{ doc.name }}</small>\\t\\t\\t\\t</h2></div>\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"customer_name\", \"label\": \"Customer Name\"}, {\"print_hide\": 0, \"fieldname\": \"customer_name_in_arabic\", \"label\": \"Customer Name in Arabic\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"posting_date\", \"label\": \"Date\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Address\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"company\", \"label\": \"Company\"}, {\"print_hide\": 0, \"fieldname\": \"company_trn\", \"label\": \"Company TRN\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"company_address_display\", \"label\": \"Company Address\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"visible_columns\": [{\"print_hide\": 0, \"fieldname\": \"item_code\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"description\", \"print_width\": \"200px\"}, {\"print_hide\": 0, \"fieldname\": \"uom\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"tax_code\", \"print_width\": \"\"}], \"print_hide\": 0, \"fieldname\": \"items\", \"label\": \"Items\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"total\", \"label\": \"Total\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"visible_columns\": [{\"print_hide\": 0, \"fieldname\": \"charge_type\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"row_id\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"account_head\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"cost_center\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"description\", \"print_width\": \"300px\"}, {\"print_hide\": 0, \"fieldname\": \"rate\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"tax_amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"total\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"tax_amount_after_discount_amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"base_tax_amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"base_total\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"base_tax_amount_after_discount_amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"item_wise_tax_detail\", \"print_width\": \"\"}], \"print_hide\": 0, \"fieldname\": \"taxes\", \"label\": \"Sales Taxes and Charges\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"grand_total\", \"label\": \"Grand Total\"}, {\"print_hide\": 0, \"fieldname\": \"rounded_total\", \"label\": \"Rounded Total\"}, {\"print_hide\": 0, \"fieldname\": \"in_words\", \"align\": \"left\", \"label\": \"In Words\"}]", 
  "idx": 0, 
  "line_breaks": 0, 
- "modified": "2017-12-11 12:32:00.136741", 
+ "modified": "2017-12-15 11:57:20.498724", 
  "modified_by": "Administrator", 
  "module": "Regional", 
  "name": "Simplified Tax Invoice", 
diff --git a/erpnext/regional/united_arab_emirates/setup.py b/erpnext/regional/united_arab_emirates/setup.py
index b1b3cc7..936e0f7 100644
--- a/erpnext/regional/united_arab_emirates/setup.py
+++ b/erpnext/regional/united_arab_emirates/setup.py
@@ -71,3 +71,6 @@
 def add_print_formats():
 	frappe.reload_doc("regional", "print_format", "detailed_tax_invoice")
 	frappe.reload_doc("regional", "print_format", "simplified_tax_invoice")
+
+	frappe.db.sql(""" update `tabPrint Format` set disabled = 0 where
+		name in('Simplified Tax Invoice', 'Detailed Tax Invoice') """)
diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.js b/erpnext/selling/page/point_of_sale/point_of_sale.js
index 2e690ec..a058fdf 100644
--- a/erpnext/selling/page/point_of_sale/point_of_sale.js
+++ b/erpnext/selling/page/point_of_sale/point_of_sale.js
@@ -193,9 +193,10 @@
 		// add to cur_frm
 		const item = this.frm.add_child('items', args);
 		frappe.flags.hide_serial_batch_dialog = true;
-		this.frm.script_manager
-			.trigger('item_code', item.doctype, item.name)
-			.then(() => {
+
+		frappe.run_serially([
+			() => this.frm.script_manager.trigger('item_code', item.doctype, item.name),
+			() => {
 				const show_dialog = item.has_serial_no || item.has_batch_no;
 
 				// if actual_batch_qty and actual_qty if then there is only one batch. In such
@@ -208,7 +209,8 @@
 					// update cart
 					this.update_cart_data(item);
 				}
-			});
+			}
+		]);
 	}
 
 	select_batch_and_serial_no(item) {
@@ -672,6 +674,11 @@
 				fieldname: 'customer',
 				options: 'Customer',
 				reqd: 1,
+				get_query: function() {
+					return {
+						query: 'erpnext.controllers.queries.customer_query'
+					}
+				},
 				onchange: () => {
 					this.events.on_customer_change(this.customer_field.get_value());
 				}
diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py
index cebcd34..0a8d504 100644
--- a/erpnext/setup/doctype/company/company.py
+++ b/erpnext/setup/doctype/company/company.py
@@ -102,19 +102,16 @@
 			{"warehouse_name": _("Finished Goods"), "is_group": 0}]:
 
 			if not frappe.db.exists("Warehouse", "{0} - {1}".format(wh_detail["warehouse_name"], self.abbr)):
-				stock_group = frappe.db.get_value("Account", {"account_type": "Stock",
-					"is_group": 1, "company": self.name})
-				if stock_group:
-					warehouse = frappe.get_doc({
-						"doctype":"Warehouse",
-						"warehouse_name": wh_detail["warehouse_name"],
-						"is_group": wh_detail["is_group"],
-						"company": self.name,
-						"parent_warehouse": "{0} - {1}".format(_("All Warehouses"), self.abbr) \
-							if not wh_detail["is_group"] else ""
-					})
-					warehouse.flags.ignore_permissions = True
-					warehouse.insert()
+				warehouse = frappe.get_doc({
+					"doctype":"Warehouse",
+					"warehouse_name": wh_detail["warehouse_name"],
+					"is_group": wh_detail["is_group"],
+					"company": self.name,
+					"parent_warehouse": "{0} - {1}".format(_("All Warehouses"), self.abbr) \
+						if not wh_detail["is_group"] else ""
+				})
+				warehouse.flags.ignore_permissions = True
+				warehouse.insert()
 
 	def create_default_accounts(self):
 		from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import create_charts
diff --git a/erpnext/stock/doctype/material_request_item/material_request_item.json b/erpnext/stock/doctype/material_request_item/material_request_item.json
index 3434b4d..ef2e7fc 100644
--- a/erpnext/stock/doctype/material_request_item/material_request_item.json
+++ b/erpnext/stock/doctype/material_request_item/material_request_item.json
@@ -360,34 +360,6 @@
   {
    "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "col_break2", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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
-  }, 
-  {
-   "allow_bulk_edit": 0, 
-   "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
    "columns": 2, 
@@ -425,6 +397,34 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "col_break2", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "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
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "uom", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -898,8 +898,8 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2017-10-25 17:18:59.974778", 
- "modified_by": "Administrator", 
+ "modified": "2017-12-15 16:29:18.902085", 
+ "modified_by": "nabinhait@gmail.com", 
  "module": "Stock", 
  "name": "Material Request Item", 
  "owner": "Administrator", 
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index 79afb21..4c5031d 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -191,16 +191,18 @@
 			'allow_zero_valuation': 1,
 		};
 
-		frappe.call({
-			method: "erpnext.stock.utils.get_incoming_rate",
-			args: {
-				args: args
-			},
-			callback: function(r) {
-				frappe.model.set_value(cdt, cdn, 'basic_rate', (r.message || 0.0));
-				frm.events.calculate_basic_amount(frm, item);
-			}
-		})
+		if (item.item_code || item.serial_no) {
+			frappe.call({
+				method: "erpnext.stock.utils.get_incoming_rate",
+				args: {
+					args: args
+				},
+				callback: function(r) {
+					frappe.model.set_value(cdt, cdn, 'basic_rate', (r.message || 0.0));
+					frm.events.calculate_basic_amount(frm, item);
+				}
+			});
+		}
 	},
 
 	get_warehouse_details: function(frm, cdt, cdn) {