From 219855311d4c35ebeea36c260853a6bcf1068fe5 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 30 Jun 2022 15:14:38 +0530 Subject: [PATCH 1/2] fix: wrong amount fetched in payment reconciliation tool - fetch amount on account currency for outstanding invoices and - unreconcilied dr/cr notes - fix currency field name in payment ledger entry creation --- .../payment_reconciliation/payment_reconciliation.py | 2 +- erpnext/accounts/utils.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py index 5b2b526e59..5ed34d34a3 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py @@ -162,7 +162,7 @@ class PaymentReconciliation(Document): { "reference_type": inv.voucher_type, "reference_name": inv.voucher_no, - "amount": -(inv.outstanding), + "amount": -(inv.outstanding_in_account_currency), "posting_date": inv.posting_date, "currency": inv.currency, } diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 8daff9d193..6be8fd7e60 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -855,8 +855,8 @@ def get_outstanding_invoices( ) for d in invoice_list: - payment_amount = d.invoice_amount - d.outstanding - outstanding_amount = d.outstanding + payment_amount = d.invoice_amount_in_account_currency - d.outstanding_in_account_currency + outstanding_amount = d.outstanding_in_account_currency if outstanding_amount > 0.5 / (10**precision): if ( min_outstanding @@ -872,7 +872,7 @@ def get_outstanding_invoices( "voucher_no": d.voucher_no, "voucher_type": d.voucher_type, "posting_date": d.posting_date, - "invoice_amount": flt(d.invoice_amount), + "invoice_amount": flt(d.invoice_amount_in_account_currency), "payment_amount": payment_amount, "outstanding_amount": outstanding_amount, "due_date": d.due_date, @@ -1412,7 +1412,7 @@ def create_payment_ledger_entry( if gle.against_voucher_type else gle.voucher_type, "against_voucher_no": gle.against_voucher if gle.against_voucher else gle.voucher_no, - "currency": gle.currency, + "account_currency": gle.account_currency, "amount": dr_or_cr, "amount_in_account_currency": dr_or_cr_account_currency, "delinked": True if cancel else False, From c9d67defd8dd4efef916587216fa9e626252d79b Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 1 Jul 2022 13:02:14 +0530 Subject: [PATCH 2/2] test: PR output should have account currency --- .../test_payment_reconciliation.py | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py index 575ac74a4e..325346d6b6 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py @@ -19,6 +19,7 @@ class TestPaymentReconciliation(FrappeTestCase): self.create_company() self.create_item() self.create_customer() + self.create_account() self.clear_old_entries() def tearDown(self): @@ -89,6 +90,38 @@ class TestPaymentReconciliation(FrappeTestCase): customer.save() self.customer2 = customer.name + if frappe.db.exists("Customer", "_Test PR Customer 3"): + self.customer3 = "_Test PR Customer 3" + else: + customer = frappe.new_doc("Customer") + customer.customer_name = "_Test PR Customer 3" + customer.type = "Individual" + customer.default_currency = "EUR" + customer.save() + self.customer3 = customer.name + + def create_account(self): + account_name = "Debtors EUR" + 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 Receivable - _PR" + acc.company = self.company + acc.account_currency = "EUR" + acc.account_type = "Receivable" + 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.debtors_eur = acc.name + def create_sales_invoice( self, qty=1, rate=100, posting_date=nowdate(), do_not_save=False, do_not_submit=False ): @@ -454,3 +487,56 @@ class TestPaymentReconciliation(FrappeTestCase): self.assertEqual(len(pr.get("payments")), 1) self.assertEqual(pr.get("invoices")[0].outstanding_amount, 20) self.assertEqual(pr.get("payments")[0].amount, 20) + + def test_pr_output_foreign_currency_and_amount(self): + # test for currency and amount invoices and payments + transaction_date = nowdate() + # In EUR + amount = 100 + exchange_rate = 80 + + si = self.create_sales_invoice( + qty=1, rate=amount, posting_date=transaction_date, do_not_save=True, do_not_submit=True + ) + si.customer = self.customer3 + si.currency = "EUR" + si.conversion_rate = exchange_rate + si.debit_to = self.debtors_eur + si = si.save().submit() + + cr_note = self.create_sales_invoice( + qty=-1, rate=amount, posting_date=transaction_date, do_not_save=True, do_not_submit=True + ) + cr_note.customer = self.customer3 + cr_note.is_return = 1 + cr_note.currency = "EUR" + cr_note.conversion_rate = exchange_rate + cr_note.debit_to = self.debtors_eur + cr_note = cr_note.save().submit() + + pr = self.create_payment_reconciliation() + pr.party = self.customer3 + pr.receivable_payable_account = self.debtors_eur + pr.get_unreconciled_entries() + + self.assertEqual(len(pr.invoices), 1) + self.assertEqual(len(pr.payments), 1) + + self.assertEqual(pr.invoices[0].amount, amount) + self.assertEqual(pr.invoices[0].currency, "EUR") + self.assertEqual(pr.payments[0].amount, amount) + self.assertEqual(pr.payments[0].currency, "EUR") + + cr_note.cancel() + + from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry + + pay = get_payment_entry(si.doctype, si.name) + pay.references.clear() + pay = pay.save().submit() + + pr.get_unreconciled_entries() + self.assertEqual(len(pr.invoices), 1) + self.assertEqual(len(pr.payments), 1) + self.assertEqual(pr.payments[0].amount, amount) + self.assertEqual(pr.payments[0].currency, "EUR")