mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 03:39:11 +00:00
fix: Change & simplify query to cater for zero rate tax entries
This commit is contained in:
@@ -6,16 +6,15 @@ from __future__ import unicode_literals
|
|||||||
import frappe, json
|
import frappe, json
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
|
||||||
# NOTE: Payroll is implemented using Journal Entries
|
# NOTE: Payroll is implemented using Journal Entries which translate directly to GL Entries
|
||||||
|
|
||||||
# field lists in multiple doctypes will be coalesced
|
# field lists in multiple doctypes will be coalesced
|
||||||
required_sql_fields = {
|
required_sql_fields = {
|
||||||
"GL Entry": ["posting_date", "voucher_type", "voucher_no", "account as tax_account", "account_currency", "debit", "credit"],
|
("GL Entry", 1): ["posting_date"],
|
||||||
"Journal Entry Account": ["account_type", "account", "debit_in_account_currency", "credit_in_account_currency"],
|
("Account",): ["account_type"],
|
||||||
("Purchase Invoice Item", "Sales Invoice Item"): ["base_net_amount", "item_tax_rate", "item_tax_template", "item_name"],
|
("GL Entry", 2): ["account", "voucher_type", "voucher_no", "debit", "credit"],
|
||||||
|
("Purchase Invoice Item", "Sales Invoice Item"): ["base_net_amount", "item_tax_rate", "item_tax_template", "item_group", "item_name"],
|
||||||
("Purchase Invoice", "Sales Invoice"): ["taxes_and_charges", "tax_category"],
|
("Purchase Invoice", "Sales Invoice"): ["taxes_and_charges", "tax_category"],
|
||||||
"Purchase Invoice Item": ["expense_account"],
|
|
||||||
"Sales Invoice Item": ["income_account"]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -34,15 +33,12 @@ def execute(filters=None):
|
|||||||
left join `tabSales Invoice` si on
|
left join `tabSales Invoice` si on
|
||||||
ge.company=si.company and ge.voucher_type='Sales Invoice' and ge.voucher_no=si.name
|
ge.company=si.company and ge.voucher_type='Sales Invoice' and ge.voucher_no=si.name
|
||||||
left join `tabSales Invoice Item` sii on
|
left join `tabSales Invoice Item` sii on
|
||||||
si.name=sii.parent
|
a.root_type='Income' and si.name=sii.parent
|
||||||
left join `tabPurchase Invoice` pi on
|
left join `tabPurchase Invoice` pi on
|
||||||
ge.company=pi.company and ge.voucher_type='Purchase Invoice' and ge.voucher_no=pi.name
|
ge.company=pi.company and ge.voucher_type='Purchase Invoice' and ge.voucher_no=pi.name
|
||||||
left join `tabPurchase Invoice Item` pii on
|
left join `tabPurchase Invoice Item` pii on
|
||||||
pi.name=pii.parent
|
a.root_type='Expense' and pi.name=pii.parent
|
||||||
left join `tabJournal Entry Account` jea on
|
|
||||||
ge.voucher_type=jea.parenttype and ge.voucher_no=jea.parent
|
|
||||||
where
|
where
|
||||||
a.account_type='Tax' and
|
|
||||||
ge.company=%(company)s and
|
ge.company=%(company)s and
|
||||||
ge.posting_date>=%(from_date)s and
|
ge.posting_date>=%(from_date)s and
|
||||||
ge.posting_date<=%(to_date)s
|
ge.posting_date<=%(to_date)s
|
||||||
@@ -151,19 +147,18 @@ def coalesce(doctypes, fields):
|
|||||||
def get_fieldstr(fieldlist):
|
def get_fieldstr(fieldlist):
|
||||||
fields = []
|
fields = []
|
||||||
for doctypes, docfields in fieldlist.items():
|
for doctypes, docfields in fieldlist.items():
|
||||||
if isinstance(doctypes, str):
|
if len(doctypes) == 1 or isinstance(doctypes[1], int):
|
||||||
fields += doclist(doctypes, docfields)
|
fields += doclist(doctypes[0], docfields)
|
||||||
if isinstance(doctypes, tuple):
|
else:
|
||||||
fields += coalesce(doctypes, docfields)
|
fields += coalesce(doctypes, docfields)
|
||||||
return ', '.join(fields)
|
return ', '.join(fields)
|
||||||
|
|
||||||
def get_columns(fieldlist):
|
def get_columns(fieldlist):
|
||||||
columns = {}
|
columns = {}
|
||||||
for doctypes, docfields in fieldlist.items():
|
for doctypes, docfields in fieldlist.items():
|
||||||
if isinstance(doctypes, str):
|
|
||||||
doctypes = [doctypes]
|
|
||||||
fieldmap = {name: new_name for name, new_name in as_split(docfields)}
|
fieldmap = {name: new_name for name, new_name in as_split(docfields)}
|
||||||
for doctype in doctypes:
|
for doctype in doctypes:
|
||||||
|
if isinstance(doctype, int): break
|
||||||
meta = frappe.get_meta(doctype)
|
meta = frappe.get_meta(doctype)
|
||||||
# get column field metadata from the db
|
# get column field metadata from the db
|
||||||
fieldmeta = {}
|
fieldmeta = {}
|
||||||
@@ -186,29 +181,9 @@ def get_columns(fieldlist):
|
|||||||
|
|
||||||
def modify_report_columns(doctype, field, column):
|
def modify_report_columns(doctype, field, column):
|
||||||
"Because data is rearranged into other columns"
|
"Because data is rearranged into other columns"
|
||||||
if doctype in ["Sales Invoice Item", "Purchase Invoice Item"] and field == "item_tax_rate":
|
if doctype in ["Sales Invoice Item", "Purchase Invoice Item"]:
|
||||||
return None
|
if field in ["item_tax_rate", "base_net_amount"]:
|
||||||
if doctype == "GL Entry" and field == "tax_account":
|
return None
|
||||||
column.update({"label": _("Tax Account")})
|
|
||||||
if doctype == "GL Entry" and field == "debit":
|
|
||||||
column.update({"label": _("Tax Debit")})
|
|
||||||
if doctype == "GL Entry" and field == "credit":
|
|
||||||
column.update({"label": _("Tax Credit")})
|
|
||||||
|
|
||||||
if doctype == "Journal Entry Account" and field == "debit_in_account_currency":
|
|
||||||
column.update({"label": _("Debit Net Amount"), "fieldname": "debit_net_amount"})
|
|
||||||
if doctype == "Journal Entry Account" and field == "credit_in_account_currency":
|
|
||||||
column.update({"label": _("Credit Net Amount"), "fieldname": "credit_net_amount"})
|
|
||||||
|
|
||||||
if doctype == "Sales Invoice Item" and field == "base_net_amount":
|
|
||||||
column.update({"label": _("Credit Net Amount"), "fieldname": "credit_net_amount"})
|
|
||||||
if doctype == "Sales Invoice Item" and field == "income_account":
|
|
||||||
column.update({"label": _("Account"), "fieldname": "account"})
|
|
||||||
|
|
||||||
if doctype == "Purchase Invoice Item" and field == "base_net_amount":
|
|
||||||
column.update({"label": _("Debit Net Amount"), "fieldname": "debit_net_amount"})
|
|
||||||
if doctype == "Purchase Invoice Item" and field == "expense_account":
|
|
||||||
column.update({"label": _("Account"), "fieldname": "account"})
|
|
||||||
|
|
||||||
if field == "taxes_and_charges":
|
if field == "taxes_and_charges":
|
||||||
column.update({"label": _("Taxes and Charges Template")})
|
column.update({"label": _("Taxes and Charges Template")})
|
||||||
@@ -216,35 +191,28 @@ def modify_report_columns(doctype, field, column):
|
|||||||
|
|
||||||
def modify_report_data(data):
|
def modify_report_data(data):
|
||||||
import json
|
import json
|
||||||
|
new_data = []
|
||||||
for line in data:
|
for line in data:
|
||||||
# Transform Invoice lines
|
# Remove Invoice GL Tax Entries and generate Tax entries from the invoice lines
|
||||||
if "Invoice" in line.voucher_type:
|
if "Invoice" in line.voucher_type:
|
||||||
if line.income_account:
|
if line.account_type != "Tax":
|
||||||
line.account = line.income_account
|
new_data += [line]
|
||||||
line.account_type = "Income Account"
|
|
||||||
if line.expense_account:
|
|
||||||
line.account = line.expense_account
|
|
||||||
line.account_type = "Expense Account"
|
|
||||||
if line.item_tax_rate:
|
if line.item_tax_rate:
|
||||||
tax_rates = json.loads(line.item_tax_rate)
|
tax_rates = json.loads(line.item_tax_rate)
|
||||||
for account, rate in tax_rates.items():
|
for account, rate in tax_rates.items():
|
||||||
if account == line.tax_account:
|
tax_line = line.copy()
|
||||||
if line.voucher_type == "Sales Invoice":
|
tax_line.account_type = "Tax"
|
||||||
line.credit = line.base_net_amount * (rate / 100)
|
tax_line.account = account
|
||||||
line.credit_net_amount = line.base_net_amount
|
if line.voucher_type == "Sales Invoice":
|
||||||
if line.voucher_type == "Purchase Invoice":
|
line.credit = line.base_net_amount
|
||||||
line.debit = line.base_net_amount * (rate / 100)
|
tax_line.credit = line.base_net_amount * (rate / 100)
|
||||||
line.debit_net_amount = line.base_net_amount
|
if line.voucher_type == "Purchase Invoice":
|
||||||
# Transform Journal Entry lines
|
line.debit = line.base_net_amount
|
||||||
if "Journal" in line.voucher_type:
|
tax_line.debit = line.base_net_amount * (rate / 100)
|
||||||
if line.account_type != 'Tax':
|
new_data += [tax_line]
|
||||||
line.debit = 0.0
|
else:
|
||||||
line.credit = 0.0
|
new_data += [line]
|
||||||
if line.debit_in_account_currency:
|
return new_data
|
||||||
line.debit_net_amount = line.debit_in_account_currency
|
|
||||||
if line.credit_in_account_currency:
|
|
||||||
line.credit_net_amount = line.credit_in_account_currency
|
|
||||||
return data
|
|
||||||
|
|
||||||
####### JS client utilities
|
####### JS client utilities
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user