Skip to content

Commit

Permalink
Merge PR #1399 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Mar 2, 2023
2 parents 8c49ed5 + 0f63982 commit f5b1731
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
6 changes: 5 additions & 1 deletion account_invoice_refund_link/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 20 additions & 7 deletions account_invoice_refund_link/tests/test_invoice_refund_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ def setUpClass(cls):
}
)
cls.invoice_lines = [
(
0,
False,
{
"name": "Test section",
"display_type": "line_section",
},
),
(
0,
False,
Expand Down Expand Up @@ -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):
Expand All @@ -111,15 +120,19 @@ def test_invoice_copy(self):
self.invoice.copy()
self.assertEqual(
refund.invoice_line_ids.mapped("origin_line_id"),
self.invoice.invoice_line_ids,
self.invoice.invoice_line_ids.filtered(
lambda x: x.display_type == "product"
),
)

def test_refund_copy(self):
refund = self.invoice.refund_invoice_ids[0]
refund.copy()
self.assertEqual(
self.invoice.invoice_line_ids.mapped("refund_line_ids"),
refund.invoice_line_ids,
self.invoice.invoice_line_ids.filtered(
lambda x: x.display_type == "product"
),
refund.invoice_line_ids.mapped("origin_line_id"),
)


Expand Down

0 comments on commit f5b1731

Please sign in to comment.