Merge pull request #7336 from rohitwaghchaure/pos_enhancement_and_issues

[Enhancement] POS features
diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.json b/erpnext/accounts/doctype/pos_profile/pos_profile.json
index cef56af..a25dd51 100644
--- a/erpnext/accounts/doctype/pos_profile/pos_profile.json
+++ b/erpnext/accounts/doctype/pos_profile/pos_profile.json
@@ -22,7 +22,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "in_standard_filter": 1, 
    "label": "Applicable for User", 
    "length": 0, 
    "no_copy": 0, 
@@ -52,7 +51,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "in_standard_filter": 0, 
    "label": "Series", 
    "length": 0, 
    "no_copy": 1, 
@@ -84,7 +82,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Update Stock", 
    "length": 0, 
    "no_copy": 0, 
@@ -112,7 +109,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Warehouse", 
    "length": 0, 
    "no_copy": 0, 
@@ -142,7 +138,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Campaign", 
    "length": 0, 
    "no_copy": 0, 
@@ -164,34 +159,6 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "ignore_pricing_rule", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Ignore Pricing Rule", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
    "fieldname": "column_break_4", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -199,7 +166,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -226,7 +192,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Customer", 
    "length": 0, 
    "no_copy": 0, 
@@ -256,7 +221,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "in_standard_filter": 1, 
    "label": "Company", 
    "length": 0, 
    "no_copy": 0, 
@@ -286,7 +250,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Currency", 
    "length": 0, 
    "no_copy": 0, 
@@ -309,6 +272,33 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "ignore_pricing_rule", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Ignore Pricing Rule", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "allow_delete", 
    "fieldtype": "Check", 
    "hidden": 0, 
@@ -316,7 +306,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Allow Delete", 
    "length": 0, 
    "no_copy": 0, 
@@ -337,6 +326,33 @@
    "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_list_view": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_11", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -344,7 +360,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -371,7 +386,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Sales Invoice Payment", 
    "length": 0, 
    "no_copy": 0, 
@@ -400,7 +414,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -427,7 +440,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Item Groups", 
    "length": 0, 
    "no_copy": 0, 
@@ -456,7 +468,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -483,7 +494,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Customer Groups", 
    "length": 0, 
    "no_copy": 0, 
@@ -512,7 +522,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -540,7 +549,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Print Format", 
    "length": 0, 
    "no_copy": 0, 
@@ -569,7 +577,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Letter Head", 
    "length": 0, 
    "no_copy": 0, 
@@ -599,7 +606,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Print Heading", 
    "length": 0, 
    "no_copy": 0, 
@@ -629,7 +635,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Terms and Conditions", 
    "length": 0, 
    "no_copy": 0, 
@@ -659,7 +664,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "oldfieldtype": "Column Break", 
@@ -687,7 +691,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "in_standard_filter": 0, 
    "label": "Territory", 
    "length": 0, 
    "no_copy": 0, 
@@ -717,7 +720,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Price List", 
    "length": 0, 
    "no_copy": 0, 
@@ -747,7 +749,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Apply Discount", 
    "length": 0, 
    "no_copy": 0, 
@@ -777,7 +778,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Apply Discount On", 
    "length": 0, 
    "no_copy": 0, 
@@ -806,7 +806,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -834,7 +833,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Write Off Account", 
    "length": 0, 
    "no_copy": 0, 
@@ -863,7 +861,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Write Off Cost Center", 
    "length": 0, 
    "no_copy": 0, 
@@ -892,7 +889,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Account for Change Amount", 
    "length": 0, 
    "no_copy": 0, 
@@ -921,7 +917,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Taxes and Charges", 
    "length": 0, 
    "no_copy": 0, 
@@ -951,7 +946,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -978,7 +972,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Income Account", 
    "length": 0, 
    "no_copy": 0, 
@@ -1009,7 +1002,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Expense Account", 
    "length": 0, 
    "no_copy": 0, 
@@ -1037,7 +1029,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Cost Center", 
    "length": 0, 
    "no_copy": 0, 
@@ -1067,8 +1058,8 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-12-12 17:02:22.323006", 
- "modified_by": "Administrator", 
+ "modified": "2016-12-28 15:14:59.411457", 
+ "modified_by": "rohit@erpnext.com", 
  "module": "Accounts", 
  "name": "POS Profile", 
  "owner": "Administrator", 
diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py
index 3619e98..f5721e8 100644
--- a/erpnext/accounts/doctype/sales_invoice/pos.py
+++ b/erpnext/accounts/doctype/sales_invoice/pos.py
@@ -41,6 +41,7 @@
 		'pos_profile': pos_profile,
 		'meta': {
 			'invoice': frappe.get_meta('Sales Invoice'),
+			'customer': frappe.get_meta('Customer'),
 			'items': frappe.get_meta('Sales Invoice Item'),
 			'taxes': frappe.get_meta('Sales Taxes and Charges')
 		}
diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js
index a4078bd..55f6653 100644
--- a/erpnext/accounts/page/pos/pos.js
+++ b/erpnext/accounts/page/pos/pos.js
@@ -325,6 +325,7 @@
 
 		$.each(this.meta, function(i, data){
 			frappe.meta.sync(data)
+			locals["DocType"][data.name] = data;
 		})
 
 		this.print_template_data = frappe.render_template("print_template",
@@ -412,21 +413,26 @@
 			autoFocus: true,
 			source: function (request, response) {
 				me.customer_data = me.get_customers(request.term)
+				me.add_customer();
+
 				response($.map(me.customer_data, function(data){
-					return {label: data.name, value: data.name,
-						customer_group: data.customer_group, territory: data.territory}
+					return {label: data.name, customer_name: data.name, customer_group: data.customer_group,
+						territory: data.territory, onclick: data.onclick}
 				}))
 			},
-			change: function(event, ui){
-				if(ui.item){
-					me.frm.doc.customer = ui.item.label;
-					me.frm.doc.customer_name = ui.item.customer_name;
-					me.frm.doc.customer_group = ui.item.customer_group;
-					me.frm.doc.territory = ui.item.territory;
-				}else{
-					me.frm.doc.customer = me.party_field.$input.val();
+			select: function(event, ui){
+				if(ui.item.onclick) {
+					ui.item.value = ""
+					ui.item.onclick(me);
+				}else if(ui.item) {
+					me.update_customer_data(ui.item)
 				}
 				me.refresh();
+			},
+			change: function(event, ui) {
+				if(!ui.item) {
+					me.frm.doc.customer = $(this).val();
+				}
 			}
 		}).on("focus", function(){
 			setTimeout(function() {
@@ -434,7 +440,43 @@
 					me.party_field.$input.autocomplete( "search", " " );
 				}
 			}, 500);
-		});
+		}).autocomplete(this.party_field).data('ui-autocomplete')._renderItem = function(ul, d){
+			var html = "<span>" + __(d.label) + "</span>";
+			return $('<li></li>')
+				.data('item.autocomplete', d)
+				.html('<a><p>' + html + '</p></a>')
+				.appendTo(ul);
+		}
+	},
+
+	add_customer: function() {
+		var me = this;
+		if(this.connection_status) {
+			this.customer_data.push({
+				name: "<span class='text-primary link-option'>"
+					+ "<i class='fa fa-plus' style='margin-right: 5px;'></i> "
+					+ __("Create a new Customer")
+					+ "</span>",
+				onclick: me.new_customer
+			});
+		}
+	},
+
+	new_customer: function(obj) {
+		var me = obj;
+		frappe.ui.form.quick_entry('Customer', function(doc){
+			me.customers.push(doc)
+			me.party_field.$input.val(doc.name);
+			me.update_customer_data(doc)
+		})
+	},
+
+	update_customer_data: function(doc) {
+		var me = this;
+		this.frm.doc.customer = doc.label || doc.name;
+		this.frm.doc.customer_name = doc.customer_name;
+		this.frm.doc.customer_group = doc.customer_group;
+		this.frm.doc.territory = doc.territory;
 	},
 
 	get_customers: function(key){
@@ -593,7 +635,7 @@
 
 		this.remove_item = []
 		$.each(this.frm.doc["items"] || [], function(i, d) {
-			if(d.serial_no){
+			if(d.serial_no && field == 'qty'){
 				me.validate_serial_no_qty(d, item_code, field, value)
 			}
 
@@ -764,6 +806,7 @@
 				actual_qty: me.actual_qty_dict[d.item_code] || 0,
 				projected_qty: d.projected_qty,
 				rate: format_number(d.rate, me.frm.doc.currency),
+				enabled: me.pos_profile_data["allow_user_to_edit_rate"] ? true: false,
 				amount: format_currency(d.amount, me.frm.doc.currency)
 			})).appendTo($items);
 		});
diff --git a/erpnext/accounts/print_format/point_of_sale/point_of_sale.json b/erpnext/accounts/print_format/point_of_sale/point_of_sale.json
index 773f7fc..367ce07 100644
--- a/erpnext/accounts/print_format/point_of_sale/point_of_sale.json
+++ b/erpnext/accounts/print_format/point_of_sale/point_of_sale.json
@@ -1,4 +1,5 @@
 {
+ "align_labels_left": 0, 
  "creation": "2016-05-05 17:16:18.564460", 
  "custom_format": 1, 
  "disabled": 0, 
@@ -6,13 +7,16 @@
  "docstatus": 0, 
  "doctype": "Print Format", 
  "font": "Default", 
- "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{{ company }}<br>\n\t{{  __(\"POS No : \") }}{{offline_pos_name}}<br>\n</p>\n<p>\n\t<b>{{ __(\"Date\") }}:</b> {{ dateutil.global_date_format(posting_date) }}<br>\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=\"50%\">{{ __(\"Item\") }}</b></th>\n\t\t\t<th width=\"25%\" class=\"text-right\">{{ __(\"Qty\") }}</th>\n\t\t\t<th width=\"25%\" class=\"text-right\">{{ __(\"Amount\") }}</th>\n\t\t</tr>\n\t</thead>\n\t<tbody>\n\t\t{% for item in items %}\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\t{{ item.item_name }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">{{ format_number(item.qty, precision(\"difference\")) }}<br>@ {{ format_currency(item.rate, currency) }}</td>\n\t\t\t<td class=\"text-right\">{{ format_currency(item.amount, currency) }}</td>\n\t\t</tr>\n\t\t{% endfor %}\n\t</tbody>\n</table>\n\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{{ format_currency(total, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% for row in 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{{ format_currency(row.tax_amount, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% endif %}\n\t\t{% endfor %}\n\t\t{% if 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{{ format_currency(discount_amount, currency) }}\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{{ format_currency(grand_total, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t</tbody>\n</table>\n\n\n<hr>\n<p class=\"text-center\">{{ __(\"Thank you, please visit again.\") }}</p>", 
+ "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{{ company }}<br>\n\t{{  __(\"POS No : \") }}{{offline_pos_name}}<br>\n</p>\n<p>\n\t<b>{{ __(\"Date\") }}:</b> {{ dateutil.global_date_format(posting_date) }}<br>\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=\"50%\">{{ __(\"Item\") }}</b></th>\n\t\t\t<th width=\"25%\" class=\"text-right\">{{ __(\"Qty\") }}</th>\n\t\t\t<th width=\"25%\" class=\"text-right\">{{ __(\"Amount\") }}</th>\n\t\t</tr>\n\t</thead>\n\t<tbody>\n\t\t{% for item in items %}\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\t{{ item.item_name }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">{{ format_number(item.qty, precision(\"difference\")) }}<br>@ {{ format_currency(item.rate, currency) }}</td>\n\t\t\t<td class=\"text-right\">{{ format_currency(item.amount, currency) }}</td>\n\t\t</tr>\n\t\t{% endfor %}\n\t</tbody>\n</table>\n\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{{ format_currency(total, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% for row in 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{{ format_currency(row.tax_amount, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% endif %}\n\t\t{% endfor %}\n\t\t{% if 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{{ format_currency(discount_amount, currency) }}\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{{ format_currency(grand_total, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 75%\">\n\t\t\t\t<b>{{ __(\"Paid Amount\") }}</b>\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(paid_amount, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t</tbody>\n</table>\n\n\n<hr>\n<p class=\"text-center\">{{ __(\"Thank you, please visit again.\") }}</p>", 
  "idx": 0, 
- "modified": "2016-09-05 08:28:42.308782", 
+ "line_breaks": 0, 
+ "modified": "2016-12-27 17:22:17.391673", 
  "modified_by": "Administrator", 
+ "module": "Accounts", 
  "name": "Point of Sale", 
  "owner": "Administrator", 
  "print_format_builder": 0, 
  "print_format_type": "Js", 
+ "show_section_headings": 0, 
  "standard": "Yes"
 }
\ No newline at end of file
diff --git a/erpnext/public/js/pos/pos_bill_item.html b/erpnext/public/js/pos/pos_bill_item.html
index a6ef2d6..d8833bb 100644
--- a/erpnext/public/js/pos/pos_bill_item.html
+++ b/erpnext/public/js/pos/pos_bill_item.html
@@ -17,7 +17,13 @@
         </div>
     </div>
     <div class="col-xs-3 text-right">
-        <div class="text-muted" style="margin-top: 5px;"><input type="text" value="{%= rate %}" class="form-control input-sm pos-item-rate text-right"></div>
+        <div class="text-muted" style="margin-top: 5px;">
+			{% if(enabled) { %}
+				<input type="text" value="{%= rate %}" class="form-control input-sm pos-item-rate text-right">
+			{% } else { %}
+				<h6>{%= format_currency(rate) %}</h6>
+			{% } %}
+		</div>
 		<p><h6>{%= amount %}</h6></p>
     </div>
 </div>
diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py
index 7f506d5..32ad8eb 100644
--- a/erpnext/setup/doctype/company/company.py
+++ b/erpnext/setup/doctype/company/company.py
@@ -78,6 +78,8 @@
 
 		if not frappe.local.flags.ignore_chart_of_accounts:
 			self.set_default_accounts()
+			if self.default_cash_account:
+				self.mode_of_payment()
 
 		if self.default_currency:
 			frappe.db.set_value("Currency", self.default_currency, "enabled", 1)
@@ -162,6 +164,16 @@
 		if account:
 			self.db_set(fieldname, account)
 
+	def mode_of_payment(self):
+		cash = frappe.db.get_value('Mode of Payment', {'type': 'Cash'}, 'name')
+		if cash and not frappe.db.get_value('Mode of Payment Account', {'company': self.name}):
+			mode_of_payment = frappe.get_doc('Mode of Payment', cash)
+			mode_of_payment.append('accounts', {
+				'company': self.name,
+				'default_account': self.default_cash_account
+			})
+			mode_of_payment.save(ignore_permissions=True)
+
 	def create_default_cost_center(self):
 		cc_list = [
 			{
diff --git a/erpnext/setup/doctype/company/test_company.py b/erpnext/setup/doctype/company/test_company.py
index 43cb4d3..d2e7d23 100644
--- a/erpnext/setup/doctype/company/test_company.py
+++ b/erpnext/setup/doctype/company/test_company.py
@@ -40,9 +40,10 @@
 			acc = frappe.get_doc("Account", account)
 			for prop, val in acc_property.items():
 				self.assertEqual(acc.get(prop), val)
-				
+
+		self.delete_mode_of_payment("COA from Existing Company")
 		frappe.delete_doc("Company", "COA from Existing Company")
-				
+
 	def test_coa_based_on_country_template(self):
 		countries = ["India", "Brazil", "United Arab Emirates", "Canada", "Germany", "France",
 			"Guatemala", "Indonesia", "Mexico", "Nicaragua", "Netherlands", "Singapore"]
@@ -78,4 +79,9 @@
 
 						self.assertTrue(frappe.get_all("Account", filters))
 				finally:
-					frappe.delete_doc("Company", template)
\ No newline at end of file
+					self.delete_mode_of_payment(template)
+					frappe.delete_doc("Company", template)
+
+	def delete_mode_of_payment(self, company):
+		frappe.db.sql(""" delete from `tabMode of Payment Account`
+			where company =%s """, (company))