fix: Add filtesr for accounting dimensions in trial balance report

This commit is contained in:
deepeshgarg007 2019-07-03 18:08:41 +05:30
parent 1a6bfe986e
commit 58b4644c1a
2 changed files with 34 additions and 10 deletions

View File

@ -96,3 +96,16 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() {
}
});
let dimension_filters = erpnext.get_dimension_filters();
dimension_filters.then((dimensions) => {
dimensions.forEach((dimension) => {
frappe.query_reports["Trial Balance"].filters.splice(5, 0 ,{
"fieldname": dimension["fieldname"],
"label": __(dimension["label"]),
"fieldtype": "Link",
"options": dimension["document_type"]
});
});
});

View File

@ -7,6 +7,7 @@ from frappe import _
from frappe.utils import flt, getdate, formatdate, cstr
from erpnext.accounts.report.financial_statements \
import filter_accounts, set_gl_entries_by_account, filter_out_zero_value_rows
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
value_fields = ("opening_debit", "opening_credit", "debit", "credit", "closing_debit", "closing_credit")
@ -109,6 +110,25 @@ def get_rootwise_opening_balances(filters, report_type):
additional_conditions += fb_conditions
accounting_dimensions = get_accounting_dimensions()
query_filters = {
"company": filters.company,
"from_date": filters.from_date,
"report_type": report_type,
"year_start_date": filters.year_start_date,
"finance_book": filters.finance_book,
"company_fb": frappe.db.get_value("Company", filters.company, 'default_finance_book')
}
if accounting_dimensions:
for dimension in accounting_dimensions:
additional_conditions += """ and {0} in (%({0})s) """.format(dimension)
query_filters.update({
dimension: filters.get(dimension)
})
gle = frappe.db.sql("""
select
account, sum(debit) as opening_debit, sum(credit) as opening_credit
@ -118,16 +138,7 @@ def get_rootwise_opening_balances(filters, report_type):
{additional_conditions}
and (posting_date < %(from_date)s or ifnull(is_opening, 'No') = 'Yes')
and account in (select name from `tabAccount` where report_type=%(report_type)s)
group by account""".format(additional_conditions=additional_conditions),
{
"company": filters.company,
"from_date": filters.from_date,
"report_type": report_type,
"year_start_date": filters.year_start_date,
"finance_book": filters.finance_book,
"company_fb": frappe.db.get_value("Company", filters.company, 'default_finance_book')
},
as_dict=True)
group by account""".format(additional_conditions=additional_conditions), query_filters , as_dict=True)
opening = frappe._dict()
for d in gle: