From 23da1ccb94dbd9603ccd8ba71e5efcb6b3eb55a2 Mon Sep 17 00:00:00 2001 From: Joan Sisquella Date: Thu, 25 May 2023 17:53:49 +0200 Subject: [PATCH] [FIX] rma: procurement origin In the current implementation of Odoo's _assign_picking() method in stock.move, there's a conditional check that looks at whether all the moves associated with a picking have the same partner_id and origin. If any move doesn't align with these conditions, the origin of the picking is set to False. if any(picking.partner_id.id != m.partner_id.id or picking.origin != m.origin for m in moves): # If a picking is found, we'll append `move` to its move list and thus its # `partner_id` and `ref` field will refer to multiple records. In this # case, we chose to wipe them. picking.write({ 'partner_id': False, 'origin': False, }) In the context of RMA when we have multiple moves associated with a picking, each coming from a different RMA order line, we encounter a problem. Each move has its origin set as the name of the RMA orde line (line.name), so as soon as a second move from a different line is appended to the picking, the origin of the picking is wiped, because it doesn't match the origin of the first move. In order to prevent the partner_id of the picking from being set to False when there are multiple associated moves, I propose that we change the origin of the procurement from the name of the RMA line to the name of the procurement group (group.name). This way, all moves associated with a picking will share the same origin, preserving the origin of the picking and ensuring it doesn't get inadvertently set to False. --- rma/tests/test_rma.py | 23 +++++++++++++++++++++-- rma/wizards/rma_make_picking.py | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/rma/tests/test_rma.py b/rma/tests/test_rma.py index 85880964..35059202 100644 --- a/rma/tests/test_rma.py +++ b/rma/tests/test_rma.py @@ -766,7 +766,9 @@ class TestRma(common.TransactionCase): wizard._create_picking() res = self.rma_supplier_id.rma_line_ids.action_view_out_shipments() self.assertTrue("res_id" in res, "Incorrect number of pickings" "created") - picking = self.env["stock.picking"].browse(res["res_id"]) + picking = self.rma_supplier_id.rma_line_ids._get_out_pickings() + partner = picking.partner_id + self.assertTrue(partner, "Partner is not defined or False") moves = picking.move_ids self.assertEqual(len(moves), 3, "Incorrect number of moves created") @@ -886,7 +888,9 @@ class TestRma(common.TransactionCase): pickings = self.env["stock.picking"].browse(res["res_id"]) self.assertEqual(len(pickings), 1, "Incorrect number of pickings created") picking_in = pickings[0] - moves = picking_in.move_ids + partner = picking_in.partner_id + self.assertTrue(partner, "Partner is not defined or False") + moves = picking.move_ids self.assertEqual(len(moves), 3, "Incorrect number of moves created") lines = self.rma_supplier_id.rma_line_ids @@ -1064,3 +1068,18 @@ class TestRma(common.TransactionCase): ).create({}) with self.assertRaisesRegex(ValidationError, "No quantity to transfer"): wizard._create_picking() + + def test_08_supplier_rma_single_line(self): + rma_line_id = self.rma_supplier_id.rma_line_ids[0].id + wizard = self.rma_make_picking.with_context( + active_ids=[rma_line_id], + active_model="rma.order.line", + picking_type="outgoing", + active_id=2, + ).create({}) + wizard._create_picking() + picking = self.rma_supplier_id.rma_line_ids[0]._get_out_pickings() + partner = picking.partner_id + self.assertTrue(partner, "Partner is not defined or False") + moves = picking.move_ids + self.assertEqual(len(moves), 1, "Incorrect number of moves created") diff --git a/rma/wizards/rma_make_picking.py b/rma/wizards/rma_make_picking.py index f2841609..e066d07f 100644 --- a/rma/wizards/rma_make_picking.py +++ b/rma/wizards/rma_make_picking.py @@ -124,7 +124,7 @@ class RmaMakePicking(models.TransientModel): procurement_data = { "name": line.rma_id and line.rma_id.name or line.name, "group_id": group, - "origin": line.name, + "origin": group and group.name or line.name, "warehouse_id": warehouse, "date_planned": time.strftime(DT_FORMAT), "product_id": item.product_id,