refactor: dynamic dimension filters in pop up
This commit is contained in:
parent
fcf4687c52
commit
f8bbb0619c
@ -638,23 +638,9 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
frm.events.set_unallocated_amount(frm);
|
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) {
|
get_outstanding_invoices_or_orders: function(frm, get_outstanding_invoices, get_orders_to_be_billed) {
|
||||||
const today = frappe.datetime.get_today();
|
const today = frappe.datetime.get_today();
|
||||||
const fields = [
|
let fields = [
|
||||||
{fieldtype:"Section Break", label: __("Posting Date")},
|
{fieldtype:"Section Break", label: __("Posting Date")},
|
||||||
{fieldtype:"Date", label: __("From Date"),
|
{fieldtype:"Date", label: __("From Date"),
|
||||||
fieldname:"from_posting_date", default:frappe.datetime.add_days(today, -30)},
|
fieldname:"from_posting_date", default:frappe.datetime.add_days(today, -30)},
|
||||||
@ -669,18 +655,29 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
fieldname:"outstanding_amt_greater_than", default: 0},
|
fieldname:"outstanding_amt_greater_than", default: 0},
|
||||||
{fieldtype:"Column Break"},
|
{fieldtype:"Column Break"},
|
||||||
{fieldtype:"Float", label: __("Less Than Amount"), fieldname:"outstanding_amt_less_than"},
|
{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() {
|
if (frm.dimension_filters) {
|
||||||
return {
|
let column_break_insertion_point = Math.ceil((frm.dimension_filters.length)/2);
|
||||||
"filters": {"company": frm.doc.company}
|
|
||||||
|
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:"Section Break"},
|
||||||
{fieldtype:"Check", label: __("Allocate Payment Amount"), fieldname:"allocate_payment_amount", default:1},
|
{fieldtype:"Check", label: __("Allocate Payment Amount"), fieldname:"allocate_payment_amount", default:1},
|
||||||
];
|
]);
|
||||||
|
|
||||||
let btn_text = "";
|
let btn_text = "";
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ from pypika import Case
|
|||||||
from pypika.functions import Coalesce, Sum
|
from pypika.functions import Coalesce, Sum
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_dimensions
|
||||||
from erpnext.accounts.doctype.bank_account.bank_account import (
|
from erpnext.accounts.doctype.bank_account.bank_account import (
|
||||||
get_bank_account_details,
|
get_bank_account_details,
|
||||||
get_party_bank_account,
|
get_party_bank_account,
|
||||||
@ -1684,6 +1685,13 @@ def get_outstanding_reference_documents(args, validate=False):
|
|||||||
condition += " and cost_center='%s'" % args.get("cost_center")
|
condition += " and cost_center='%s'" % args.get("cost_center")
|
||||||
accounting_dimensions_filter.append(ple.cost_center == 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 = {
|
date_fields_dict = {
|
||||||
"posting_date": ["from_posting_date", "to_posting_date"],
|
"posting_date": ["from_posting_date", "to_posting_date"],
|
||||||
"due_date": ["from_due_date", "to_due_date"],
|
"due_date": ["from_due_date", "to_due_date"],
|
||||||
|
|||||||
@ -25,6 +25,10 @@ erpnext.accounts.dimensions = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setup_filters(frm, doctype) {
|
setup_filters(frm, doctype) {
|
||||||
|
if (doctype == 'Payment Entry' && this.accounting_dimensions) {
|
||||||
|
frm.dimension_filters = this.accounting_dimensions
|
||||||
|
}
|
||||||
|
|
||||||
if (this.accounting_dimensions) {
|
if (this.accounting_dimensions) {
|
||||||
this.accounting_dimensions.forEach((dimension) => {
|
this.accounting_dimensions.forEach((dimension) => {
|
||||||
frappe.model.with_doctype(dimension['document_type'], () => {
|
frappe.model.with_doctype(dimension['document_type'], () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user