Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: AP AR filters from Party link #37268

Merged
merged 7 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def get_ar_filters(doc, entry):
return {
"report_date": doc.posting_date if doc.posting_date else None,
"party_type": "Customer",
"party": entry.customer,
"party": [entry.customer],
"customer_name": entry.customer_name if entry.customer_name else None,
"payment_terms_template": doc.payment_terms_template if doc.payment_terms_template else None,
"sales_partner": doc.sales_partner if doc.sales_partner else None,
Expand Down
38 changes: 25 additions & 13 deletions erpnext/accounts/report/accounts_payable/accounts_payable.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,27 @@ frappe.query_reports["Accounts Payable"] = {
"options": "Payment Terms Template"
},
{
"fieldname": "party_type",
"fieldname":"party_type",
"label": __("Party Type"),
"fieldtype": "Link",
"options": "Party Type",
get_query: () => {
return {
filters: {
'account_type': 'Payable'
}
};
},
on_change: () => {
"fieldtype": "Autocomplete",
options: get_party_type_options(),
on_change: function() {
frappe.query_report.set_filter_value('party', "");
frappe.query_report.toggle_filter_display('supplier_group', frappe.query_report.get_filter_value('party_type') !== "Supplier");
}
},
{
"fieldname":"party",
"label": __("Party"),
"fieldtype": "Dynamic Link",
"options": "party_type",
"fieldtype": "MultiSelectList",
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": "supplier_group",
Expand Down Expand Up @@ -164,3 +164,15 @@ frappe.query_reports["Accounts Payable"] = {
}

erpnext.utils.add_dimensions('Accounts Payable', 9);

function get_party_type_options() {
let options = [];
frappe.db.get_list(
"Party Type", {filters:{"account_type": "Payable"}, fields:['name']}
).then((res) => {
res.forEach((party_type) => {
options.push(party_type.name);
});
});
return options;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_accounts_payable_for_foreign_currency_supplier(self):
filters = {
"company": self.company,
"party_type": "Supplier",
"party": self.supplier,
"party": [self.supplier],
"report_date": today(),
"range1": 30,
"range2": 60,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,27 @@ frappe.query_reports["Accounts Payable Summary"] = {
}
},
{
"fieldname": "party_type",
"fieldname":"party_type",
"label": __("Party Type"),
"fieldtype": "Link",
"options": "Party Type",
get_query: () => {
return {
filters: {
'account_type': 'Payable'
}
};
},
on_change: () => {
"fieldtype": "Autocomplete",
options: get_party_type_options(),
on_change: function() {
frappe.query_report.set_filter_value('party', "");
frappe.query_report.toggle_filter_display('supplier_group', frappe.query_report.get_filter_value('party_type') !== "Supplier");
}
},
{
"fieldname":"party",
"label": __("Party"),
"fieldtype": "Dynamic Link",
"options": "party_type",
"fieldtype": "MultiSelectList",
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":"payment_terms_template",
Expand Down Expand Up @@ -122,3 +122,15 @@ frappe.query_reports["Accounts Payable Summary"] = {
}

erpnext.utils.add_dimensions('Accounts Payable Summary', 9);

function get_party_type_options() {
let options = [];
frappe.db.get_list(
"Party Type", {filters:{"account_type": "Payable"}, fields:['name']}
).then((res) => {
res.forEach((party_type) => {
options.push(party_type.name);
});
});
return options;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt

frappe.provide("erpnext.utils");

frappe.query_reports["Accounts Receivable"] = {
"filters": [
{
Expand Down Expand Up @@ -38,28 +40,27 @@ frappe.query_reports["Accounts Receivable"] = {
}
},
{
"fieldname": "party_type",
"fieldname":"party_type",
"label": __("Party Type"),
"fieldtype": "Link",
"options": "Party Type",
"Default": "Customer",
get_query: () => {
return {
filters: {
'account_type': 'Receivable'
}
};
},
on_change: () => {
"fieldtype": "Autocomplete",
options: get_party_type_options(),
on_change: function() {
frappe.query_report.set_filter_value('party', "");
frappe.query_report.toggle_filter_display('customer_group', frappe.query_report.get_filter_value('party_type') !== "Customer");
}
},
{
"fieldname":"party",
"label": __("Party"),
"fieldtype": "Dynamic Link",
"options": "party_type",
"fieldtype": "MultiSelectList",
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",
Expand Down Expand Up @@ -192,3 +193,16 @@ frappe.query_reports["Accounts Receivable"] = {
}

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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ def add_common_filters(self):
self.qb_selection_filter.append(self.filters.party_type == self.ple.party_type)

if self.filters.get("party"):
self.qb_selection_filter.append(self.filters.party == self.ple.party)
self.qb_selection_filter.append(self.ple.party.isin(self.filters.party))

if self.filters.party_account:
self.qb_selection_filter.append(self.ple.account == self.filters.party_account)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def test_usd_customer_filter(self):
filters = {
"company": self.company,
"party_type": "Customer",
"party": self.customer,
"party": [self.customer],
"report_date": today(),
"range1": 30,
"range2": 60,
Expand Down Expand Up @@ -605,3 +605,41 @@ def test_usd_customer_filter(self):
for field in expected:
with self.subTest(field=field):
self.assertEqual(report_output.get(field), expected.get(field))

def test_multi_select_party_filter(self):
self.customer1 = self.customer
self.create_customer("_Test Customer 2")
self.customer2 = self.customer
self.create_customer("_Test Customer 3")
self.customer3 = self.customer

filters = {
"company": self.company,
"party_type": "Customer",
"party": [self.customer1, self.customer3],
"report_date": today(),
"range1": 30,
"range2": 60,
"range3": 90,
"range4": 120,
}

si1 = self.create_sales_invoice(no_payment_schedule=True, do_not_submit=True)
si1.customer = self.customer1
si1.save().submit()

si2 = self.create_sales_invoice(no_payment_schedule=True, do_not_submit=True)
si2.customer = self.customer2
si2.save().submit()

si3 = self.create_sales_invoice(no_payment_schedule=True, do_not_submit=True)
si3.customer = self.customer3
si3.save().submit()

# check invoice grand total and invoiced column's value for 3 payment terms
report = execute(filters)

expected_output = {self.customer1, self.customer3}
self.assertEqual(len(report[1]), 2)
output_for = set([x.party for x in report[1]])
self.assertEqual(output_for, expected_output)
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,27 @@ frappe.query_reports["Accounts Receivable Summary"] = {
}
},
{
"fieldname": "party_type",
"fieldname":"party_type",
"label": __("Party Type"),
"fieldtype": "Link",
"options": "Party Type",
"Default": "Customer",
get_query: () => {
return {
filters: {
'account_type': 'Receivable'
}
};
},
on_change: () => {
"fieldtype": "Autocomplete",
options: get_party_type_options(),
on_change: function() {
frappe.query_report.set_filter_value('party', "");
frappe.query_report.toggle_filter_display('customer_group', frappe.query_report.get_filter_value('party_type') !== "Customer");
}
},
{
"fieldname":"party",
"label": __("Party"),
"fieldtype": "Dynamic Link",
"options": "party_type",
"fieldtype": "MultiSelectList",
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":"customer_group",
Expand Down Expand Up @@ -151,3 +150,15 @@ frappe.query_reports["Accounts Receivable Summary"] = {
}

erpnext.utils.add_dimensions('Accounts Receivable Summary', 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;
}
2 changes: 1 addition & 1 deletion erpnext/buying/doctype/supplier/supplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ frappe.ui.form.on("Supplier", {
}, __("View"));

frm.add_custom_button(__('Accounts Payable'), function () {
frappe.set_route('query-report', 'Accounts Payable', { supplier: frm.doc.name });
frappe.set_route('query-report', 'Accounts Payable', { party_type: "Supplier", party: frm.doc.name });
}, __("View"));

frm.add_custom_button(__('Bank Account'), function () {
Expand Down
2 changes: 1 addition & 1 deletion erpnext/selling/doctype/customer/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ frappe.ui.form.on("Customer", {
// custom buttons

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'));

frm.add_custom_button(__('Accounting Ledger'), function () {
Expand Down