Skip to content

Commit

Permalink
[FIX] rma: use replacement action for automatic return
Browse files Browse the repository at this point in the history
  • Loading branch information
sbejaoui committed Sep 20, 2024
1 parent 9737b31 commit ad6b471
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 6 additions & 2 deletions rma/models/rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 18 additions & 3 deletions rma/tests/test_rma_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -128,7 +128,7 @@ 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)
Expand All @@ -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"""
Expand Down Expand Up @@ -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")
)

0 comments on commit ad6b471

Please sign in to comment.