Skip to content

Commit

Permalink
fix: fetch acc dimension fieldname
Browse files Browse the repository at this point in the history
(cherry picked from commit 1c5c310)
  • Loading branch information
GursheenK authored and mergify[bot] committed Jul 25, 2023
1 parent 1fe6d4e commit 542c804
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from frappe import _
from frappe.utils import cstr, flt

from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_dimensions
from erpnext.accounts.report.financial_statements import (
filter_accounts,
filter_out_zero_value_rows,
Expand All @@ -19,7 +20,9 @@ def execute(filters=None):
if filters.get("based_on") == "Accounting Dimension" and not filters.get("accounting_dimension"):
frappe.throw(_("Select Accounting Dimension."))

based_on = filters.based_on.replace(" ", "_").lower()
based_on = (
filters.based_on if filters.based_on != "Accounting Dimension" else filters.accounting_dimension
)
validate_filters(filters)
accounts = get_accounts_data(based_on, filters.get("company"))
data = get_data(accounts, filters, based_on)
Expand All @@ -28,17 +31,15 @@ def execute(filters=None):


def get_accounts_data(based_on, company):
if based_on == "cost_center":
if based_on == "Cost Center":
return frappe.db.sql(
"""select name, parent_cost_center as parent_account, cost_center_name as account_name, lft, rgt
from `tabCost Center` where company=%s order by name""",
company,
as_dict=True,
)
elif based_on == "project":
elif based_on == "Project":
return frappe.get_all("Project", fields=["name"], filters={"company": company}, order_by="name")
elif based_on == "accounting_dimension":
return frappe.get_all("Accounting Dimension", fields=["name"], order_by="name")
else:
filters = {}
doctype = frappe.unscrub(based_on)
Expand All @@ -58,13 +59,17 @@ def get_data(accounts, filters, based_on):

gl_entries_by_account = {}

accounting_dimensions = get_dimensions(with_cost_center_and_project=True)[0]
fieldname = ""
for dimension in accounting_dimensions:
if dimension["document_type"] == based_on:
fieldname = dimension["fieldname"]

set_gl_entries_by_account(
filters.get("company"),
filters.get("from_date"),
filters.get("to_date"),
based_on
if based_on != "accounting_dimension"
else filters.accounting_dimension.replace(" ", "_").lower(),
fieldname,
gl_entries_by_account,
ignore_closing_entries=not flt(filters.get("with_period_closing_entry")),
)
Expand Down

0 comments on commit 542c804

Please sign in to comment.