From fcb237911c446c8927cd8b6741ba6bc9b8b47c69 Mon Sep 17 00:00:00 2001 From: Pedro Castro Silva Date: Mon, 27 Feb 2023 23:14:11 +0000 Subject: [PATCH] [FIX] account_invoice_refund_link: Exclude section/notes origin lines On the side by side comparison, exclude the lines that are not products, as that's what we do on the refund lines. --- .../models/account_move.py | 6 +++++- .../tests/test_invoice_refund_link.py | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/account_invoice_refund_link/models/account_move.py b/account_invoice_refund_link/models/account_move.py index 4969dc1c94c2..5dec2192d775 100644 --- a/account_invoice_refund_link/models/account_move.py +++ b/account_invoice_refund_link/models/account_move.py @@ -23,7 +23,11 @@ def _reverse_moves(self, default_values_list=None, cancel=False): refund_lines = move.line_ids.filtered( lambda x: x.display_type == "product" ) - for i, line in enumerate(self.invoice_line_ids): + for i, line in enumerate( + self.invoice_line_ids.filtered( + lambda x: x.display_type == "product" + ) + ): if i < len(refund_lines): refund_lines[i].origin_line_id = line.id return reverse_moves diff --git a/account_invoice_refund_link/tests/test_invoice_refund_link.py b/account_invoice_refund_link/tests/test_invoice_refund_link.py index 6ff9d5e46c96..b8c8fe1c43ba 100644 --- a/account_invoice_refund_link/tests/test_invoice_refund_link.py +++ b/account_invoice_refund_link/tests/test_invoice_refund_link.py @@ -32,6 +32,14 @@ def setUpClass(cls): } ) cls.invoice_lines = [ + ( + 0, + False, + { + "name": "Test section", + "display_type": "line_section", + }, + ), ( 0, False, @@ -79,14 +87,15 @@ def _test_refund_link(self): self.assertEqual(refund.ref, ref) self.assertEqual(len(self.invoice.invoice_line_ids), len(self.invoice_lines)) self.assertEqual(len(refund.invoice_line_ids), len(self.invoice_lines)) - self.assertTrue(refund.invoice_line_ids[0].origin_line_id) - self.assertEqual( - self.invoice.invoice_line_ids[0], refund.invoice_line_ids[0].origin_line_id - ) + # We're checking only the 2nd and 3rd lines because the first is a line section self.assertTrue(refund.invoice_line_ids[1].origin_line_id) self.assertEqual( self.invoice.invoice_line_ids[1], refund.invoice_line_ids[1].origin_line_id ) + self.assertTrue(refund.invoice_line_ids[2].origin_line_id) + self.assertEqual( + self.invoice.invoice_line_ids[2], refund.invoice_line_ids[2].origin_line_id + ) class TestInvoiceRefundLink(TestInvoiceRefundLinkBase):