From 72eca306816b0b94db0b29bfe4506d386766fc11 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Date: Wed, 2 Mar 2022 13:11:20 +0100 Subject: [PATCH] [FIX] rma_account: maintain refund_line_id --- .../test_account_move_line_rma_order_line.py | 6 ++--- rma_account/models/rma_order.py | 4 +-- rma_account/models/rma_order_line.py | 25 +++++++++++-------- rma_account/tests/test_rma_account.py | 6 ++--- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py index 5b38e5fd..766c1ba4 100644 --- a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py +++ b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py @@ -279,12 +279,10 @@ class TestAccountMoveLineRmaOrderLine(common.SavepointCase): } ) make_refund.invoice_refund() - rma_line.move_line_ids.move_id.filtered( + rma_line.refund_line_ids.move_id.filtered( lambda x: x.state != "posted" ).action_post() - for aml in rma_line.move_line_ids.move_id.filtered( - lambda x: x.move_type in ("out_refund", "in_refund") - ).invoice_line_ids: + for aml in rma_line.refund_line_ids.move_id.invoice_line_ids: if aml.product_id == rma_line.product_id and aml.move_id: self.assertEqual( aml.rma_line_id, diff --git a/rma_account/models/rma_order.py b/rma_account/models/rma_order.py index 370630d2..747316c2 100644 --- a/rma_account/models/rma_order.py +++ b/rma_account/models/rma_order.py @@ -9,9 +9,7 @@ class RmaOrder(models.Model): def _compute_invoice_refund_count(self): for rec in self: - invoices = rec.mapped("rma_line_ids.move_line_ids.move_id").filtered( - lambda m: m.move_type in ["in_refund", "out_refund"] - ) + invoices = rec.mapped("rma_line_ids.refund_line_ids.move_id") rec.invoice_refund_count = len(invoices) def _compute_invoice_count(self): diff --git a/rma_account/models/rma_order_line.py b/rma_account/models/rma_order_line.py index 02ee3157..7fd95800 100644 --- a/rma_account/models/rma_order_line.py +++ b/rma_account/models/rma_order_line.py @@ -21,9 +21,8 @@ class RmaOrderLine(models.Model): def _compute_qty_refunded(self): for rec in self: rec.qty_refunded = sum( - rec.move_line_ids.filtered( + rec.refund_line_ids.filtered( lambda i: i.move_id.state in ("posted") - and i.move_id.move_type in ["out_refund", "in_refund"] ).mapped("quantity") ) @@ -48,11 +47,7 @@ class RmaOrderLine(models.Model): def _compute_refund_count(self): for rec in self: - rec.refund_count = len( - rec.move_line_ids.mapped("move_id").filtered( - lambda m: m.move_type in ["out_refund", "in_refund"] - ) - ) + rec.refund_count = len(rec.refund_line_ids.mapped("move_id")) invoice_address_id = fields.Many2one( "res.partner", @@ -81,6 +76,18 @@ class RmaOrderLine(models.Model): index=True, readonly=True, ) + refund_line_ids = fields.One2many( + comodel_name="account.move.line", + inverse_name="rma_line_id", + string="Refund Lines", + domain=[ + ("move_id.move_type", "in", ["in_refund", "out_refund"]), + ("exclude_from_invoice_tab", "=", False), + ], + copy=False, + index=True, + readonly=True, + ) move_id = fields.Many2one( "account.move", string="Source", @@ -274,9 +281,7 @@ class RmaOrderLine(models.Model): } def action_view_refunds(self): - moves = self.mapped("move_line_ids.move_id").filtered( - lambda m: m.move_type in ["out_refund", "in_refund"] - ) + moves = self.mapped("refund_line_ids.move_id") form_view_ref = self.env.ref("account.view_move_form", False) tree_view_ref = self.env.ref("account.view_move_tree", False) diff --git a/rma_account/tests/test_rma_account.py b/rma_account/tests/test_rma_account.py index 7f169e7a..6d07bf3a 100644 --- a/rma_account/tests/test_rma_account.py +++ b/rma_account/tests/test_rma_account.py @@ -224,7 +224,7 @@ class TestRmaAccount(common.SingleTransactionCase): } ).create({"description": "Test refund"}) make_refund.invoice_refund() - rma.move_line_ids.move_id.action_post() + rma.refund_line_ids.move_id.action_post() rma._compute_refund_count() self.assertEqual(rma.refund_count, 1) self.assertEqual(rma.qty_to_refund, 0.0) @@ -266,8 +266,8 @@ class TestRmaAccount(common.SingleTransactionCase): } ).create({"description": "Test refund"}) make_refund.invoice_refund() - rma.move_line_ids.move_id.action_post() + rma.refund_line_ids.move_id.action_post() rma._compute_refund_count() self.assertEqual( - self.operation_1.refund_journal_id, rma.move_line_ids.journal_id + self.operation_1.refund_journal_id, rma.refund_line_ids.journal_id )