fix: set route filter values for AR

This commit is contained in:
Gursheen Anand 2023-09-27 13:01:48 +05:30
parent 888ed36eed
commit 9d15124a6a
2 changed files with 29 additions and 15 deletions

View File

@ -1,6 +1,8 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
frappe.provide("erpnext.utils");
frappe.query_reports["Accounts Receivable"] = { frappe.query_reports["Accounts Receivable"] = {
"filters": [ "filters": [
{ {
@ -38,19 +40,11 @@ frappe.query_reports["Accounts Receivable"] = {
} }
}, },
{ {
"fieldname": "party_type", "fieldname":"party_type",
"label": __("Party Type"), "label": __("Party Type"),
"fieldtype": "Link", "fieldtype": "Autocomplete",
"options": "Party Type", options: get_party_type_options(),
"Default": "Customer", on_change: function() {
get_query: () => {
return {
filters: {
'account_type': 'Receivable'
}
};
},
on_change: () => {
frappe.query_report.set_filter_value('party', ""); frappe.query_report.set_filter_value('party', "");
frappe.query_report.toggle_filter_display('customer_group', frappe.query_report.get_filter_value('party_type') !== "Customer"); frappe.query_report.toggle_filter_display('customer_group', frappe.query_report.get_filter_value('party_type') !== "Customer");
} }
@ -58,8 +52,15 @@ frappe.query_reports["Accounts Receivable"] = {
{ {
"fieldname":"party", "fieldname":"party",
"label": __("Party"), "label": __("Party"),
"fieldtype": "Dynamic Link", "fieldtype": "MultiSelectList",
"options": "party_type", get_data: function(txt) {
if (!frappe.query_report.filters) return;
let party_type = frappe.query_report.get_filter_value('party_type');
if (!party_type) return;
return frappe.db.get_link_options(party_type, txt);
},
}, },
{ {
"fieldname": "party_account", "fieldname": "party_account",
@ -192,3 +193,16 @@ frappe.query_reports["Accounts Receivable"] = {
} }
erpnext.utils.add_dimensions('Accounts Receivable', 9); erpnext.utils.add_dimensions('Accounts Receivable', 9);
function get_party_type_options() {
let options = [];
frappe.db.get_list(
"Party Type", {filters:{"account_type": "Receivable"}, fields:['name']}
).then((res) => {
res.forEach((party_type) => {
options.push(party_type.name);
});
});
return options;
}

View File

@ -138,7 +138,7 @@ frappe.ui.form.on("Customer", {
// custom buttons // custom buttons
frm.add_custom_button(__('Accounts Receivable'), function () { frm.add_custom_button(__('Accounts Receivable'), function () {
frappe.set_route('query-report', 'Accounts Receivable', {customer:frm.doc.name}); frappe.set_route('query-report', 'Accounts Receivable', { party_type: "Customer", party: frm.doc.name });
}, __('View')); }, __('View'));
frm.add_custom_button(__('Accounting Ledger'), function () { frm.add_custom_button(__('Accounting Ledger'), function () {