From 2344852bfe76a10e0bf925d0a0338ad58347e09e Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Wed, 28 Aug 2024 10:17:02 +0200 Subject: [PATCH] [FIX] rma: fix returned quantity in picking return wizard fixes: #418 --- rma/models/rma.py | 1 + rma/tests/test_rma.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/rma/models/rma.py b/rma/models/rma.py index 5921848e9..e108e28a2 100644 --- a/rma/models/rma.py +++ b/rma/models/rma.py @@ -701,6 +701,7 @@ def _prepare_reception_procurement_vals(self, group=None): vals["rma_receiver_ids"] = [(6, 0, self.ids)] if self.move_id: vals["origin_returned_move_id"] = self.move_id.id + vals["move_orig_ids"] = [(6, 0, self.move_id.ids)] return vals def _prepare_reception_procurements(self): diff --git a/rma/tests/test_rma.py b/rma/tests/test_rma.py index 7b798fcb8..d251eb321 100644 --- a/rma/tests/test_rma.py +++ b/rma/tests/test_rma.py @@ -848,3 +848,33 @@ def test_autoconfirm_email(self): ) self.assertTrue(rma.name in mail_receipt.subject) self.assertTrue("products received" in mail_receipt.subject) + + def _create_return_wizard(self, picking): + stock_return_picking_form = Form( + self.env["stock.return.picking"].with_context( + active_ids=picking.ids, + active_id=picking.id, + active_model="stock.picking", + ) + ) + stock_return_picking_form.create_rma = True + stock_return_picking_form.rma_operation_id = self.operation + return stock_return_picking_form.save() + + def test_partial_return(self): + origin_delivery = self._create_delivery() + return_wizard = self._create_return_wizard(origin_delivery) + return_line = return_wizard.product_return_moves.filtered( + lambda m, p=self.product: m.product_id == p + ) + self.assertEqual(return_line.quantity, 10) + return_line.quantity = 5 + picking_action = return_wizard.create_returns() + 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.assertEqual(move.product_qty, 5) + return_wizard = self._create_return_wizard(origin_delivery) + return_line = return_wizard.product_return_moves.filtered( + lambda m, p=self.product: m.product_id == p + ) + self.assertEqual(return_line.quantity, 5)