diff --git a/rma/models/rma.py b/rma/models/rma.py index 5921848e9..9084925ff 100644 --- a/rma/models/rma.py +++ b/rma/models/rma.py @@ -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, @@ -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() diff --git a/rma/tests/test_rma.py b/rma/tests/test_rma.py index 7b798fcb8..83248889d 100644 --- a/rma/tests/test_rma.py +++ b/rma/tests/test_rma.py @@ -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) diff --git a/rma_sale/models/rma.py b/rma_sale/models/rma.py index 7662ba5fa..b07b71517 100644 --- a/rma_sale/models/rma.py +++ b/rma_sale/models/rma.py @@ -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 - ) diff --git a/rma_sale/tests/test_rma_sale.py b/rma_sale/tests/test_rma_sale.py index 532230d1d..daf2c5012 100644 --- a/rma_sale/tests/test_rma_sale.py +++ b/rma_sale/tests/test_rma_sale.py @@ -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"} ) diff --git a/rma_sale_mrp/tests/test_rma_sale_mrp.py b/rma_sale_mrp/tests/test_rma_sale_mrp.py index 2276860d5..3508c43ff 100644 --- a/rma_sale_mrp/tests/test_rma_sale_mrp.py +++ b/rma_sale_mrp/tests/test_rma_sale_mrp.py @@ -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"}