refactor: dynamic dimension filters in pop up
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js
index a98934a..f5a07bf 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.js
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js
@@ -638,23 +638,9 @@
frm.events.set_unallocated_amount(frm);
},
- get_dimensions: function(frm) {
- let result = [];
- frappe.call({
- method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimensions",
- async: false,
- callback: function(r) {
- if(!r.exc) {
- result = r.message[0].map(elem => elem.document_type);
- }
- }
- });
- return result;
- },
-
get_outstanding_invoices_or_orders: function(frm, get_outstanding_invoices, get_orders_to_be_billed) {
const today = frappe.datetime.get_today();
- const fields = [
+ let fields = [
{fieldtype:"Section Break", label: __("Posting Date")},
{fieldtype:"Date", label: __("From Date"),
fieldname:"from_posting_date", default:frappe.datetime.add_days(today, -30)},
@@ -669,18 +655,29 @@
fieldname:"outstanding_amt_greater_than", default: 0},
{fieldtype:"Column Break"},
{fieldtype:"Float", label: __("Less Than Amount"), fieldname:"outstanding_amt_less_than"},
- {fieldtype:"Section Break"},
- {fieldtype:"Link", label:__("Cost Center"), fieldname:"cost_center", options:"Cost Center",
- "get_query": function() {
- return {
- "filters": {"company": frm.doc.company}
- }
+ ];
+
+ if (frm.dimension_filters) {
+ let column_break_insertion_point = Math.ceil((frm.dimension_filters.length)/2);
+
+ fields.push({fieldtype:"Section Break"});
+ frm.dimension_filters.map((elem, idx)=>{
+ fields.push({
+ fieldtype: "Link",
+ label: elem.document_type == "Cost Center" ? "Cost Center" : elem.label,
+ options: elem.document_type,
+ fieldname: elem.fieldname || elem.document_type
+ });
+ if(idx+1 == column_break_insertion_point) {
+ fields.push({fieldtype:"Column Break"});
}
- },
- {fieldtype:"Column Break"},
+ });
+ }
+
+ fields = fields.concat([
{fieldtype:"Section Break"},
{fieldtype:"Check", label: __("Allocate Payment Amount"), fieldname:"allocate_payment_amount", default:1},
- ];
+ ]);
let btn_text = "";
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 37bd8e6..45e0f0b 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -13,6 +13,7 @@
from pypika.functions import Coalesce, Sum
import erpnext
+from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_dimensions
from erpnext.accounts.doctype.bank_account.bank_account import (
get_bank_account_details,
get_party_bank_account,
@@ -1684,6 +1685,13 @@
condition += " and cost_center='%s'" % args.get("cost_center")
accounting_dimensions_filter.append(ple.cost_center == args.get("cost_center"))
+ # dynamic dimension filters
+ active_dimensions = get_dimensions()[0]
+ for dim in active_dimensions:
+ if args.get(dim.fieldname):
+ condition += " and {0}='{1}'".format(dim.fieldname, args.get(dim.fieldname))
+ accounting_dimensions_filter.append(ple[dim.fieldname] == args.get(dim.fieldname))
+
date_fields_dict = {
"posting_date": ["from_posting_date", "to_posting_date"],
"due_date": ["from_due_date", "to_due_date"],
diff --git a/erpnext/public/js/utils/dimension_tree_filter.js b/erpnext/public/js/utils/dimension_tree_filter.js
index 3f70c09..27d00ba 100644
--- a/erpnext/public/js/utils/dimension_tree_filter.js
+++ b/erpnext/public/js/utils/dimension_tree_filter.js
@@ -25,6 +25,10 @@
},
setup_filters(frm, doctype) {
+ if (doctype == 'Payment Entry' && this.accounting_dimensions) {
+ frm.dimension_filters = this.accounting_dimensions
+ }
+
if (this.accounting_dimensions) {
this.accounting_dimensions.forEach((dimension) => {
frappe.model.with_doctype(dimension['document_type'], () => {