From 92bc962f60adb3967a2ef378511822d53ff2f4a8 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 1 Jan 2024 14:46:15 +0530 Subject: [PATCH 1/2] fix: undefined error in Budget Variance and Profitability report 'Budget' and 'Budget Account' doesn't have support for dynamic dimension. It only supports hard-coded ones - Project and Cost Center --- .../report/budget_variance_report/budget_variance_report.js | 4 ---- .../report/profitability_analysis/profitability_analysis.js | 5 ----- 2 files changed, 9 deletions(-) diff --git a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js index 15aa265b56..15088335e5 100644 --- a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js +++ b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js @@ -88,7 +88,3 @@ frappe.query_reports["Budget Variance Report"] = { return value; } } - -erpnext.dimension_filters.forEach((dimension) => { - frappe.query_reports["Budget Variance Report"].filters[4].options.push(dimension["document_type"]); -}); diff --git a/erpnext/accounts/report/profitability_analysis/profitability_analysis.js b/erpnext/accounts/report/profitability_analysis/profitability_analysis.js index b6bbd979ed..5dd3617a92 100644 --- a/erpnext/accounts/report/profitability_analysis/profitability_analysis.js +++ b/erpnext/accounts/report/profitability_analysis/profitability_analysis.js @@ -117,8 +117,3 @@ frappe.query_reports["Profitability Analysis"] = { "parent_field": "parent_account", "initial_depth": 3 } - -erpnext.dimension_filters.forEach((dimension) => { - frappe.query_reports["Profitability Analysis"].filters[1].options.push(dimension["document_type"]); -}); - From 1a9e091d12f9149638f3774b9def0fa80370b59b Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 1 Jan 2024 17:32:33 +0530 Subject: [PATCH 2/2] fix: select options should dynamically load dimensions --- .../budget_variance_report.js | 63 ++++++++++++++----- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js index 15088335e5..9c356bf28e 100644 --- a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js +++ b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js @@ -2,7 +2,44 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Budget Variance Report"] = { - "filters": [ + "filters": get_filters(), + "formatter": function (value, row, column, data, default_formatter) { + value = default_formatter(value, row, column, data); + + if (column.fieldname.includes(__("variance"))) { + + if (data[column.fieldname] < 0) { + value = "" + value + ""; + } + else if (data[column.fieldname] > 0) { + value = "" + value + ""; + } + } + + return value; + } +} +function get_filters() { + function get_dimensions() { + let result = []; + frappe.call({ + method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimensions", + args: { + 'with_cost_center_and_project': true + }, + async: false, + callback: function(r) { + if(!r.exc) { + result = r.message[0].map(elem => elem.document_type); + } + } + }); + return result; + } + + let budget_against_options = get_dimensions(); + + let filters = [ { fieldname: "from_fiscal_year", label: __("From Fiscal Year"), @@ -44,9 +81,13 @@ frappe.query_reports["Budget Variance Report"] = { fieldname: "budget_against", label: __("Budget Against"), fieldtype: "Select", - options: ["Cost Center", "Project"], + options: budget_against_options, default: "Cost Center", reqd: 1, + get_data: function() { + console.log(this.options); + return ["Emacs", "Rocks"]; + }, on_change: function() { frappe.query_report.set_filter_value("budget_against_filter", []); frappe.query_report.refresh(); @@ -71,20 +112,8 @@ frappe.query_reports["Budget Variance Report"] = { fieldtype: "Check", default: 0, }, - ], - "formatter": function (value, row, column, data, default_formatter) { - value = default_formatter(value, row, column, data); + ] - if (column.fieldname.includes(__("variance"))) { - - if (data[column.fieldname] < 0) { - value = "" + value + ""; - } - else if (data[column.fieldname] > 0) { - value = "" + value + ""; - } - } - - return value; - } + return filters; } +