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 a3d5c26
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
17 changes: 13 additions & 4 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 Expand Up @@ -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()

Expand Down
23 changes: 19 additions & 4 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,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):
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 a3d5c26

Please sign in to comment.