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") + ) diff --git a/rma_sale/models/rma.py b/rma_sale/models/rma.py index 1898e717c..0da46b5aa 100644 --- a/rma_sale/models/rma.py +++ b/rma_sale/models/rma.py @@ -186,6 +186,18 @@ def _prepare_delivery_procurement_vals(self, scheduled_date=None): vals["sale_line_id"] = self.move_id.sale_line_id.id return vals + def _prepare_replace_procurement_vals(self, warehouse=None, scheduled_date=None): + vals = super()._prepare_replace_procurement_vals( + warehouse=warehouse, scheduled_date=scheduled_date + ) + if ( + self.move_id + and self.move_id.sale_line_id + and self.operation_id.action_create_refund == "update_quantity" + ): + vals["sale_line_id"] = self.move_id.sale_line_id.id + return vals + def _prepare_reception_procurement_vals(self, group=None): """This method is used only for reception and a specific RMA IN route.""" vals = super()._prepare_reception_procurement_vals(group=group)