Merge pull request #6516 from bcornwellmott/patch-6

Update request_for_quotation.html
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index bec17c1..03c30a1 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -2,7 +2,7 @@
 from __future__ import unicode_literals
 import frappe
 
-__version__ = '7.0.51'
+__version__ = '7.0.54'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index adc30e2..914c9be 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -372,7 +372,7 @@
 			if flt(item.base_net_amount):
 				account_currency = get_account_currency(item.expense_account)
 
-				if self.update_stock and self.auto_accounting_for_stock:
+				if self.update_stock and self.auto_accounting_for_stock and item.item_code in stock_items:
 					val_rate_db_precision = 6 if cint(item.precision("valuation_rate")) <= 6 else 9
 
 					# warehouse account
diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py
index 5336b54..51b8e7e 100644
--- a/erpnext/accounts/doctype/sales_invoice/pos.py
+++ b/erpnext/accounts/doctype/sales_invoice/pos.py
@@ -15,6 +15,7 @@
 	doc = frappe.new_doc('Sales Invoice')
 	doc.is_pos = 1;
 	pos_profile = get_pos_profile(doc.company) or {}
+	if not doc.company: doc.company = pos_profile.get('company')
 	doc.update_stock = pos_profile.get('update_stock')
 
 	if pos_profile.get('name'):
@@ -66,7 +67,7 @@
 	doc.naming_series = pos_profile.get('naming_series') or 'SINV-'
 	doc.letter_head = pos_profile.get('letter_head') or company_data.default_letter_head
 	doc.ignore_pricing_rule = pos_profile.get('ignore_pricing_rule') or 0
-	doc.apply_discount_on = pos_profile.get('apply_discount_on') or ''
+	doc.apply_discount_on = pos_profile.get('apply_discount_on') if pos_profile.get('apply_discount') else ''
 	doc.customer_group = pos_profile.get('customer_group') or get_root('Customer Group')
 	doc.territory = pos_profile.get('territory') or get_root('Territory')
 
diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py
index 4af197e..392902c 100644
--- a/erpnext/accounts/general_ledger.py
+++ b/erpnext/accounts/general_ledger.py
@@ -168,8 +168,8 @@
 
 	if not gl_entries:
 		gl_entries = frappe.db.sql("""
-			select account, posting_date, party_type, party, cost_center, fiscal_year,
-			voucher_type, voucher_no, against_voucher_type, against_voucher, cost_center
+			select account, posting_date, party_type, party, cost_center, fiscal_year,voucher_type,
+			voucher_no, against_voucher_type, against_voucher, cost_center, company
 			from `tabGL Entry`
 			where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no), as_dict=True)
 
diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js
index 247d5ac..fa88481 100644
--- a/erpnext/accounts/page/pos/pos.js
+++ b/erpnext/accounts/page/pos/pos.js
@@ -106,11 +106,15 @@
 			me.get_data_from_server(function(){
 				me.load_data(false);
 				me.make_customer();
-				me.make_item_list();
+				me.make_item_list(true);
 				me.set_missing_values();
 			})
 		});
 
+		this.page.add_menu_item(__("Sync Offline Invoices"), function(){
+			me.sync_sales_invoice()
+		});
+
 		this.page.add_menu_item(__("POS Profile"), function() {
 			frappe.set_route('List', 'POS Profile');
 		});
@@ -275,7 +279,7 @@
 	make: function() {
 		this.make_search();
 		this.make_customer();
-		this.make_item_list();
+		this.make_item_list(true);
 		this.make_discount_field()
 	},
 
@@ -296,7 +300,7 @@
 		this.search.$input.on("keyup", function() {
 			setTimeout(function() {
 				me.items = me.get_items();
-				me.make_item_list();
+				me.make_item_list(false);
 			}, 1000);
 		});
 
@@ -369,7 +373,7 @@
 		}
 	},
 
-	make_item_list: function() {
+	make_item_list: function(index_search) {
 		var me = this;
 		if(!this.price_list) {
 			msgprint(__("Price List not found or disabled"));
@@ -383,7 +387,7 @@
 
 		if (this.items) {
 			$.each(this.items, function(index, obj) {
-				if(index < 16){
+				if(!index_search || index < 16){
 					$(frappe.render_template("pos_item", {
 						item_code: obj.name,
 						item_price: format_currency(obj.price_list_rate, obj.currency),
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
index db811cf..ce7f7fc 100644
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
@@ -53,9 +53,10 @@
 			self.filters["range3"] = "90"
 			
 		for label in ("0-{range1}".format(range1=self.filters["range1"]),
-			"{range1}-{range2}".format(range1=self.filters["range1"]+1, range2=self.filters["range2"]),
-			"{range2}-{range3}".format(range2=self.filters["range2"]+1, range3=self.filters["range3"]),
-			"{range3}-{above}".format(range3=self.filters["range3"] + 1, above=_("Above"))):
+			"{range1}-{range2}".format(range1=cint(self.filters["range1"])+ 1, range2=self.filters["range2"]),
+			"{range2}-{range3}".format(range2=cint(self.filters["range2"])+ 1, range3=self.filters["range3"]),
+			"{range3}-{above}".format(range3=cint(self.filters["range3"])+ 1, above=_("Above"))):
+				frappe.errprint(label)
 				columns.append({
 					"label": label,
 					"fieldtype": "Currency",
@@ -93,9 +94,10 @@
 		data = []
 		for gle in self.get_entries_till(self.filters.report_date, args.get("party_type")):
 			if self.is_receivable_or_payable(gle, dr_or_cr, future_vouchers):
-				outstanding_amount = self.get_outstanding_amount(gle, self.filters.report_date, dr_or_cr)
+				outstanding_amount = flt(self.get_outstanding_amount(gle, 
+					self.filters.report_date, dr_or_cr), currency_precision)
+					
 				if abs(outstanding_amount) > 0.1/10**currency_precision:
-
 					row = [gle.posting_date, gle.party]
 
 					# customer / supplier name
@@ -227,7 +229,7 @@
 				account_currency, remarks, {0}
 				from `tabGL Entry`
 				where docstatus < 2 and party_type=%s and (party is not null and party != '') {1}
-				group by voucher_type, voucher_no, against_voucher_type, against_voucher
+				group by voucher_type, voucher_no, against_voucher_type, against_voucher, party
 				order by posting_date, party"""
 				.format(select_fields, conditions), values, as_dict=True)
 
diff --git a/erpnext/controllers/trends.py b/erpnext/controllers/trends.py
index 080d749..d991c15 100644
--- a/erpnext/controllers/trends.py
+++ b/erpnext/controllers/trends.py
@@ -49,10 +49,10 @@
 		posting_date = 't1.posting_date'
 
 	if conditions["based_on_select"] in ["t1.project,", "t2.project,"]:
-		cond = 'and '+ conditions["based_on_select"][:-1] +' IS Not NULL'
+		cond = ' and '+ conditions["based_on_select"][:-1] +' IS Not NULL'
 	
 	if conditions.get('trans') in ['Sales Order', 'Purchase Order']:
-		cond += "and t1.status != 'Closed'"
+		cond += " and t1.status != 'Closed'"
 
 	year_start_date, year_end_date = frappe.db.get_value("Fiscal Year",
 		filters.get('fiscal_year'), ["year_start_date", "year_end_date"])
diff --git a/erpnext/setup/doctype/sales_partner/sales_partner.js b/erpnext/setup/doctype/sales_partner/sales_partner.js
index cb66b7f..143bf44 100644
--- a/erpnext/setup/doctype/sales_partner/sales_partner.js
+++ b/erpnext/setup/doctype/sales_partner/sales_partner.js
@@ -12,9 +12,3 @@
 		erpnext.utils.render_address_and_contact(cur_frm);
 	}
 }
-
-cur_frm.fields_dict['targets'].grid.get_field("item_group").get_query = function(doc, dt, dn) {
-  return{
-  	filters:{ 'is_group': 0 }
-  }
-}
diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py
index 0be2bae..06df636 100644
--- a/erpnext/stock/doctype/material_request/material_request.py
+++ b/erpnext/stock/doctype/material_request/material_request.py
@@ -75,7 +75,7 @@
 		pc_obj = frappe.get_doc('Purchase Common')
 		pc_obj.validate_for_items(self)
 
-		self.set_title()
+		# self.set_title()
 
 
 		# self.validate_qty_against_so()
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index a9d978a..0d3d7b8 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -356,6 +356,7 @@
 }
 
 cur_frm.cscript.purpose = function(doc, cdt, cdn) {
+	cur_frm.fields_dict.items.grid.refresh();
 	cur_frm.cscript.toggle_related_fields(doc);
 }
 
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 1e3bd8a..e5dd735 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -328,10 +328,11 @@
 
 @frappe.whitelist()
 def get_pos_profile(company):
+	condition = "and company = '%s'"%(company) if company else ''
 	pos_profile = frappe.db.sql("""select * from `tabPOS Profile` where user = %s
-		and company = %s""", (frappe.session['user'], company), as_dict=1)
+		{cond}""".format(cond=condition), (frappe.session['user']), as_dict=1)
 
-	if not pos_profile:
+	if not pos_profile and company:
 		pos_profile = frappe.db.sql("""select * from `tabPOS Profile`
 			where ifnull(user,'') = '' and company = %s""", company, as_dict=1)
 
diff --git a/erpnext/support/doctype/warranty_claim/warranty_claim.js b/erpnext/support/doctype/warranty_claim/warranty_claim.js
index cf9d806..9fed265 100644
--- a/erpnext/support/doctype/warranty_claim/warranty_claim.js
+++ b/erpnext/support/doctype/warranty_claim/warranty_claim.js
@@ -37,7 +37,7 @@
 
 cur_frm.cscript.onload = function(doc,cdt,cdn){
 	if(!doc.status)
-		set_multiple(dt,dn,{status:'Open'});
+		set_multiple(cdt,cdn,{status:'Open'});
 }
 
 cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
diff --git a/erpnext/templates/print_formats/includes/item_table_description.html b/erpnext/templates/print_formats/includes/item_table_description.html
index e8a98f0..16e98e0 100644
--- a/erpnext/templates/print_formats/includes/item_table_description.html
+++ b/erpnext/templates/print_formats/includes/item_table_description.html
@@ -3,8 +3,7 @@
 
 {% if doc.in_format_data("image") and doc.get("image") and not doc.is_print_hide("image")-%}
 <div class="pull-left" style="width: 20%; margin-right: 10px;">
-	<div class="square-image" style="background-image: url('{{ doc.image }}')">
-	</div>
+	<img class="print-item-image" src="{{ doc.image }}" alt="">
 </div>
 {%- endif %}