fix: Do not add filters in report on accounting dimension creation if it already exists
diff --git a/erpnext/accounts/report/accounts_payable/accounts_payable.js b/erpnext/accounts/report/accounts_payable/accounts_payable.js
index 4e09f99..2aa9618 100644
--- a/erpnext/accounts/report/accounts_payable/accounts_payable.js
+++ b/erpnext/accounts/report/accounts_payable/accounts_payable.js
@@ -135,12 +135,5 @@
}
}
-erpnext.dimension_filters.forEach((dimension) => {
- frappe.query_reports["Accounts Payable"].filters.splice(9, 0 ,{
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
-});
+erpnext.utils.add_dimensions('Accounts Payable', 9);
diff --git a/erpnext/accounts/report/accounts_payable_summary/accounts_payable_summary.js b/erpnext/accounts/report/accounts_payable_summary/accounts_payable_summary.js
index d5f18b0..9c6b063 100644
--- a/erpnext/accounts/report/accounts_payable_summary/accounts_payable_summary.js
+++ b/erpnext/accounts/report/accounts_payable_summary/accounts_payable_summary.js
@@ -104,12 +104,5 @@
}
}
-erpnext.dimension_filters.forEach((dimension) => {
- frappe.query_reports["Accounts Payable Summary"].filters.splice(9, 0 ,{
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
-});
+erpnext.utils.add_dimensions('Accounts Payable Summary', 9);
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js
index 6208eb6..8dc558a 100644
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js
@@ -199,12 +199,5 @@
}
}
-erpnext.dimension_filters.forEach((dimension) => {
- frappe.query_reports["Accounts Receivable"].filters.splice(9, 0 ,{
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
-});
+erpnext.utils.add_dimensions('Accounts Receivable', 9);
diff --git a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js
index b316f10..32ecc63 100644
--- a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js
+++ b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js
@@ -122,11 +122,4 @@
}
}
-erpnext.dimension_filters.forEach((dimension) => {
- frappe.query_reports["Accounts Receivable Summary"].filters.splice(9, 0 ,{
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
-});
+erpnext.utils.add_dimensions('Accounts Receivable Summary', 9);
diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.js b/erpnext/accounts/report/balance_sheet/balance_sheet.js
index c4c24c0..4a4ad4d 100644
--- a/erpnext/accounts/report/balance_sheet/balance_sheet.js
+++ b/erpnext/accounts/report/balance_sheet/balance_sheet.js
@@ -4,6 +4,8 @@
frappe.require("assets/erpnext/js/financial_statements.js", function() {
frappe.query_reports["Balance Sheet"] = $.extend({}, erpnext.financial_statements);
+ erpnext.utils.add_dimensions('Balance Sheet', 10);
+
frappe.query_reports["Balance Sheet"]["filters"].push({
"fieldname": "accumulated_values",
"label": __("Accumulated Values"),
diff --git a/erpnext/accounts/report/cash_flow/cash_flow.js b/erpnext/accounts/report/cash_flow/cash_flow.js
index e5d0c89..a984bf4 100644
--- a/erpnext/accounts/report/cash_flow/cash_flow.js
+++ b/erpnext/accounts/report/cash_flow/cash_flow.js
@@ -5,6 +5,8 @@
frappe.query_reports["Cash Flow"] = $.extend({},
erpnext.financial_statements);
+ erpnext.utils.add_dimensions('Cash Flow', 10);
+
// The last item in the array is the definition for Presentation Currency
// filter. It won't be used in cash flow for now so we pop it. Please take
// of this if you are working here.
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.js b/erpnext/accounts/report/general_ledger/general_ledger.js
index 2aecd6b..1fc0f79 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.js
+++ b/erpnext/accounts/report/general_ledger/general_ledger.js
@@ -164,12 +164,5 @@
]
}
-erpnext.dimension_filters.forEach((dimension) => {
- frappe.query_reports["General Ledger"].filters.splice(15, 0 ,{
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
-});
+erpnext.utils.add_dimensions('General Ledger', 15)
diff --git a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js
index 2b946c0..1c461ef 100644
--- a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js
+++ b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js
@@ -6,6 +6,8 @@
frappe.query_reports["Profit and Loss Statement"] = $.extend({},
erpnext.financial_statements);
+ erpnext.utils.add_dimensions('Profit and Loss Statement', 10);
+
frappe.query_reports["Profit and Loss Statement"]["filters"].push(
{
"fieldname": "project",
diff --git a/erpnext/accounts/report/purchase_register/purchase_register.js b/erpnext/accounts/report/purchase_register/purchase_register.js
index b2b95b2..f34ea57 100644
--- a/erpnext/accounts/report/purchase_register/purchase_register.js
+++ b/erpnext/accounts/report/purchase_register/purchase_register.js
@@ -56,11 +56,4 @@
]
}
-erpnext.dimension_filters.forEach((dimension) => {
- frappe.query_reports["Purchase Register"].filters.splice(7, 0 ,{
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
-});
\ No newline at end of file
+erpnext.utils.add_dimensions('Purchase Register', 7);
\ No newline at end of file
diff --git a/erpnext/accounts/report/sales_register/sales_register.js b/erpnext/accounts/report/sales_register/sales_register.js
index 9dee656..85bbcea 100644
--- a/erpnext/accounts/report/sales_register/sales_register.js
+++ b/erpnext/accounts/report/sales_register/sales_register.js
@@ -68,12 +68,5 @@
]
}
-erpnext.dimension_filters.forEach((dimension) => {
- frappe.query_reports["Sales Register"].filters.splice(7, 0 ,{
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
-});
+erpnext.utils.add_dimensions('Sales Register', 7);
diff --git a/erpnext/accounts/report/trial_balance/trial_balance.js b/erpnext/accounts/report/trial_balance/trial_balance.js
index 07752e1..9c0854c 100644
--- a/erpnext/accounts/report/trial_balance/trial_balance.js
+++ b/erpnext/accounts/report/trial_balance/trial_balance.js
@@ -102,14 +102,7 @@
"initial_depth": 3
}
- erpnext.dimension_filters.forEach((dimension) => {
- frappe.query_reports["Trial Balance"].filters.splice(6, 0 ,{
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
- });
+ erpnext.utils.add_dimensions('Trial Balance', 6);
});
diff --git a/erpnext/public/js/financial_statements.js b/erpnext/public/js/financial_statements.js
index 296c628..cf98b75 100644
--- a/erpnext/public/js/financial_statements.js
+++ b/erpnext/public/js/financial_statements.js
@@ -62,7 +62,7 @@
}
};
-function get_filters(){
+function get_filters() {
let filters = [
{
"fieldname":"company",
@@ -162,15 +162,6 @@
}
]
- erpnext.dimension_filters.forEach((dimension) => {
- filters.push({
- "fieldname": dimension["fieldname"],
- "label": __(dimension["label"]),
- "fieldtype": "Link",
- "options": dimension["document_type"]
- });
- });
-
return filters;
}
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index 58969f2..3eeafe1 100755
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -145,6 +145,7 @@
},
get_party_name: function(party_type) {
+ console.log("********");
var dict = {'Customer': 'customer_name', 'Supplier': 'supplier_name', 'Employee': 'employee_name',
'Member': 'member_name'};
return dict[party_type];
@@ -191,6 +192,23 @@
})
},
+ add_dimensions: function(report_name, index) {
+ let filters = frappe.query_reports[report_name].filters;
+
+ erpnext.dimension_filters.forEach((dimension) => {
+ let found = filters.some(el => el.fieldname === dimension['fieldname']);
+
+ if (!found) {
+ filters.splice(index, 0 ,{
+ "fieldname": dimension["fieldname"],
+ "label": __(dimension["label"]),
+ "fieldtype": "Link",
+ "options": dimension["document_type"]
+ });
+ }
+ });
+ },
+
make_subscription: function(doctype, docname) {
frappe.call({
method: "frappe.automation.doctype.auto_repeat.auto_repeat.make_auto_repeat",