Code cleanup online POS (#12985)

diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.py b/erpnext/accounts/doctype/pos_profile/pos_profile.py
index 0bce49c..20a90f4 100644
--- a/erpnext/accounts/doctype/pos_profile/pos_profile.py
+++ b/erpnext/accounts/doctype/pos_profile/pos_profile.py
@@ -32,7 +32,7 @@
 					.format(res[0][0], row.user), raise_exception=1)
 			elif not row.default and not res:
 				msgprint(_("User {0} doesn't have any default POS Profile. Check Default at Row {1} for this User.")
-					.format(row.user, row.idx), raise_exception=1)
+					.format(row.user, row.idx))
 
 	def validate_all_link_fields(self):
 		accounts = {"Account": [self.income_account,
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index 754fc6b..93c2206 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -106,6 +106,10 @@
 	on_submit: function(doc, dt, dn) {
 		var me = this;
 
+		if (frappe.get_route()[0] != 'Sales Invoice') {
+			return
+		}
+
 		$.each(doc["items"], function(i, row) {
 			if(row.delivery_note) frappe.model.clear_doc("Delivery Note", row.delivery_note)
 		})
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 9484dc7..d1f6b7a 100644
--- a/erpnext/selling/page/point_of_sale/point_of_sale.js
+++ b/erpnext/selling/page/point_of_sale/point_of_sale.js
@@ -256,17 +256,22 @@
 		if (field == 'qty' && value < 0) {
 			frappe.msgprint(__("Quantity must be positive"));
 			value = item.qty;
+		} else {
+			item[field] = value;
+			if (field == "serial_no" && value) {
+				let serial_nos = value.split("\n");
+				item["qty"] = serial_nos.filter(d => {
+					return d!=="";
+				}).length;
+			}
 		}
 
-		if (field) {
-			return frappe.model.set_value(item.doctype, item.name, field, value)
-				.then(() => this.frm.script_manager.trigger('qty', item.doctype, item.name))
-				.then(() => {
-					if (field === 'qty' && item.qty === 0) {
-						frappe.model.clear_doc(item.doctype, item.name);
-					}
-				})
-		}
+		return this.frm.script_manager.trigger('qty', item.doctype, item.name)
+			.then(() => {
+				if (field === 'qty' && item.qty === 0) {
+					frappe.model.clear_doc(item.doctype, item.name);
+				}
+			})
 
 		return Promise.resolve();
 	}
@@ -283,20 +288,13 @@
 	}
 
 	submit_sales_invoice() {
-
-		frappe.confirm(__("Permanently Submit {0}?", [this.frm.doc.name]), () => {
-			frappe.call({
-				method: 'erpnext.selling.page.point_of_sale.point_of_sale.submit_invoice',
-				freeze: true,
-				args: {
-					doc: this.frm.doc
-				}
-			}).then(r => {
-				if(r.message) {
-					this.frm.doc = r.message;
+		this.frm.savesubmit()
+			.then((r) => {
+				if (r && r.doc) {
+					this.frm.doc.docstatus = r.doc.docstatus;
 					frappe.show_alert({
 						indicator: 'green',
-						message: __(`Sales invoice ${r.message.name} created succesfully`)
+						message: __(`Sales invoice ${r.doc.name} created succesfully`)
 					});
 
 					this.toggle_editing();
@@ -304,21 +302,22 @@
 					this.set_primary_action_in_modal();
 				}
 			});
-		});
 	}
 
 	set_primary_action_in_modal() {
-		this.frm.msgbox = frappe.msgprint(
-			`<a class="btn btn-primary" onclick="cur_frm.print_preview.printit(true)" style="margin-right: 5px;">
-				${__('Print')}</a>
-			<a class="btn btn-default">
-				${__('New')}</a>`
-		);
+		if (!this.frm.msgbox) {
+			this.frm.msgbox = frappe.msgprint(
+				`<a class="btn btn-primary" onclick="cur_frm.print_preview.printit(true)" style="margin-right: 5px;">
+					${__('Print')}</a>
+				<a class="btn btn-default">
+					${__('New')}</a>`
+			);
 
-		$(this.frm.msgbox.body).find('.btn-default').on('click', () => {
-			this.frm.msgbox.hide();
-			this.make_new_invoice();
-		})
+			$(this.frm.msgbox.body).find('.btn-default').on('click', () => {
+				this.frm.msgbox.hide();
+				this.make_new_invoice();
+			})
+		}
 	}
 
 	change_pos_profile() {
@@ -487,11 +486,6 @@
 		//
 		// }).addClass('visible-xs');
 
-		this.page.add_menu_item(__("Form View"), function () {
-			frappe.model.sync(me.frm.doc);
-			frappe.set_route("Form", me.frm.doc.doctype, me.frm.doc.name);
-		});
-
 		this.page.add_menu_item(__("POS Profile"), function () {
 			frappe.set_route('List', 'POS Profile');
 		});
@@ -589,6 +583,7 @@
 		this.$taxes_and_totals.html(this.get_taxes_and_totals());
 		this.numpad && this.numpad.reset_value();
 		this.customer_field.set_value("");
+		this.frm.msgbox = "";
 
 		this.$discount_amount.find('input:text').val('');
 		this.wrapper.find('.grand-total-value').text(
diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.py b/erpnext/selling/page/point_of_sale/point_of_sale.py
index d98a017..8654287 100644
--- a/erpnext/selling/page/point_of_sale/point_of_sale.py
+++ b/erpnext/selling/page/point_of_sale/point_of_sale.py
@@ -87,19 +87,6 @@
 
 	return '%%%s%%'%(frappe.db.escape(item_code)), condition
 
-@frappe.whitelist()
-def submit_invoice(doc):
-	if isinstance(doc, basestring):
-		args = json.loads(doc)
-
-	doc = frappe.new_doc('Sales Invoice')
-	doc.update(args)
-	doc.run_method("set_missing_values")
-	doc.run_method("calculate_taxes_and_totals")
-	doc.submit()
-
-	return doc
-
 def get_item_group_condition(pos_profile):
 	cond = "and 1=1"
 	item_groups = get_item_groups(pos_profile)