[fixes] sales/purchase register
diff --git a/accounts/report/purchase_register/purchase_register.py b/accounts/report/purchase_register/purchase_register.py
index c131c17..d4f2392 100644
--- a/accounts/report/purchase_register/purchase_register.py
+++ b/accounts/report/purchase_register/purchase_register.py
@@ -20,9 +20,10 @@
 
 def execute(filters=None):
 	if not filters: filters = {}
-	columns, expense_accounts, tax_accounts = get_columns()
-	
+
 	invoice_list = get_invoices(filters)
+	columns, expense_accounts, tax_accounts = get_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)
@@ -55,7 +56,7 @@
 	return columns, data
 	
 	
-def get_columns():
+def get_columns(invoice_list):
 	"""return columns based on filters"""
 	columns = [
 		"Invoice:Link/Purchase Invoice:120", "Posting Date:Date:80", "Supplier:Link/Supplier:120", 
@@ -66,10 +67,14 @@
 	
 	expense_accounts = webnotes.conn.sql_list("""select distinct expense_head 
 		from `tabPurchase Invoice Item` where docstatus = 1 and ifnull(expense_head, '') != '' 
-		order by 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, '') != '' order by account_head""")
+		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] + \
diff --git a/accounts/report/sales_register/sales_register.py b/accounts/report/sales_register/sales_register.py
index 23d2227..b150974 100644
--- a/accounts/report/sales_register/sales_register.py
+++ b/accounts/report/sales_register/sales_register.py
@@ -20,9 +20,10 @@
 
 def execute(filters=None):
 	if not filters: filters = {}
-	columns, income_accounts, tax_accounts = get_columns()
 	
 	invoice_list = get_invoices(filters)
+	columns, income_accounts, tax_accounts = get_columns(invoice_list)
+	
 	invoice_income_map = get_invoice_income_map(invoice_list)
 	invoice_tax_map = get_invoice_tax_map(invoice_list)
 	
@@ -59,7 +60,7 @@
 	return columns, data
 	
 	
-def get_columns():
+def get_columns(invoice_list):
 	"""return columns based on filters"""
 	columns = [
 		"Invoice:Link/Sales Invoice:120", "Posting Date:Date:80", "Customer:Link/Customer:120", 
@@ -69,11 +70,14 @@
 	]
 	
 	income_accounts = webnotes.conn.sql_list("""select distinct income_account 
-		from `tabSales Invoice Item` where docstatus = 1 order by 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 order by account_head""")
+		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] + \