[fix] [report] sales/purchase register: if income/expense account entered in tax table for discount

This commit is contained in:
Nabin Hait 2013-07-16 12:11:00 +05:30
parent 8faa90fb20
commit 642634f6c8
2 changed files with 51 additions and 43 deletions

View File

@ -23,7 +23,7 @@ def execute(filters=None):
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 @@ def execute(filters=None):
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 @@ def execute(filters=None):
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 @@ def get_columns(invoice_list):
"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 @@ def get_columns(invoice_list):
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 @@ def get_columns(invoice_list):
["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_conditions(filters):
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 @@ def get_invoice_expense_map(invoice_list):
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,

View File

@ -23,14 +23,14 @@ def execute(filters=None):
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 @@ def execute(filters=None):
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 @@ def get_columns(invoice_list):
]
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 @@ def get_columns(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 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_conditions(filters):
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 @@ def get_invoice_income_map(invoice_list):
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