[fix] [report] sales/purchase register: if income/expense account entered in tax table for discount
diff --git a/accounts/report/purchase_register/purchase_register.py b/accounts/report/purchase_register/purchase_register.py
index 705a654..0970541 100644
--- a/accounts/report/purchase_register/purchase_register.py
+++ b/accounts/report/purchase_register/purchase_register.py
@@ -23,7 +23,7 @@
if not filters: filters = {}
invoice_list = get_invoices(filters)
- columns, expense_accounts, tax_accounts, renamed_columns = get_columns(invoice_list)
+ columns, expense_accounts, tax_accounts = get_columns(invoice_list)
if not invoice_list:
@@ -31,7 +31,7 @@
return columns, invoice_list
invoice_expense_map = get_invoice_expense_map(invoice_list)
- invoice_tax_map = get_invoice_tax_map(invoice_list, renamed_columns)
+ invoice_expense_map, invoice_tax_map = get_invoice_tax_map(invoice_list, invoice_expense_map)
invoice_po_pr_map = get_invoice_po_pr_map(invoice_list)
account_map = get_account_details(invoice_list)
@@ -47,20 +47,27 @@
inv.remarks, ", ".join(purchase_order), ", ".join(purchase_receipt)]
# map expense values
+ net_total = 0
for expense_acc in expense_accounts:
- row.append(invoice_expense_map.get(inv.name, {}).get(expense_acc))
+ expense_amount = flt(invoice_expense_map.get(inv.name, {}).get(expense_acc))
+ net_total += expense_amount
+ row.append(expense_amount)
# net total
- row.append(inv.net_total)
+ row.append(net_total)
# tax account
+ total_tax = 0
for tax_acc in tax_accounts:
- row.append(invoice_tax_map.get(inv.name, {}).get(tax_acc))
+ if tax_acc not in expense_accounts:
+ tax_amount = flt(invoice_tax_map.get(inv.name, {}).get(tax_acc))
+ total_tax += tax_amount
+ row.append(tax_amount)
# total tax, grand total, outstanding amount & rounded total
- row += [inv.total_tax, inv.grand_total, flt(inv.grand_total, 2), \
- inv.outstanding_amount]
+ row += [total_tax, inv.grand_total, flt(inv.grand_total, 2), inv.outstanding_amount]
data.append(row)
+ # raise Exception
return columns, data
@@ -74,7 +81,6 @@
"Purchase Order:Link/Purchase Order:100", "Purchase Receipt:Link/Purchase Receipt:100"
]
expense_accounts = tax_accounts = expense_columns = tax_columns = []
- renamed_columns = {}
if invoice_list:
expense_accounts = webnotes.conn.sql_list("""select distinct expense_head
@@ -91,11 +97,7 @@
expense_columns = [(account + ":Currency:120") for account in expense_accounts]
for account in tax_accounts:
- if account in expense_accounts:
- new_account = account + " (Tax)"
- renamed_columns[account] = new_account
- tax_columns.append(new_account + ":Currency:120")
- else:
+ if account not in expense_accounts:
tax_columns.append(account + ":Currency:120")
columns = columns + expense_columns + \
@@ -103,7 +105,7 @@
["Total Tax:Currency:120"] + ["Grand Total:Currency:120"] + \
["Rounded Total:Currency:120"] + ["Outstanding Amount:Currency:120"]
- return columns, expense_accounts, tax_accounts, renamed_columns
+ return columns, expense_accounts, tax_accounts
def get_conditions(filters):
conditions = ""
@@ -119,7 +121,7 @@
def get_invoices(filters):
conditions = get_conditions(filters)
return webnotes.conn.sql("""select name, posting_date, credit_to, supplier, supplier_name,
- bill_no, bill_date, remarks, net_total, total_tax, grand_total, outstanding_amount
+ bill_no, bill_date, remarks, grand_total, outstanding_amount
from `tabPurchase Invoice` where docstatus = 1 %s
order by posting_date desc, name desc""" % conditions, filters, as_dict=1)
@@ -136,18 +138,20 @@
return invoice_expense_map
-def get_invoice_tax_map(invoice_list, renamed_columns):
+def get_invoice_tax_map(invoice_list, invoice_expense_map):
tax_details = webnotes.conn.sql("""select parent, account_head, sum(tax_amount) as tax_amount
from `tabPurchase Taxes and Charges` where parent in (%s) group by parent, account_head""" %
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)
invoice_tax_map = {}
for d in tax_details:
- account = renamed_columns.get(d.account_head) or d.account_head
- invoice_tax_map.setdefault(d.parent, webnotes._dict()).setdefault(account, [])
- invoice_tax_map[d.parent][account] = flt(d.tax_amount)
+ if d.account_head in invoice_expense_map.get(d.parent):
+ invoice_expense_map[d.parent][d.account_head] += flt(d.tax_amount)
+ else:
+ invoice_tax_map.setdefault(d.parent, webnotes._dict()).setdefault(d.account_head, [])
+ invoice_tax_map[d.parent][d.account_head] = flt(d.tax_amount)
- return invoice_tax_map
+ return invoice_expense_map, invoice_tax_map
def get_invoice_po_pr_map(invoice_list):
pi_items = webnotes.conn.sql("""select parent, purchase_order, purchase_receipt,
diff --git a/accounts/report/sales_register/sales_register.py b/accounts/report/sales_register/sales_register.py
index 2bc2850..91ad1c2 100644
--- a/accounts/report/sales_register/sales_register.py
+++ b/accounts/report/sales_register/sales_register.py
@@ -23,14 +23,14 @@
if not filters: filters = {}
invoice_list = get_invoices(filters)
- columns, income_accounts, tax_accounts, renamed_columns = get_columns(invoice_list)
+ columns, income_accounts, tax_accounts = get_columns(invoice_list)
if not invoice_list:
- msgprint(_("No record found"))
+ 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, renamed_columns)
+ invoice_income_map, invoice_tax_map = get_invoice_tax_map(invoice_list, invoice_income_map)
invoice_so_dn_map = get_invoice_so_dn_map(invoice_list)
customer_map = get_customer_deatils(invoice_list)
@@ -47,18 +47,25 @@
inv.remarks, ", ".join(sales_order), ", ".join(delivery_note)]
# map income values
+ net_total = 0
for income_acc in income_accounts:
- row.append(invoice_income_map.get(inv.name, {}).get(income_acc))
+ income_amount = flt(invoice_income_map.get(inv.name, {}).get(income_acc))
+ net_total += income_amount
+ row.append(income_amount)
# net total
- row.append(inv.net_total)
+ row.append(net_total)
# tax account
+ total_tax = 0
for tax_acc in tax_accounts:
- row.append(invoice_tax_map.get(inv.name, {}).get(tax_acc))
+ if tax_acc not in income_accounts:
+ tax_amount = flt(invoice_tax_map.get(inv.name, {}).get(tax_acc))
+ total_tax += tax_amount
+ row.append(tax_amount)
# total tax, grand total, outstanding amount & rounded total
- row += [inv.other_charges_total, inv.grand_total, inv.rounded_total, inv.outstanding_amount]
+ row += [total_tax, inv.grand_total, inv.rounded_total, inv.outstanding_amount]
data.append(row)
@@ -75,7 +82,6 @@
]
income_accounts = tax_accounts = income_columns = tax_columns = []
- renamed_columns = {}
if invoice_list:
income_accounts = webnotes.conn.sql_list("""select distinct income_account
@@ -85,24 +91,20 @@
tax_accounts = webnotes.conn.sql_list("""select distinct account_head
from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice'
- and docstatus = 1 and ifnull(tax_amount, 0) > 0
+ and docstatus = 1 and ifnull(tax_amount, 0) != 0
and parent in (%s) order by account_head""" %
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
-
+
income_columns = [(account + ":Currency:120") for account in income_accounts]
for account in tax_accounts:
- if account in income_accounts:
- new_account = account + " (Tax)"
- renamed_columns[account] = new_account
- tax_columns.append(new_account + ":Currency:120")
- else:
+ if account not in income_accounts:
tax_columns.append(account + ":Currency:120")
columns = columns + income_columns + ["Net Total:Currency:120"] + tax_columns + \
["Total Tax:Currency:120"] + ["Grand Total:Currency:120"] + \
["Rounded Total:Currency:120"] + ["Outstanding Amount:Currency:120"]
- return columns, income_accounts, tax_accounts, renamed_columns
+ return columns, income_accounts, tax_accounts
def get_conditions(filters):
conditions = ""
@@ -118,8 +120,8 @@
def get_invoices(filters):
conditions = get_conditions(filters)
return webnotes.conn.sql("""select name, posting_date, debit_to, project_name, customer,
- customer_name, remarks, net_total, other_charges_total, grand_total, rounded_total,
- outstanding_amount from `tabSales Invoice`
+ customer_name, remarks, grand_total, rounded_total, outstanding_amount
+ from `tabSales Invoice`
where docstatus = 1 %s order by posting_date desc, name desc""" %
conditions, filters, as_dict=1)
@@ -135,18 +137,20 @@
return invoice_income_map
-def get_invoice_tax_map(invoice_list, renamed_columns):
+def get_invoice_tax_map(invoice_list, invoice_income_map):
tax_details = webnotes.conn.sql("""select parent, account_head, sum(tax_amount) as tax_amount
from `tabSales Taxes and Charges` where parent in (%s) group by parent, account_head""" %
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)
invoice_tax_map = {}
for d in tax_details:
- account = renamed_columns.get(d.account_head) or d.account_head
- invoice_tax_map.setdefault(d.parent, webnotes._dict()).setdefault(account, [])
- invoice_tax_map[d.parent][account] = flt(d.tax_amount)
+ if d.account_head in invoice_income_map.get(d.parent):
+ invoice_income_map[d.parent][d.account_head] += flt(d.tax_amount)
+ else:
+ invoice_tax_map.setdefault(d.parent, webnotes._dict()).setdefault(d.account_head, [])
+ invoice_tax_map[d.parent][d.account_head] = flt(d.tax_amount)
- return invoice_tax_map
+ return invoice_income_map, invoice_tax_map
def get_invoice_so_dn_map(invoice_list):
si_items = webnotes.conn.sql("""select parent, sales_order, delivery_note