Merge branch 'edge' of github.com:webnotes/erpnext into webshop
diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py
index 7f8ad63..7e18041 100644
--- a/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -306,7 +306,7 @@
 					against_accounts.append(stock_not_billed_account)
 			
 			elif not item.expense_head:
-				msgprint(_("""Expense account is mandatory for item: """) + item.item_code, 
+				msgprint(_("""Expense account is mandatory for item: """) + (item.item_code or item.item_name), 
 					raise_exception=1)
 			
 			elif item.expense_head not in against_accounts:
diff --git a/accounts/report/purchase_register/purchase_register.py b/accounts/report/purchase_register/purchase_register.py
index d4f2392..7c4b386 100644
--- a/accounts/report/purchase_register/purchase_register.py
+++ b/accounts/report/purchase_register/purchase_register.py
@@ -17,6 +17,7 @@
 from __future__ import unicode_literals
 import webnotes
 from webnotes.utils import flt
+from webnotes import msgprint, _
 
 def execute(filters=None):
 	if not filters: filters = {}
@@ -24,6 +25,11 @@
 	invoice_list = get_invoices(filters)
 	columns, expense_accounts, tax_accounts = get_columns(invoice_list)
 	
+	
+	if not invoice_list:
+		msgprint(_("No record found"))		
+		return columns, invoice_list
+	
 	invoice_expense_map = get_invoice_expense_map(invoice_list)
 	invoice_tax_map = get_invoice_tax_map(invoice_list)
 	invoice_po_pr_map = get_invoice_po_pr_map(invoice_list)
@@ -64,17 +70,18 @@
 		"Project:Link/Project:80", "Bill No::120", "Bill Date:Date:80", "Remarks::150", 
 		"Purchase Order:Link/Purchase Order:100", "Purchase Receipt:Link/Purchase Receipt:100"
 	]
-	
-	expense_accounts = webnotes.conn.sql_list("""select distinct expense_head 
-		from `tabPurchase Invoice Item` where docstatus = 1 and ifnull(expense_head, '') != '' 
-		and parent in (%s) order by expense_head""" % 
-		', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
+	expense_accounts = tax_accounts = []
+	if invoice_list:	
+		expense_accounts = webnotes.conn.sql_list("""select distinct expense_head 
+			from `tabPurchase Invoice Item` where docstatus = 1 and ifnull(expense_head, '') != '' 
+			and parent in (%s) order by expense_head""" % 
+			', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
 		
-	tax_accounts = 	webnotes.conn.sql_list("""select distinct account_head 
-		from `tabPurchase Taxes and Charges` where parenttype = 'Purchase Invoice' 
-		and docstatus = 1 and ifnull(account_head, '') != '' and parent in (%s) 
-		order by account_head""" % 
-		', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
+		tax_accounts = 	webnotes.conn.sql_list("""select distinct account_head 
+			from `tabPurchase Taxes and Charges` where parenttype = 'Purchase Invoice' 
+			and docstatus = 1 and ifnull(account_head, '') != '' and parent in (%s) 
+			order by account_head""" % 
+			', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
 	
 	columns = columns + [(account + ":Currency:120") for account in expense_accounts] + \
 		["Net Total:Currency:120"] + [(account + ":Currency:120") for account in tax_accounts] + \
@@ -86,7 +93,7 @@
 	conditions = ""
 	
 	if filters.get("company"): conditions += " and company=%(company)s"
-	if filters.get("account"): conditions += " and account = %(account)s"
+	if filters.get("account"): conditions += " and credit_to = %(account)s"
 
 	if filters.get("from_date"): conditions += " and posting_date>=%(from_date)s"
 	if filters.get("to_date"): conditions += " and posting_date<=%(to_date)s"
diff --git a/accounts/report/sales_register/sales_register.py b/accounts/report/sales_register/sales_register.py
index 3946f00..99057f9 100644
--- a/accounts/report/sales_register/sales_register.py
+++ b/accounts/report/sales_register/sales_register.py
@@ -17,6 +17,7 @@
 from __future__ import unicode_literals
 import webnotes
 from webnotes.utils import flt
+from webnotes import msgprint, _
 
 def execute(filters=None):
 	if not filters: filters = {}
@@ -24,6 +25,10 @@
 	invoice_list = get_invoices(filters)
 	columns, income_accounts, tax_accounts = get_columns(invoice_list)
 	
+	if not invoice_list:
+		msgprint(_("No record found"))		
+		return columns, invoice_list
+	
 	invoice_income_map = get_invoice_income_map(invoice_list)
 	invoice_tax_map = get_invoice_tax_map(invoice_list)
 	
@@ -69,15 +74,17 @@
 		"Remarks::150", "Sales Order:Link/Sales Order:100", "Delivery Note:Link/Delivery Note:100"
 	]
 	
-	income_accounts = webnotes.conn.sql_list("""select distinct income_account 
-		from `tabSales Invoice Item` where docstatus = 1 and parent in (%s) 
-		order by income_account""" % 
-		', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
+	income_accounts = tax_accounts = []
+	if invoice_list:
+		income_accounts = webnotes.conn.sql_list("""select distinct income_account 
+			from `tabSales Invoice Item` where docstatus = 1 and parent in (%s) 
+			order by income_account""" % 
+			', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
 	
-	tax_accounts = 	webnotes.conn.sql_list("""select distinct account_head 
-		from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice' 
-		and docstatus = 1 and parent in (%s) order by account_head""" % 
-		', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
+		tax_accounts = 	webnotes.conn.sql_list("""select distinct account_head 
+			from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice' 
+			and docstatus = 1 and parent in (%s) order by account_head""" % 
+			', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
 	
 	columns = columns + [(account + ":Currency:120") for account in income_accounts] + \
 		["Net Total:Currency:120"] + [(account + ":Currency:120") for account in tax_accounts] + \
@@ -89,19 +96,19 @@
 	conditions = ""
 	
 	if filters.get("company"): conditions += " and company=%(company)s"
-	if filters.get("account"): conditions += " and account = %(account)s"
+	if filters.get("account"): conditions += " and debit_to = %(account)s"
 
-	if filters.get("from_date"): conditions += " and posting_date>=%(from_date)s"
-	if filters.get("to_date"): conditions += " and posting_date<=%(to_date)s"
+	if filters.get("from_date"): conditions += " and posting_date >= %(from_date)s"
+	if filters.get("to_date"): conditions += " and posting_date <= %(to_date)s"
 
 	return conditions
 	
 def get_invoices(filters):
 	conditions = get_conditions(filters)
 	return webnotes.conn.sql("""select name, posting_date, debit_to, project_name, customer, 
-		remarks, net_total, other_charges_total, grand_total 
-		from `tabSales Invoice` where docstatus = 1 %s 
-		order by posting_date desc, name desc""" % conditions, filters, as_dict=1)
+		remarks, net_total, other_charges_total, grand_total from `tabSales Invoice` 
+		where docstatus = 1 %s order by posting_date desc, name desc""" % 
+		conditions, filters, as_dict=1)
 	
 def get_invoice_income_map(invoice_list):
 	income_details = webnotes.conn.sql("""select parent, income_account, sum(amount) as amount