diff --git a/erpnext/accounts/report/accounts_payable/accounts_payable.js b/erpnext/accounts/report/accounts_payable/accounts_payable.js index e1a30a4b77e0..27a85701edda 100644 --- a/erpnext/accounts/report/accounts_payable/accounts_payable.js +++ b/erpnext/accounts/report/accounts_payable/accounts_payable.js @@ -37,24 +37,6 @@ frappe.query_reports["Accounts Payable"] = { } } }, - { - "fieldname": "supplier", - "label": __("Supplier"), - "fieldtype": "Link", - "options": "Supplier", - on_change: () => { - var supplier = frappe.query_report.get_filter_value('supplier'); - if (supplier) { - frappe.db.get_value('Supplier', supplier, "tax_id", function(value) { - frappe.query_report.set_filter_value('tax_id', value["tax_id"]); - }); - } else { - frappe.query_report.set_filter_value('tax_id', ""); - } - - frappe.query_report.refresh(); - } - }, { "fieldname": "party_account", "label": __("Payable Account"), @@ -112,11 +94,38 @@ frappe.query_reports["Accounts Payable"] = { "fieldtype": "Link", "options": "Payment Terms Template" }, + { + "fieldname": "party_type", + "label": __("Party Type"), + "fieldtype": "Link", + "options": "Party Type", + get_query: () => { + return { + filters: { + 'account_type': 'Payable' + } + }; + }, + on_change: () => { + frappe.query_report.set_filter_value('party', ""); + let party_type = frappe.query_report.get_filter_value('party_type'); + 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", + }, { "fieldname": "supplier_group", "label": __("Supplier Group"), "fieldtype": "Link", - "options": "Supplier Group" + "options": "Supplier Group", + "hidden": 1 }, { "fieldname": "group_by_party", @@ -133,12 +142,6 @@ frappe.query_reports["Accounts Payable"] = { "label": __("Show Remarks"), "fieldtype": "Check", }, - { - "fieldname": "tax_id", - "label": __("Tax Id"), - "fieldtype": "Data", - "hidden": 1 - }, { "fieldname": "show_future_payments", "label": __("Show Future Payments"), diff --git a/erpnext/accounts/report/accounts_payable/test_accounts_payable.py b/erpnext/accounts/report/accounts_payable/test_accounts_payable.py new file mode 100644 index 000000000000..cb84cf4fc0a6 --- /dev/null +++ b/erpnext/accounts/report/accounts_payable/test_accounts_payable.py @@ -0,0 +1,67 @@ +import unittest + +import frappe +from frappe.tests.utils import FrappeTestCase, change_settings +from frappe.utils import add_days, flt, getdate, today + +from erpnext import get_default_cost_center +from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry +from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice +from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice +from erpnext.accounts.report.accounts_payable.accounts_payable import execute +from erpnext.accounts.test.accounts_mixin import AccountsTestMixin +from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order + + +class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase): + def setUp(self): + self.create_company() + self.create_customer() + self.create_item() + self.create_supplier(currency="USD", supplier_name="Test Supplier2") + self.create_usd_payable_account() + + def tearDown(self): + frappe.db.rollback() + + def test_accounts_receivable_with_supplier(self): + pi = self.create_purchase_invoice(do_not_submit=True) + pi.currency = "USD" + pi.conversion_rate = 80 + pi.credit_to = self.creditors_usd + pi = pi.save().submit() + + filters = { + "company": self.company, + "party_type": "Supplier", + "party": self.supplier, + "report_date": today(), + "range1": 30, + "range2": 60, + "range3": 90, + "range4": 120, + } + + data = execute(filters) + self.assertEqual(data[1][0].get("outstanding"), 300) + self.assertEqual(data[1][0].get("currency"), "USD") + + def create_purchase_invoice(self, do_not_submit=False): + frappe.set_user("Administrator") + pi = make_purchase_invoice( + item=self.item, + company=self.company, + supplier=self.supplier, + is_return=False, + update_stock=False, + posting_date=frappe.utils.datetime.date(2021, 5, 1), + do_not_save=1, + rate=300, + price_list_rate=300, + qty=1, + ) + + pi = pi.save() + if not do_not_submit: + pi = pi.submit() + return pi diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js index 0b4e577f6cb3..cb8ec876e9ee 100644 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js @@ -46,8 +46,7 @@ frappe.query_reports["Accounts Receivable"] = { var customer = frappe.query_report.get_filter_value('customer'); var company = frappe.query_report.get_filter_value('company'); if (customer) { - frappe.db.get_value('Customer', customer, ["tax_id", "customer_name", "payment_terms"], function(value) { - frappe.query_report.set_filter_value('tax_id', value["tax_id"]); + frappe.db.get_value('Customer', customer, ["customer_name", "payment_terms"], function(value) { frappe.query_report.set_filter_value('customer_name', value["customer_name"]); frappe.query_report.set_filter_value('payment_terms', value["payment_terms"]); }); @@ -59,7 +58,6 @@ frappe.query_reports["Accounts Receivable"] = { } }, "Customer"); } else { - frappe.query_report.set_filter_value('tax_id', ""); frappe.query_report.set_filter_value('customer_name', ""); frappe.query_report.set_filter_value('credit_limit', ""); frappe.query_report.set_filter_value('payment_terms', ""); @@ -172,12 +170,6 @@ frappe.query_reports["Accounts Receivable"] = { "label": __("Show Sales Person"), "fieldtype": "Check", }, - { - "fieldname": "tax_id", - "label": __("Tax Id"), - "fieldtype": "Data", - "hidden": 1 - }, { "fieldname": "show_remarks", "label": __("Show Remarks"), diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py index 751063ad8e64..3700f00ee226 100755 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py @@ -211,11 +211,10 @@ def update_voucher_balance(self, ple): return # amount in "Party Currency", if its supplied. If not, amount in company currency - for party_type in self.party_type: - if self.filters.get(scrub(party_type)): - amount = ple.amount_in_account_currency - else: - amount = ple.amount + if self.filters.get("party_type") and self.filters.get("party"): + amount = ple.amount_in_account_currency + else: + amount = ple.amount amount_in_account_currency = ple.amount_in_account_currency # update voucher @@ -426,10 +425,9 @@ def set_party_details(self, row): # customer / supplier name party_details = self.get_party_details(row.party) or {} row.update(party_details) - for party_type in self.party_type: - if self.filters.get(scrub(party_type)): - row.currency = row.account_currency - break + + if self.filters.get("party_type") and self.filters.get("party"): + row.currency = row.account_currency else: row.currency = self.company_currency @@ -765,6 +763,7 @@ def get_sales_invoices_or_customers_based_on_sales_person(self): def prepare_conditions(self): self.qb_selection_filter = [] self.or_filters = [] + for party_type in self.party_type: party_type_field = scrub(party_type) self.or_filters.append(self.ple.party_type == party_type) @@ -800,6 +799,12 @@ def add_common_filters(self, party_type_field): if self.filters.get(party_type_field): self.qb_selection_filter.append(self.ple.party == self.filters.get(party_type_field)) + if self.filters.get("party_type"): + 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) + if self.filters.party_account: self.qb_selection_filter.append(self.ple.account == self.filters.party_account) else: diff --git a/erpnext/accounts/test/accounts_mixin.py b/erpnext/accounts/test/accounts_mixin.py index bf01362c97ff..08688608f4b1 100644 --- a/erpnext/accounts/test/accounts_mixin.py +++ b/erpnext/accounts/test/accounts_mixin.py @@ -126,6 +126,28 @@ def create_usd_receivable_account(self): acc = frappe.get_doc("Account", name) self.debtors_usd = acc.name + def create_usd_payable_account(self): + account_name = "Creditors USD" + if not frappe.db.get_value( + "Account", filters={"account_name": account_name, "company": self.company} + ): + acc = frappe.new_doc("Account") + acc.account_name = account_name + acc.parent_account = "Accounts Payable - " + self.company_abbr + acc.company = self.company + acc.account_currency = "USD" + acc.account_type = "Payable" + acc.insert() + else: + name = frappe.db.get_value( + "Account", + filters={"account_name": account_name, "company": self.company}, + fieldname="name", + pluck=True, + ) + acc = frappe.get_doc("Account", name) + self.creditors_usd = acc.name + def clear_old_entries(self): doctype_list = [ "GL Entry",