From 0a65217423035b0fe6e8a2934f1bd2aed85e2ac9 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Thu, 27 Feb 2025 13:17:57 +0530 Subject: [PATCH 1/3] fix: if invoice is return then add amount in proper column (cherry picked from commit ccb4bdbe4cd7e11118621968f4097aa20fc0dd1d) --- .../accounts_receivable/accounts_receivable.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py index 1ddf9bce06f..c7a0da5afe9 100644 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py @@ -267,6 +267,18 @@ class ReceivablePayableReport: row.invoiced_in_account_currency += amount_in_account_currency else: if self.is_invoice(ple): + # when invoice has is_return marked + if self.invoice_details.get(row.voucher_no, {}).get("is_return"): + # for Credit Note + if row.voucher_type == "Sales Invoice": + row.credit_note -= amount + row.credit_note_in_account_currency -= amount_in_account_currency + # for Debit Note + else: + row.invoiced -= amount + row.invoiced_in_account_currency -= amount_in_account_currency + return + if row.voucher_no == ple.voucher_no == ple.against_voucher_no: row.paid -= amount row.paid_in_account_currency -= amount_in_account_currency @@ -421,7 +433,7 @@ class ReceivablePayableReport: # nosemgrep si_list = frappe.db.sql( """ - select name, due_date, po_no + select name, due_date, po_no, is_return from `tabSales Invoice` where posting_date <= %s and company = %s @@ -453,7 +465,7 @@ class ReceivablePayableReport: # nosemgrep for pi in frappe.db.sql( """ - select name, due_date, bill_no, bill_date + select name, due_date, bill_no, bill_date, is_return from `tabPurchase Invoice` where posting_date <= %s From 9f4311e7fbaa4ad607747f61a3a4b95ab61b75a2 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Thu, 27 Feb 2025 16:52:13 +0530 Subject: [PATCH 2/3] fix: fixing test case (cherry picked from commit 9b2b477ae05f1d0d6ccb5ce990061956e90acaef) --- .../accounts_receivable/test_accounts_receivable.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py index 39ca78153c3..f3513286c9e 100644 --- a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py @@ -204,7 +204,7 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase): expected_data_after_credit_note = [ [100.0, 100.0, 40.0, 0.0, 60.0, si.name], - [0, 0, 100.0, 0.0, -100.0, cr_note.name], + [0, 0, 0, 100.0, -100.0, cr_note.name], ] self.assertEqual(len(report[1]), 2) si_row = next( @@ -478,13 +478,19 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase): report = execute(filters)[1] self.assertEqual(len(report), 2) - expected_data = {sr.name: [10.0, -10.0, 0.0, -10], si.name: [100.0, 100.0, 10.0, 90.0]} + expected_data = {sr.name: [0.0, 10.0, -10.0, 0.0, -10], si.name: [100.0, 0.0, 100.0, 10.0, 90.0]} rows = report[:2] for row in rows: self.assertEqual( expected_data[row.voucher_no], - [row.invoiced or row.paid, row.outstanding, row.remaining_balance, row.future_amount], + [ + row.invoiced or row.paid, + row.credit_note, + row.outstanding, + row.remaining_balance, + row.future_amount, + ], ) pe.cancel() From a8b31df65ddeae3e0fcee7895dbafc9691034f10 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Thu, 27 Feb 2025 17:14:29 +0530 Subject: [PATCH 3/3] fix: test case for debit note (cherry picked from commit 6719bbeb10156f1c0d7b148e178cafaa3014e248) --- .../accounts_payable/test_accounts_payable.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/erpnext/accounts/report/accounts_payable/test_accounts_payable.py b/erpnext/accounts/report/accounts_payable/test_accounts_payable.py index 8971dc3d37b..69f332d9800 100644 --- a/erpnext/accounts/report/accounts_payable/test_accounts_payable.py +++ b/erpnext/accounts/report/accounts_payable/test_accounts_payable.py @@ -38,6 +38,23 @@ class TestAccountsPayable(AccountsTestMixin, FrappeTestCase): self.assertEqual(data[1][0].get("outstanding"), 300) self.assertEqual(data[1][0].get("currency"), "USD") + def test_account_payable_for_debit_note(self): + pi = self.create_purchase_invoice(do_not_submit=True) + pi.is_return = 1 + pi.items[0].qty = -1 + pi = pi.save().submit() + + filters = { + "company": self.company, + "party_type": "Supplier", + "party": [self.supplier], + "report_date": today(), + "range": "30, 60, 90, 120", + } + + data = execute(filters) + self.assertEqual(data[1][0].get("invoiced"), 300) + def create_purchase_invoice(self, do_not_submit=False): frappe.set_user("Administrator") pi = make_purchase_invoice(