mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-22 11:44:11 +00:00
feat(reports): preserve accounting dimension filters while navigating between reports
(cherry picked from commit fcfcaa76c6)
This commit is contained in:
@@ -15,6 +15,7 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
|||||||
get_accounting_dimensions,
|
get_accounting_dimensions,
|
||||||
get_dimension_with_children,
|
get_dimension_with_children,
|
||||||
)
|
)
|
||||||
|
from erpnext.accounts.report.financial_statements import get_cost_centers_with_children
|
||||||
from erpnext.accounts.utils import (
|
from erpnext.accounts.utils import (
|
||||||
build_qb_match_conditions,
|
build_qb_match_conditions,
|
||||||
get_advance_payment_doctypes,
|
get_advance_payment_doctypes,
|
||||||
@@ -994,11 +995,7 @@ class ReceivablePayableReport:
|
|||||||
self.add_accounting_dimensions_filters()
|
self.add_accounting_dimensions_filters()
|
||||||
|
|
||||||
def get_cost_center_conditions(self):
|
def get_cost_center_conditions(self):
|
||||||
lft, rgt = frappe.db.get_value("Cost Center", self.filters.cost_center, ["lft", "rgt"])
|
cost_center_list = get_cost_centers_with_children(self.filters.cost_center)
|
||||||
cost_center_list = [
|
|
||||||
center.name
|
|
||||||
for center in frappe.get_list("Cost Center", filters={"lft": (">=", lft), "rgt": ("<=", rgt)})
|
|
||||||
]
|
|
||||||
self.qb_selection_filter.append(self.ple.cost_center.isin(cost_center_list))
|
self.qb_selection_filter.append(self.ple.cost_center.isin(cost_center_list))
|
||||||
|
|
||||||
def add_common_filters(self):
|
def add_common_filters(self):
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
|||||||
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,
|
||||||
|
get_cost_centers_with_children,
|
||||||
set_gl_entries_by_account,
|
set_gl_entries_by_account,
|
||||||
)
|
)
|
||||||
from erpnext.accounts.report.utils import convert_to_presentation_currency, get_currency
|
from erpnext.accounts.report.utils import convert_to_presentation_currency, get_currency
|
||||||
@@ -103,10 +104,6 @@ def get_data(filters):
|
|||||||
|
|
||||||
opening_balances = get_opening_balances(filters, ignore_is_opening)
|
opening_balances = get_opening_balances(filters, ignore_is_opening)
|
||||||
|
|
||||||
# add filter inside list so that the query in financial_statements.py doesn't break
|
|
||||||
if filters.project:
|
|
||||||
filters.project = [filters.project]
|
|
||||||
|
|
||||||
set_gl_entries_by_account(
|
set_gl_entries_by_account(
|
||||||
filters.company,
|
filters.company,
|
||||||
filters.from_date,
|
filters.from_date,
|
||||||
@@ -270,18 +267,12 @@ def get_opening_balance(
|
|||||||
opening_balance = opening_balance.where(closing_balance.voucher_type != "Period Closing Voucher")
|
opening_balance = opening_balance.where(closing_balance.voucher_type != "Period Closing Voucher")
|
||||||
|
|
||||||
if filters.cost_center:
|
if filters.cost_center:
|
||||||
lft, rgt = frappe.db.get_value("Cost Center", filters.cost_center, ["lft", "rgt"])
|
|
||||||
cost_center = frappe.qb.DocType("Cost Center")
|
|
||||||
opening_balance = opening_balance.where(
|
opening_balance = opening_balance.where(
|
||||||
closing_balance.cost_center.isin(
|
closing_balance.cost_center.isin(get_cost_centers_with_children(filters.get("cost_center")))
|
||||||
frappe.qb.from_(cost_center)
|
|
||||||
.select("name")
|
|
||||||
.where((cost_center.lft >= lft) & (cost_center.rgt <= rgt))
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if filters.project:
|
if filters.project:
|
||||||
opening_balance = opening_balance.where(closing_balance.project == filters.project)
|
opening_balance = opening_balance.where(closing_balance.project.isin(filters.project))
|
||||||
|
|
||||||
if frappe.db.count("Finance Book"):
|
if frappe.db.count("Finance Book"):
|
||||||
if filters.get("include_default_book_entries"):
|
if filters.get("include_default_book_entries"):
|
||||||
|
|||||||
@@ -79,18 +79,35 @@ erpnext.financial_statements = {
|
|||||||
},
|
},
|
||||||
open_general_ledger: function (data) {
|
open_general_ledger: function (data) {
|
||||||
if (!data.account && !data.accounts) return;
|
if (!data.account && !data.accounts) return;
|
||||||
let project = $.grep(frappe.query_report.filters, function (e) {
|
let filters = frappe.query_report.filters;
|
||||||
|
|
||||||
|
let project = $.grep(filters, function (e) {
|
||||||
return e.df.fieldname == "project";
|
return e.df.fieldname == "project";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let cost_center = $.grep(filters, function (e) {
|
||||||
|
return e.df.fieldname == "cost_center";
|
||||||
|
});
|
||||||
|
|
||||||
frappe.route_options = {
|
frappe.route_options = {
|
||||||
account: data.account || data.accounts,
|
account: data.account || data.accounts,
|
||||||
company: frappe.query_report.get_filter_value("company"),
|
company: frappe.query_report.get_filter_value("company"),
|
||||||
from_date: data.from_date || data.year_start_date,
|
from_date: data.from_date || data.year_start_date,
|
||||||
to_date: data.to_date || data.year_end_date,
|
to_date: data.to_date || data.year_end_date,
|
||||||
project: project && project.length > 0 ? project[0].$input.val() : "",
|
project: project && project.length > 0 ? project[0].get_value() : "",
|
||||||
|
cost_center: cost_center && cost_center.length > 0 ? cost_center[0].get_value() : "",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
filters.forEach((f) => {
|
||||||
|
if (f.df.fieldtype == "MultiSelectList") {
|
||||||
|
if (f.df.fieldname in frappe.route_options) return;
|
||||||
|
let value = f.get_value();
|
||||||
|
if (value && value.length > 0) {
|
||||||
|
frappe.route_options[f.df.fieldname] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let report = "General Ledger";
|
let report = "General Ledger";
|
||||||
|
|
||||||
if (["Payable", "Receivable"].includes(data.account_type)) {
|
if (["Payable", "Receivable"].includes(data.account_type)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user