Skip to content

Commit

Permalink
[FIX] rma: same procurement group for reception and delivery
Browse files Browse the repository at this point in the history
The procurement group created for reception was not being correctly assigned to the RMA,
resulting in a different group being generated for the delivery.

This fix ensures that the same procurement group is used for both operations.
  • Loading branch information
sbejaoui committed Sep 3, 2024
1 parent 6197962 commit 81e6ff8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 28 deletions.
10 changes: 4 additions & 6 deletions rma/models/rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ def _prepare_reception_procurements(self):
group = rma.procurement_group_id
if not group:
group = group_model.create(rma._prepare_procurement_group_vals())
rma.procurement_group_id = group
procurements.append(
group_model.Procurement(
rma.product_id,
Expand Down Expand Up @@ -1111,12 +1112,9 @@ def _group_delivery_if_needed(self):
key=lambda rma: [rma._delivery_group_key()],
)
for _group, rmas in grouped_rmas:
rmas = (
self.browse()
.concat(*list(rmas))
.filtered(lambda rma: not rma.procurement_group_id)
)
if not rmas:
rmas = self.browse().concat(*list(rmas))
if not rmas or len(rmas.procurement_group_id) == 1:
# if the rmas already grouped, no need to create a new proc group
continue
proc_group = self.env["procurement.group"].create(
rmas._prepare_procurement_group_vals()
Expand Down
15 changes: 15 additions & 0 deletions rma/tests/test_rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,3 +848,18 @@ def test_autoconfirm_email(self):
)
self.assertTrue(rma.name in mail_receipt.subject)
self.assertTrue("products received" in mail_receipt.subject)

def test_same_procurement_group_for_reception_and_delivery(self):
rma = self._create_confirm_receive(self.partner, self.product, 10, self.rma_loc)
self.assertTrue(rma.procurement_group_id)
delivery_form = Form(
self.env["rma.delivery.wizard"].with_context(
active_ids=rma.ids,
rma_delivery_type="return",
)
)
delivery_form.product_uom_qty = 2
delivery_wizard = delivery_form.save()
delivery_wizard.action_deliver()
self.assertEqual(rma.delivery_move_ids.group_id, rma.procurement_group_id)
self.assertEqual(rma.delivery_move_ids.group_id, rma.reception_move_id.group_id)
12 changes: 0 additions & 12 deletions rma_sale/models/rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,3 @@ def _prepare_refund_line_vals(self):
):
vals["sale_line_ids"] = [(4, line.id)]
return vals

def _prepare_procurement_group_vals(self):
vals = super()._prepare_procurement_group_vals()
if not self.env.context.get("ignore_rma_sale_order") and self.order_id:
vals["sale_id"] = self.order_id.id
return vals

def _prepare_delivery_procurements(self, scheduled_date=None, qty=None, uom=None):
self = self.with_context(ignore_rma_sale_order=True)
return super()._prepare_delivery_procurements(
scheduled_date=scheduled_date, qty=qty, uom=uom
)
4 changes: 0 additions & 4 deletions rma_sale/tests/test_rma_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ def test_create_rma_from_so(self):
rma.reception_move_id.origin_returned_move_id,
self.order_out_picking.move_ids,
)
self.assertEqual(
rma.reception_move_id.picking_id + self.order_out_picking,
order.picking_ids,
)
user = self.env["res.users"].create(
{"login": "test_refund_with_so", "name": "Test"}
)
Expand Down
6 changes: 0 additions & 6 deletions rma_sale_mrp/tests/test_rma_sale_mrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ def test_create_rma_from_so(self):
rma_2.mapped("reception_move_id.origin_returned_move_id"),
move_2,
)
self.assertEqual(
rmas.mapped("reception_move_id.picking_id")
+ self.order_out_picking
+ self.backorder,
order.picking_ids,
)
# Refund the RMA
user = self.env["res.users"].create(
{"login": "test_refund_with_so", "name": "Test"}
Expand Down

0 comments on commit 81e6ff8

Please sign in to comment.