Merge pull request #5826 from rohitwaghchaure/v7_pos_issue

[Fix]POS and timesheet issues
diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py
index f986eea..605bf09 100644
--- a/erpnext/accounts/doctype/sales_invoice/pos.py
+++ b/erpnext/accounts/doctype/sales_invoice/pos.py
@@ -71,7 +71,7 @@
 def update_multi_mode_option(doc, pos_profile):
 	from frappe.model import default_fields
 
-	if not pos_profile:
+	if not pos_profile or not pos_profile.get('payments'):
 		for payment in get_mode_of_payment(doc):
 			payments = doc.append('payments', {})
 			payments.mode_of_payment = payment.parent
@@ -166,13 +166,14 @@
 
 	for docs in doc_list:
 		for name, doc in docs.items():
-			validate_customer(doc)
-			validate_item(doc)
-			si_doc = frappe.new_doc('Sales Invoice')
-			si_doc.offline_pos_name = name
-			si_doc.update(doc)
-			submit_invoice(si_doc, name)
-			name_list.append(name)
+			if not frappe.db.exists('Sales Invoice', {'offline_pos_name': name}):
+				validate_customer(doc)
+				validate_item(doc)
+				si_doc = frappe.new_doc('Sales Invoice')
+				si_doc.offline_pos_name = name
+				si_doc.update(doc)
+				submit_invoice(si_doc, name)
+				name_list.append(name)
 
 	return name_list
 
@@ -213,7 +214,6 @@
 		save_invoice(e, si_doc, name)
 
 def save_invoice(e, si_doc, name):
-	if not frappe.db.exists('Sales Invoice', {'offline_pos_name': name, 'docstatus': 1}):
 		si_doc.docstatus = 0
 		si_doc.name = ''
 		si_doc.save(ignore_permissions=True)
diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js
index 49cbdd0..cb57ff4 100644
--- a/erpnext/accounts/page/pos/pos.js
+++ b/erpnext/accounts/page/pos/pos.js
@@ -104,9 +104,10 @@
 
 		this.page.add_menu_item(__("Sync Master Data"), function(){
 			me.get_data_from_server(function(){
-				me.load_data();
+				me.load_data(false);
 				me.make_customer();
 				me.make_item_list();
+				me.set_missing_values();
 			})
 		});
 
@@ -151,7 +152,7 @@
 				if(doc_data){
 					me.frm.doc = doc_data[0][me.name];
 					me.set_missing_values();
-					me.refresh();
+					me.refresh(false);
 					me.disable_input_field();
 					me.list_dialog.hide();
 				}
@@ -177,6 +178,10 @@
 		if(this.frm.doc.payments.length == 0){
 			this.frm.doc.payments = doc.payments;
 		}
+
+		if(this.frm.doc.customer){
+			this.party_field.$input.val(this.frm.doc.customer);
+		}
 	},
 
 	get_invoice_doc: function(si_docs){
@@ -222,15 +227,18 @@
 		var me = this;
 		this.frm = {}
 		this.name = '';
-		this.load_data();
+		this.load_data(true);
 		this.setup();
 	},
 
-	load_data: function(){
+	load_data: function(load_doc){
 		this.items = window.items;
 		this.customers = window.customers;
 		this.pricing_rules = window.pricing_rules;
-		this.frm.doc =  JSON.parse(localStorage.getItem('doc'));
+
+		if(load_doc) {
+			this.frm.doc =  JSON.parse(localStorage.getItem('doc'));
+		}
 
 		$.each(window.meta, function(i, data){
 			frappe.meta.sync(data)
@@ -302,7 +310,7 @@
 	make_customer: function() {
 		var me = this;
 
-		if(this.default_customer){
+		if(this.default_customer && !this.frm.doc.customer){
 			this.party_field.$input.val(this.default_customer);
 			this.frm.doc.customer = this.default_customer;
 		}
@@ -535,7 +543,6 @@
 
 	customer_validate: function(){
 		var me = this;
-
 		if(!this.frm.doc.customer){
 			frappe.throw(__("Please select customer"))
 		}
@@ -598,21 +605,21 @@
 			? this.item_serial_no[this.child.item_code][0] : '');
 	},
 
-	refresh: function() {
+	refresh: function(update_paid_amount) {
 		var me = this;
-		this.refresh_fields();
+		this.refresh_fields(update_paid_amount);
 		this.update_qty();
 		this.update_rate();
 		this.set_primary_action();
 	},
-	refresh_fields: function() {
+	refresh_fields: function(update_paid_amount) {
 		this.apply_pricing_rule();
 		this.discount_amount_applied = false;
 		this._calculate_taxes_and_totals();
 		this.calculate_discount_amount();
 		this.show_items_in_item_cart();
 		this.set_taxes();
-		this.calculate_outstanding_amount();
+		this.calculate_outstanding_amount(update_paid_amount);
 		this.set_totals();
 	},
 
diff --git a/erpnext/projects/doctype/timesheet_detail/timesheet_detail.json b/erpnext/projects/doctype/timesheet_detail/timesheet_detail.json
index ce8c569..9413629 100644
--- a/erpnext/projects/doctype/timesheet_detail/timesheet_detail.json
+++ b/erpnext/projects/doctype/timesheet_detail/timesheet_detail.json
@@ -394,7 +394,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "depends_on": "project", 
+   "depends_on": "", 
    "fieldname": "task", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -532,7 +532,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-07-18 13:57:29.873073", 
+ "modified": "2016-07-21 09:59:01.622745", 
  "modified_by": "Administrator", 
  "module": "Projects", 
  "name": "Timesheet Detail", 
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index 236eb82..8405e3d 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -75,7 +75,7 @@
 		this.frm.doc.conversion_rate = flt(this.frm.doc.conversion_rate, precision("conversion_rate"));
 		var conversion_rate_label = frappe.meta.get_label(this.frm.doc.doctype, "conversion_rate",
 			this.frm.doc.name);
-		var company_currency = this.get_company_currency();
+		var company_currency = this.frm.doc.currency || this.get_company_currency();
 
 		if(!this.frm.doc.conversion_rate) {
 			if(this.frm.doc.currency == company_currency) {
@@ -427,7 +427,7 @@
 				this.frm.doc.currency, precision("rounded_total"));
 		}
 		if(frappe.meta.get_docfield(this.frm.doc.doctype, "base_rounded_total", this.frm.doc.name)) {
-			var company_currency = this.get_company_currency();
+			var company_currency = this.frm.doc.currency || this.get_company_currency();
 
 			this.frm.doc.base_rounded_total =
 				round_based_on_smallest_currency_fraction(this.frm.doc.base_grand_total,
@@ -587,7 +587,7 @@
 				if(data.type == "Cash" && payment_status) {
 					data.amount = total_amount_to_pay;
 					payment_status = false;
-				}else{
+				}else if(me.frm.doc.paid_amount){
 					data.amount = 0.0;
 				}
 			})