Merge pull request #11398 from rohitwaghchaure/item_variants_donot_copy_option

[enhance] In item variants settings added provision, do not update the variants of variants from the template but will copy the value while making new variant aginst the template
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index b245f56..2812fa7 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -4,7 +4,7 @@
 import frappe
 from erpnext.hooks import regional_overrides
 
-__version__ = '9.2.2'
+__version__ = '9.2.4'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js
index 17ac1f7..52d8a2d 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.js
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js
@@ -648,13 +648,13 @@
 
 	set_difference_amount: function(frm) {
 		var unallocated_amount = 0;
+		var total_deductions = frappe.utils.sum($.map(frm.doc.deductions || [],
+			function(d) { return flt(d.amount) }));
+
 		if(frm.doc.party) {
 			var party_amount = frm.doc.payment_type=="Receive" ?
 				frm.doc.paid_amount : frm.doc.received_amount;
 
-			var total_deductions = frappe.utils.sum($.map(frm.doc.deductions || [],
-				function(d) { return flt(d.amount) }));
-
 			if(frm.doc.total_allocated_amount < party_amount) {
 				if(frm.doc.payment_type == "Receive") {
 					unallocated_amount = party_amount - (frm.doc.total_allocated_amount - total_deductions);
diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.json b/erpnext/accounts/doctype/pos_profile/pos_profile.json
index 187454e..8136c98 100644
--- a/erpnext/accounts/doctype/pos_profile/pos_profile.json
+++ b/erpnext/accounts/doctype/pos_profile/pos_profile.json
@@ -3,7 +3,7 @@
  "allow_guest_to_view": 0, 
  "allow_import": 0, 
  "allow_rename": 0, 
- "autoname": "hash", 
+ "autoname": "field:pos_profile_name", 
  "beta": 0, 
  "creation": "2013-05-24 12:15:51", 
  "custom": 0, 
@@ -17,6 +17,96 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "default": "0", 
+   "fieldname": "disabled", 
+   "fieldtype": "Check", 
+   "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, 
+   "label": "Disabled", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "section_break_2", 
+   "fieldtype": "Section 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, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "pos_profile_name", 
+   "fieldtype": "Data", 
+   "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, 
+   "label": "POS Profile Name", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "user", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -112,9 +202,8 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "depends_on": "update_stock", 
-   "fieldname": "warehouse", 
-   "fieldtype": "Link", 
+   "fieldname": "ignore_pricing_rule", 
+   "fieldtype": "Check", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -122,13 +211,11 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Warehouse", 
+   "label": "Ignore Pricing Rule", 
    "length": 0, 
    "no_copy": 0, 
-   "oldfieldname": "warehouse", 
-   "oldfieldtype": "Link", 
-   "options": "Warehouse", 
    "permlevel": 0, 
+   "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
@@ -145,8 +232,8 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "campaign", 
-   "fieldtype": "Link", 
+   "fieldname": "allow_delete", 
+   "fieldtype": "Check", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -154,10 +241,39 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Campaign", 
+   "label": "Allow Delete", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "Campaign", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "allow_user_to_edit_rate", 
+   "fieldtype": "Check", 
+   "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, 
+   "label": "Allow user to edit Rate", 
+   "length": 0, 
+   "no_copy": 0, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -300,7 +416,8 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "currency", 
+   "depends_on": "update_stock", 
+   "fieldname": "warehouse", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -309,19 +426,19 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Currency", 
+   "label": "Warehouse", 
    "length": 0, 
    "no_copy": 0, 
-   "oldfieldname": "currency", 
-   "oldfieldtype": "Select", 
-   "options": "Currency", 
+   "oldfieldname": "warehouse", 
+   "oldfieldtype": "Link", 
+   "options": "Warehouse", 
    "permlevel": 0, 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "remember_last_selected_value": 0, 
    "report_hide": 0, 
-   "reqd": 1, 
+   "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
@@ -332,8 +449,8 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "ignore_pricing_rule", 
-   "fieldtype": "Check", 
+   "fieldname": "campaign", 
+   "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -341,9 +458,10 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Ignore Pricing Rule", 
+   "label": "Campaign", 
    "length": 0, 
    "no_copy": 0, 
+   "options": "Campaign", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -362,66 +480,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "allow_delete", 
-   "fieldtype": "Check", 
-   "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, 
-   "label": "Allow Delete", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_bulk_edit": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "allow_user_to_edit_rate", 
-   "fieldtype": "Check", 
-   "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, 
-   "label": "Allow user to edit Rate", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_bulk_edit": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
+   "depends_on": "", 
    "fieldname": "section_break_11", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -482,6 +541,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "depends_on": "", 
    "fieldname": "section_break_14", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -602,6 +662,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "depends_on": "", 
    "fieldname": "section_break_16", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -882,6 +943,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "depends_on": "", 
    "fieldname": "offline_pos_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1037,6 +1099,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "depends_on": "", 
    "fieldname": "section_break_19", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1046,6 +1109,7 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
+   "label": "Accounting", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -1066,6 +1130,38 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "currency", 
+   "fieldtype": "Link", 
+   "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, 
+   "label": "Currency", 
+   "length": 0, 
+   "no_copy": 0, 
+   "oldfieldname": "currency", 
+   "oldfieldtype": "Select", 
+   "options": "Currency", 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "write_off_account", 
    "fieldtype": "Link", 
@@ -1160,38 +1256,6 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "taxes_and_charges", 
-   "fieldtype": "Link", 
-   "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, 
-   "label": "Taxes and Charges", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "charge", 
-   "oldfieldtype": "Link", 
-   "options": "Sales Taxes and Charges Template", 
-   "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": "column_break_23", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -1309,6 +1373,38 @@
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "taxes_and_charges", 
+   "fieldtype": "Link", 
+   "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, 
+   "label": "Taxes and Charges", 
+   "length": 0, 
+   "no_copy": 0, 
+   "oldfieldname": "charge", 
+   "oldfieldtype": "Link", 
+   "options": "Sales Taxes and Charges Template", 
+   "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
   }
  ], 
  "has_web_view": 0, 
@@ -1322,7 +1418,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-09-01 15:55:14.890452", 
+ "modified": "2017-10-27 06:45:32.957674", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "POS Profile", 
diff --git a/erpnext/accounts/doctype/pos_profile/test_pos_profile.py b/erpnext/accounts/doctype/pos_profile/test_pos_profile.py
index 803ee8e..1e43173 100644
--- a/erpnext/accounts/doctype/pos_profile/test_pos_profile.py
+++ b/erpnext/accounts/doctype/pos_profile/test_pos_profile.py
@@ -41,6 +41,7 @@
 		"expense_account": "_Test Account Cost for Goods Sold - _TC",
 		"income_account": "Sales - _TC",
 		"name": "_Test POS Profile",
+		"pos_profile_name": "_Test POS Profile",
 		"naming_series": "_T-POS Profile-",
 		"selling_price_list": "_Test Price List",
 		"territory": "_Test Territory",
diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py
index 6856f62..36c2365 100644
--- a/erpnext/accounts/doctype/sales_invoice/pos.py
+++ b/erpnext/accounts/doctype/sales_invoice/pos.py
@@ -92,6 +92,7 @@
 	doc.customer_group = pos_profile.get('customer_group') or get_root('Customer Group')
 	doc.territory = pos_profile.get('territory') or get_root('Territory')
 	doc.terms = frappe.db.get_value('Terms and Conditions', pos_profile.get('tc_name'), 'terms') or doc.terms or ''
+	doc.offline_pos_name = ''
 
 def get_root(table):
 	root = frappe.db.sql(""" select name from `tab%(table)s` having
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 1c4fe3d..995a333 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -70,7 +70,6 @@
 		self.clear_unallocated_advances("Sales Invoice Advance", "advances")
 		self.add_remarks()
 		self.validate_write_off_account()
-		self.validate_duplicate_offline_pos_entry()
 		self.validate_account_for_change_amount()
 		self.validate_fixed_asset()
 		self.set_income_account_for_fixed_assets()
@@ -305,6 +304,7 @@
 			self.account_for_change_amount = frappe.db.get_value('Company', self.company, 'default_cash_account')
 
 		if pos:
+			self.pos_profile = pos.name
 			if not for_validate and not self.customer:
 				self.customer = pos.customer
 				self.mode_of_payment = pos.mode_of_payment
@@ -463,12 +463,6 @@
 		if flt(self.write_off_amount) and not self.write_off_account:
 			msgprint(_("Please enter Write Off Account"), raise_exception=1)
 
-	def validate_duplicate_offline_pos_entry(self):
-		if self.is_pos and self.offline_pos_name \
-			and frappe.db.get_value('Sales Invoice',
-			{'offline_pos_name': self.offline_pos_name, 'docstatus': 1}):
-			frappe.throw(_("Duplicate offline pos sales invoice {0}").format(self.offline_pos_name))
-
 	def validate_account_for_change_amount(self):
 		if flt(self.change_amount) and not self.account_for_change_amount:
 			msgprint(_("Please enter Account for Change Amount"), raise_exception=1)
diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js
index c442062..6b58033 100644
--- a/erpnext/accounts/page/pos/pos.js
+++ b/erpnext/accounts/page/pos/pos.js
@@ -179,41 +179,12 @@
 		}
 	},
 
-	dialog_actions: function () {
-		var me = this;
-
-		$(this.list_body).find('.list-select-all').click(function () {
-			me.removed_items = [];
-			$(me.list_body).find('.list-delete').prop("checked", $(this).is(":checked"))
-			if ($(this).is(":checked")) {
-				$.each(me.si_docs, function (index, data) {
-					for (key in data) {
-						me.removed_items.push(key)
-					}
-				})
-			}
-
-			me.toggle_delete_button();
-		})
-
-		$(this.list_body).find('.list-delete').click(function () {
-			me.name = $(this).parent().parent().attr('invoice-name');
-			if ($(this).is(":checked")) {
-				me.removed_items.push(me.name);
-			} else {
-				me.removed_items.pop(me.name)
-			}
-
-			me.toggle_delete_button();
-		})
-	},
-
 	edit_record: function () {
 		var me = this;
 
 		doc_data = this.get_invoice_doc(this.si_docs);
 		if (doc_data) {
-			this.frm.doc = doc_data[0][this.name];
+			this.frm.doc = doc_data[0][this.frm.doc.offline_pos_name];
 			this.set_missing_values();
 			this.refresh(false);
 			this.toggle_input_field();
@@ -226,16 +197,15 @@
 		this.validate_list()
 		this.remove_doc_from_localstorage()
 		this.update_localstorage();
-		// this.dialog_actions();
 		this.toggle_delete_button();
 	},
 
 	validate_list: function() {
 		var me = this;
 		this.si_docs = this.get_submitted_invoice()
-		$.each(this.removed_items, function(index, name){
+		$.each(this.removed_items, function(index, pos_name){
 			$.each(me.si_docs, function(key, data){
-				if(me.si_docs[key][name] && me.si_docs[key][name].offline_pos_name == name ){
+				if(me.si_docs[key][pos_name] && me.si_docs[key][pos_name].offline_pos_name == pos_name ){
 					frappe.throw(__("Submitted orders can not be deleted"))
 				}
 			})
@@ -294,7 +264,7 @@
 
 		return $.grep(this.si_docs, function (data) {
 			for (key in data) {
-				return key == me.name
+				return key == me.frm.doc.offline_pos_name;
 			}
 		})
 	},
@@ -348,7 +318,6 @@
 	create_new: function () {
 		var me = this;
 		this.frm = {}
-		this.name = null;
 		this.load_data(true);
 		this.setup();
 		this.set_default_customer()
@@ -362,6 +331,7 @@
 
 		if (load_doc) {
 			this.frm.doc = JSON.parse(localStorage.getItem('doc'));
+			this.frm.doc.offline_pos_name = null;
 		}
 
 		$.each(this.meta, function (i, data) {
@@ -629,6 +599,7 @@
 		// this.list_customers.empty();
 		this.si_docs = this.get_doc_from_localstorage();
 		if (!this.si_docs.length) {
+			this.list_customers.find('.list-customers-table').html("");
 			return;
 		}
 
@@ -655,7 +626,7 @@
 			me.list_customers_btn.toggleClass("view_customer");
 			me.pos_bill.show();
 			me.list_customers_btn.show();
-			me.name = $(this).parents().attr('invoice-name')
+			me.frm.doc.offline_pos_name = $(this).parents().attr('invoice-name')
 			me.edit_record();
 		})
 
@@ -675,11 +646,11 @@
 		});
 
 		$(this.wrapper).find('.list-delete').click(function () {
-			me.name = $(this).parent().parent().attr('invoice-name');
+			me.frm.doc.offline_pos_name = $(this).parent().parent().attr('invoice-name');
 			if ($(this).is(":checked")) {
-				me.removed_items.push(me.name);
+				me.removed_items.push(me.frm.doc.offline_pos_name);
 			} else {
-				me.removed_items.pop(me.name)
+				me.removed_items.pop(me.frm.doc.offline_pos_name)
 			}
 
 			me.toggle_delete_button();
@@ -1435,7 +1406,7 @@
 	},
 
 	update_paid_amount_status: function (update_paid_amount) {
-		if (this.name) {
+		if (this.frm.doc.offline_pos_name) {
 			update_paid_amount = update_paid_amount ? false : true;
 		}
 
@@ -1643,18 +1614,17 @@
 
 	create_invoice: function () {
 		var me = this;
-		var invoice_data = {}
+		var invoice_data = {};
 		this.si_docs = this.get_doc_from_localstorage();
-		if (this.name) {
-			this.update_invoice()
+		if (this.frm.doc.offline_pos_name) {
+			this.update_invoice();
 		} else {
-			this.name = $.now();
-			this.frm.doc.offline_pos_name = this.name;
+			this.frm.doc.offline_pos_name = $.now();
 			this.frm.doc.posting_date = frappe.datetime.get_today();
 			this.frm.doc.posting_time = frappe.datetime.now_time();
 			this.frm.doc.pos_profile = this.pos_profile_data['name'];
-			invoice_data[this.name] = this.frm.doc
-			this.si_docs.push(invoice_data)
+			invoice_data[this.frm.doc.offline_pos_name] = this.frm.doc;
+			this.si_docs.push(invoice_data);
 			this.update_localstorage();
 			this.set_primary_action();
 		}
@@ -1666,12 +1636,12 @@
 		this.si_docs = this.get_doc_from_localstorage();
 		$.each(this.si_docs, function (index, data) {
 			for (var key in data) {
-				if (key == me.name) {
+				if (key == me.frm.doc.offline_pos_name) {
 					me.si_docs[index][key] = me.frm.doc;
 					me.update_localstorage();
 				}
 			}
-		})
+		});
 	},
 
 	update_localstorage: function () {
@@ -1710,6 +1680,8 @@
 		freeze_screen = this.freeze_screen || false;
 
 		if ((this.si_docs.length || this.email_queue_list || this.customers_list) && !this.freeze) {
+			this.freeze = true;
+
 			frappe.call({
 				method: "erpnext.accounts.doctype.sales_invoice.pos.make_invoice",
 				freeze: freeze_screen,
@@ -1720,17 +1692,19 @@
 				},
 				callback: function (r) {
 					if (r.message) {
+						me.freeze = false;
 						me.customers = r.message.synced_customers_list;
 						me.address = r.message.synced_address;
 						me.contacts = r.message.synced_contacts;
 						me.removed_items = r.message.invoice;
-						me.removed_email = r.message.email_queue
-						me.removed_customers = r.message.customers
+						me.removed_email = r.message.email_queue;
+						me.removed_customers = r.message.customers;
 						me.remove_doc_from_localstorage();
 						me.remove_email_queue_from_localstorage();
 						me.remove_customer_from_localstorage();
-						me.prepare_customer_mapper()
-						me.autocomplete_customers()
+						me.prepare_customer_mapper();
+						me.autocomplete_customers();
+						me.render_list_customers();
 					}
 				}
 			})
diff --git a/erpnext/accounts/page/pos/test_pos.js b/erpnext/accounts/page/pos/test_pos.js
index 8913a9e..e5524a2 100644
--- a/erpnext/accounts/page/pos/test_pos.js
+++ b/erpnext/accounts/page/pos/test_pos.js
@@ -6,6 +6,7 @@
 		() => {
 			return frappe.tests.make("POS Profile", [
 				{naming_series: "SINV"},
+				{pos_profile_name: "_Test POS Profile"},
 				{country: "India"},
 				{currency: "INR"},
 				{write_off_account: "Write Off - FT"},
diff --git a/erpnext/hr/doctype/employee_loan/employee_loan.js b/erpnext/hr/doctype/employee_loan/employee_loan.js
index 33d3a85..1f38105 100644
--- a/erpnext/hr/doctype/employee_loan/employee_loan.js
+++ b/erpnext/hr/doctype/employee_loan/employee_loan.js
@@ -87,22 +87,24 @@
 	},
 
 	employee_loan_application: function (frm) {
-		return frappe.call({
-			method: "erpnext.hr.doctype.employee_loan.employee_loan.get_employee_loan_application",
-			args: {
-				"employee_loan_application": frm.doc.employee_loan_application
-			},
-			callback: function (r) {
-				if (!r.exc && r.message) {
-					frm.set_value("loan_type", r.message.loan_type);
-					frm.set_value("loan_amount", r.message.loan_amount);
-					frm.set_value("repayment_method", r.message.repayment_method);
-					frm.set_value("monthly_repayment_amount", r.message.repayment_amount);
-					frm.set_value("repayment_periods", r.message.repayment_periods);
-					frm.set_value("rate_of_interest", r.message.rate_of_interest);
-				}
-			}
-		})
+	    if(frm.doc.employee_loan_application){
+            return frappe.call({
+                method: "erpnext.hr.doctype.employee_loan.employee_loan.get_employee_loan_application",
+                args: {
+                    "employee_loan_application": frm.doc.employee_loan_application
+                },
+                callback: function (r) {
+                    if (!r.exc && r.message) {
+                        frm.set_value("loan_type", r.message.loan_type);
+                        frm.set_value("loan_amount", r.message.loan_amount);
+                        frm.set_value("repayment_method", r.message.repayment_method);
+                        frm.set_value("monthly_repayment_amount", r.message.repayment_amount);
+                        frm.set_value("repayment_periods", r.message.repayment_periods);
+                        frm.set_value("rate_of_interest", r.message.rate_of_interest);
+                    }
+                }
+            });
+        }
 	},
 
 	repayment_method: function (frm) {
diff --git a/erpnext/hub_node/__init__.py b/erpnext/hub_node/__init__.py
index 686fe8d..8efbed8 100644
--- a/erpnext/hub_node/__init__.py
+++ b/erpnext/hub_node/__init__.py
@@ -34,7 +34,9 @@
 	return response
 
 @frappe.whitelist()
-def get_item_details(hub_sync_id):
+def get_item_details(hub_sync_id=None):
+	if not hub_sync_id:
+		return
 	connection = get_connection()
 	return connection.get_doc('Hub Item', hub_sync_id)
 
diff --git a/erpnext/hub_node/page/hub/hub.js b/erpnext/hub_node/page/hub/hub.js
index 143f554..297a4d1 100644
--- a/erpnext/hub_node/page/hub/hub.js
+++ b/erpnext/hub_node/page/hub/hub.js
@@ -382,6 +382,7 @@
 			},
 			method: "erpnext.hub_node.get_item_details",
 			callback: (r) => {
+				if (!r || !r.message) return;
 				let item = r.message;
 				this.item_cache[item_code] = item;
 				this.render_item_page(item);
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index fd7a1b4..486cd7c 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -455,3 +455,4 @@
 erpnext.patches.v9_0.set_variant_item_description
 erpnext.patches.v9_0.set_uoms_in_variant_field
 erpnext.patches.v9_0.copy_old_fees_field_data
+erpnext.patches.v9_0.set_pos_profile_name
diff --git a/erpnext/patches/v9_0/set_pos_profile_name.py b/erpnext/patches/v9_0/set_pos_profile_name.py
new file mode 100644
index 0000000..bc6e50e
--- /dev/null
+++ b/erpnext/patches/v9_0/set_pos_profile_name.py
@@ -0,0 +1,19 @@
+# Copyright (c) 2017, Frappe and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+	doctype = 'POS Profile'
+	frappe.reload_doctype(doctype)
+
+	for pos in frappe.get_all(doctype):
+		doc = frappe.get_doc(doctype, pos.name)
+
+		if not doc.user: continue
+
+		doc.pos_profile_name = doc.user + ' - ' + doc.company
+		doc.save()
+
+		frappe.rename_doc(doctype, doc.name, doc.pos_profile_name, force=True)
\ No newline at end of file
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index efb04d1..47cda19 100644
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -38,7 +38,7 @@
 	},
 
 	stale_rate_allowed: () => {
-		return cint(frappe.boot.sysdefaults.allow_stale) || 1;
+		return cint(frappe.boot.sysdefaults.allow_stale);
 	},
 
 	setup_serial_no: function() {
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index fa21a3d..747a3c0 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -477,9 +477,11 @@
 		target.qty = flt(source.qty) - flt(source.delivered_qty)
 
 		item = frappe.db.get_value("Item", target.item_code, ["item_group", "selling_cost_center"], as_dict=1)
-		target.cost_center = frappe.db.get_value("Project", source_parent.project, "cost_center") \
-			or item.selling_cost_center \
-			or frappe.db.get_value("Item Group", item.item_group, "default_cost_center")
+
+		if item:
+			target.cost_center = frappe.db.get_value("Project", source_parent.project, "cost_center") \
+				or item.selling_cost_center \
+				or frappe.db.get_value("Item Group", item.item_group, "default_cost_center")
 
 	target_doc = get_mapped_doc("Sales Order", source_name, {
 		"Sales Order": {
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 196bb96..a0f8598 100644
--- a/erpnext/selling/page/point_of_sale/point_of_sale.js
+++ b/erpnext/selling/page/point_of_sale/point_of_sale.js
@@ -43,6 +43,7 @@
 
 	make() {
 		return frappe.run_serially([
+			() => frappe.dom.freeze(),
 			() => {
 				this.prepare_dom();
 				this.prepare_menu();
@@ -55,6 +56,7 @@
 				frappe.timeout(1);
 				this.make_items();
 				this.bind_events();
+				frappe.dom.unfreeze();
 			},
 			() => this.page.set_title(__('Point of Sale'))
 		]);
@@ -156,6 +158,7 @@
 	}
 
 	update_item_in_cart(item_code, field='qty', value=1) {
+		frappe.dom.freeze();
 		if(this.cart.exists(item_code)) {
 			const item = this.frm.doc.items.find(i => i.item_code === item_code);
 			frappe.flags.hide_serial_batch_dialog = false;
@@ -220,6 +223,7 @@
 		this.cart.add_item(item);
 		this.cart.update_taxes_and_totals();
 		this.cart.update_grand_total();
+		frappe.dom.unfreeze();
 	}
 
 	update_item_in_frm(item, field, value) {
@@ -232,8 +236,6 @@
 			return frappe.model.set_value(item.doctype, item.name, field, value)
 				.then(() => this.frm.script_manager.trigger('qty', item.doctype, item.name))
 				.then(() => {
-					console.log(item.qty, item.amount);
-
 					if (field === 'qty' && item.qty === 0) {
 						frappe.model.clear_doc(item.doctype, item.name);
 					}
diff --git a/erpnext/startup/boot.py b/erpnext/startup/boot.py
index 2080224..e940f94 100644
--- a/erpnext/startup/boot.py
+++ b/erpnext/startup/boot.py
@@ -4,6 +4,7 @@
 
 from __future__ import unicode_literals
 import frappe
+from frappe.utils import cint
 
 def boot_session(bootinfo):
 	"""boot session - send website info if guest"""
@@ -19,8 +20,8 @@
 			'territory')
 		bootinfo.sysdefaults.customer_group = frappe.db.get_single_value('Selling Settings',
 			'customer_group')
-		bootinfo.sysdefaults.allow_stale = frappe.db.get_single_value('Accounts Settings',
-			'allow_stale') or 1
+		bootinfo.sysdefaults.allow_stale = cint(frappe.db.get_single_value('Accounts Settings',
+			'allow_stale'))
 
 		bootinfo.notification_settings = frappe.get_doc("Notification Control",
 			"Notification Control")
diff --git a/erpnext/support/doctype/issue/issue.py b/erpnext/support/doctype/issue/issue.py
index ab73b34..6a18f11 100644
--- a/erpnext/support/doctype/issue/issue.py
+++ b/erpnext/support/doctype/issue/issue.py
@@ -32,7 +32,7 @@
 		if email_id:
 			if not self.lead:
 				self.lead = frappe.db.get_value("Lead", {"email_id": email_id})
-			if not self.contact:
+			if not self.contact and not self.customer:
 				self.contact = frappe.db.get_value("Contact", {"email_id": email_id})
 
 				if self.contact: