Merge pull request #36107 from GursheenK/accounting_dimension_in_based_on_filter
feat: filtering based on accounting dimensions in profitability analysis
This commit is contained in:
commit
61be373800
@ -16,9 +16,30 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() {
|
|||||||
"fieldname": "based_on",
|
"fieldname": "based_on",
|
||||||
"label": __("Based On"),
|
"label": __("Based On"),
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"options": ["Cost Center", "Project"],
|
"options": ["Cost Center", "Project", "Accounting Dimension"],
|
||||||
"default": "Cost Center",
|
"default": "Cost Center",
|
||||||
"reqd": 1
|
"reqd": 1,
|
||||||
|
"on_change": function(query_report){
|
||||||
|
let based_on = query_report.get_values().based_on;
|
||||||
|
if(based_on!='Accounting Dimension'){
|
||||||
|
frappe.query_report.set_filter_value({
|
||||||
|
accounting_dimension: ''
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "accounting_dimension",
|
||||||
|
"label": __("Accounting Dimension"),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Accounting Dimension",
|
||||||
|
"get_query": () =>{
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
"disabled": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "fiscal_year",
|
"fieldname": "fiscal_year",
|
||||||
|
@ -6,6 +6,7 @@ import frappe
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import cstr, flt
|
from frappe.utils import cstr, flt
|
||||||
|
|
||||||
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_dimensions
|
||||||
from erpnext.accounts.report.financial_statements import (
|
from erpnext.accounts.report.financial_statements import (
|
||||||
filter_accounts,
|
filter_accounts,
|
||||||
filter_out_zero_value_rows,
|
filter_out_zero_value_rows,
|
||||||
@ -16,10 +17,12 @@ value_fields = ("income", "expense", "gross_profit_loss")
|
|||||||
|
|
||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters.get("based_on"):
|
if filters.get("based_on") == "Accounting Dimension" and not filters.get("accounting_dimension"):
|
||||||
filters["based_on"] = "Cost Center"
|
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)
|
validate_filters(filters)
|
||||||
accounts = get_accounts_data(based_on, filters.get("company"))
|
accounts = get_accounts_data(based_on, filters.get("company"))
|
||||||
data = get_data(accounts, filters, based_on)
|
data = get_data(accounts, filters, based_on)
|
||||||
@ -28,14 +31,14 @@ def execute(filters=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_accounts_data(based_on, company):
|
def get_accounts_data(based_on, company):
|
||||||
if based_on == "cost_center":
|
if based_on == "Cost Center":
|
||||||
return frappe.db.sql(
|
return frappe.db.sql(
|
||||||
"""select name, parent_cost_center as parent_account, cost_center_name as account_name, lft, rgt
|
"""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""",
|
from `tabCost Center` where company=%s order by name""",
|
||||||
company,
|
company,
|
||||||
as_dict=True,
|
as_dict=True,
|
||||||
)
|
)
|
||||||
elif based_on == "project":
|
elif based_on == "Project":
|
||||||
return frappe.get_all("Project", fields=["name"], filters={"company": company}, order_by="name")
|
return frappe.get_all("Project", fields=["name"], filters={"company": company}, order_by="name")
|
||||||
else:
|
else:
|
||||||
filters = {}
|
filters = {}
|
||||||
@ -56,11 +59,17 @@ def get_data(accounts, filters, based_on):
|
|||||||
|
|
||||||
gl_entries_by_account = {}
|
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(
|
set_gl_entries_by_account(
|
||||||
filters.get("company"),
|
filters.get("company"),
|
||||||
filters.get("from_date"),
|
filters.get("from_date"),
|
||||||
filters.get("to_date"),
|
filters.get("to_date"),
|
||||||
based_on,
|
fieldname,
|
||||||
gl_entries_by_account,
|
gl_entries_by_account,
|
||||||
ignore_closing_entries=not flt(filters.get("with_period_closing_entry")),
|
ignore_closing_entries=not flt(filters.get("with_period_closing_entry")),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user