From a3d5c26a5ca325804bc891b4e1eb697526653c92 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Fri, 20 Sep 2024 11:22:49 +0200 Subject: [PATCH] [FIX] rma: use replacement action for automatic return --- rma/models/rma.py | 17 +++++++++++++---- rma/tests/test_rma_operation.py | 23 +++++++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/rma/models/rma.py b/rma/models/rma.py index 126a05515..d84b79af9 100644 --- a/rma/models/rma.py +++ b/rma/models/rma.py @@ -857,8 +857,12 @@ def action_confirm(self): if rec.operation_id.action_create_delivery == "automatic_on_confirm": rec.with_context( rma_return_grouping=rec.env.company.rma_return_grouping - ).create_return( - fields.Datetime.now(), rec.product_uom_qty, rec.product_uom + ).create_replace( + fields.Datetime.now(), + self.warehouse_id, + self.product_id, + rec.product_uom_qty, + rec.product_uom, ) if rec.operation_id.action_create_refund == "automatic_on_confirm": rec.action_refund() @@ -1502,9 +1506,14 @@ def update_received_state_on_reception(self): if rec.operation_id.action_create_delivery == "automatic_after_receipt": rec.with_context( rma_return_grouping=rec.env.company.rma_return_grouping - ).create_return( - fields.Datetime.now(), rec.product_uom_qty, rec.product_uom + ).create_replace( + fields.Datetime.now(), + self.warehouse_id, + self.product_id, + rec.product_uom_qty, + rec.product_uom, ) + if rec.operation_id.action_create_refund == "automatic_after_receipt": rec.action_refund() diff --git a/rma/tests/test_rma_operation.py b/rma/tests/test_rma_operation.py index 2957ed4bd..ab1478df0 100644 --- a/rma/tests/test_rma_operation.py +++ b/rma/tests/test_rma_operation.py @@ -76,7 +76,7 @@ def test_04(self): self.assertFalse(rma.can_be_returned) self.assertFalse(rma.can_be_replaced) rma.action_confirm() - self.assertEqual(rma.state, "waiting_return") + self.assertEqual(rma.state, "waiting_replacement") self.assertFalse(rma.can_be_returned) self.assertFalse(rma.show_create_return) self.assertFalse(rma.can_be_replaced) @@ -128,10 +128,10 @@ def test_06(self): rma.reception_move_id.picking_id._action_done() self.assertEqual(rma.delivery_move_ids.product_id, self.product) self.assertEqual(rma.delivery_move_ids.product_uom_qty, 10) - self.assertEqual(rma.state, "waiting_return") + self.assertEqual(rma.state, "waiting_replacement") self.assertFalse(rma.can_be_returned) self.assertFalse(rma.show_create_return) - self.assertFalse(rma.can_be_replaced) + self.assertTrue(rma.can_be_replaced) self.assertFalse(rma.show_create_replace) def test_07(self): @@ -155,7 +155,7 @@ def test_07(self): rma.action_confirm() self.assertEqual(rma.delivery_move_ids.product_id, rma.product_id) self.assertEqual(rma.reception_move_id.product_id, rma.return_product_id) - self.assertEqual(rma.state, "waiting_return") + self.assertEqual(rma.state, "waiting_replacement") def test_08(self): """test refund, manually after confirm""" @@ -287,3 +287,18 @@ def test_15(self): reception = self.env["stock.picking"].browse(picking_action["res_id"]) move = reception.move_ids.filtered(lambda m, p=self.product: m.product_id == p) self.assertTrue(move.to_refund) + + def test_rma_replace_pick_ship(self): + self.operation.action_create_delivery = "automatic_on_confirm" + self.warehouse.write({"delivery_steps": "pick_ship"}) + rma = self._create_rma(self.partner, self.product, 1, self.rma_loc) + rma.action_confirm() + self.assertEqual(rma.state, "waiting_replacement") + out_pickings = rma.mapped("delivery_move_ids.picking_id") + self.assertEqual(rma.delivery_picking_count, 2) + self.assertIn( + self.warehouse.pick_type_id, out_pickings.mapped("picking_type_id") + ) + self.assertIn( + self.warehouse.out_type_id, out_pickings.mapped("picking_type_id") + )