diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py index 729155cec8d..1fb93846735 100644 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py @@ -664,7 +664,16 @@ class ReceivablePayableReport: invoiced = d.base_payment_amount paid_amount = d.base_paid_amount - if company_currency == d.party_account_currency or self.filters.get("in_party_currency"): + in_party_currency = self.filters.get("in_party_currency") + # company, billing, and party account currencies are the same + if company_currency == d.currency and company_currency == d.party_account_currency: + in_party_currency = False + + # When filtered by party currency and the billing currency not matches the party account currency + if in_party_currency and d.currency != d.party_account_currency: + in_party_currency = False + + if in_party_currency: invoiced = d.payment_amount paid_amount = d.paid_amount diff --git a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py index 44fee120d8b..19f51dc7a03 100644 --- a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py @@ -199,6 +199,81 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase): row = report[1] self.assertTrue(len(row) == 0) + @change_settings( + "Accounts Settings", + {"allow_multi_currency_invoices_against_single_party_account": 1}, + ) + def test_allow_multi_currency_invoices_against_single_party_account(self): + filters = { + "company": self.company, + "based_on_payment_terms": 1, + "report_date": today(), + "range": "30, 60, 90, 120", + "show_remarks": True, + "in_party_currency": 1, + } + + # CASE 1: Company currency and party account currency are the same + si = self.create_sales_invoice(qty=1, no_payment_schedule=True, do_not_submit=True) + si.currency = "USD" + si.conversion_rate = 80 + si.save().submit() + + filters.update( + { + "party_type": "Customer", + "party": [self.customer], + } + ) + report = execute(filters) + row = report[1][0] + + expected_data = [8000, 8000, "No Remarks"] # Data in company currency + + self.assertEqual(expected_data, [row.invoice_grand_total, row.invoiced, row.remarks]) + + # CASE 2: Transaction currency and party account currency are the same + self.create_customer( + "USD Customer", currency="USD", default_account=self.debtors_usd, company=self.company + ) + si = create_sales_invoice( + item=self.item, + company=self.company, + customer=self.customer, + debit_to=self.debtors_usd, + posting_date=today(), + parent_cost_center=self.cost_center, + cost_center=self.cost_center, + rate=100, + currency="USD", + conversion_rate=80, + price_list_rate=100, + do_not_save=1, + ) + si.save().submit() + + filters.update( + { + "party_type": "Customer", + "party": [self.customer], + } + ) + report = execute(filters) + row = report[1][0] + + expected_data = [100, 100, "No Remarks"] # Data in Part Account Currency + + self.assertEqual(expected_data, [row.invoice_grand_total, row.invoiced, row.remarks]) + + # View in Company currency + filters.pop("in_party_currency") + report = execute(filters) + row = report[1][0] + + expected_data = [8000, 8000, "No Remarks"] # Data in Company Currency + + self.assertEqual(expected_data, [row.invoice_grand_total, row.invoiced, row.remarks]) + def test_accounts_receivable_with_partial_payment(self): filters = { "company": self.company, diff --git a/erpnext/accounts/test/accounts_mixin.py b/erpnext/accounts/test/accounts_mixin.py index fbd0c76a229..3cad657553e 100644 --- a/erpnext/accounts/test/accounts_mixin.py +++ b/erpnext/accounts/test/accounts_mixin.py @@ -5,7 +5,9 @@ from erpnext.stock.doctype.item.test_item import create_item class AccountsTestMixin: - def create_customer(self, customer_name="_Test Customer", currency=None): + def create_customer( + self, customer_name="_Test Customer", currency=None, default_account=None, company=None + ): if not frappe.db.exists("Customer", customer_name): customer = frappe.new_doc("Customer") customer.customer_name = customer_name @@ -13,9 +15,28 @@ class AccountsTestMixin: if currency: customer.default_currency = currency + if company and default_account: + customer.append( + "accounts", + { + "company": company, + "account": default_account, + }, + ) customer.save() self.customer = customer.name else: + if company and default_account: + customer = frappe.get_doc("Customer", customer_name) + customer.accounts = [] + customer.append( + "accounts", + { + "company": company, + "account": default_account, + }, + ) + customer.save() self.customer = customer_name def create_supplier(self, supplier_name="_Test Supplier", currency=None):