From 5261de6f5b7b815eec710c185d7b55167ec0640e Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Thu, 29 Aug 2024 14:19:06 +0200 Subject: [PATCH] [IMP] rma: allow return different product --- rma/models/rma.py | 23 ++++++++++++++-- rma/models/rma_operation.py | 4 +++ rma/tests/test_rma_operation.py | 6 +++++ rma/views/rma_operation.xml | 8 +++++- rma/views/rma_views.xml | 6 +++++ rma/wizard/stock_picking_return.py | 9 +++++++ rma/wizard/stock_picking_return_views.xml | 5 ++++ rma_sale/tests/test_rma_sale.py | 26 ++++++++++++++++++- rma_sale/wizard/sale_order_rma_wizard.py | 9 +++++++ .../wizard/sale_order_rma_wizard_views.xml | 5 ++++ 10 files changed, 97 insertions(+), 4 deletions(-) diff --git a/rma/models/rma.py b/rma/models/rma.py index 697e1bca7..126a05515 100644 --- a/rma/models/rma.py +++ b/rma/models/rma.py @@ -329,6 +329,14 @@ def _domain_location_id(self): show_create_refund = fields.Boolean( string="Show Create refund Button", compute="_compute_show_refund_replace" ) + return_product_id = fields.Many2one( + "product.product", + help="Product to be returned if it's different from the originally delivered " + "item.", + ) + different_return_product = fields.Boolean( + related="operation_id.different_return_product" + ) @api.depends("operation_id.action_create_receipt", "state", "reception_move_id") def _compute_show_create_receipt(self): @@ -788,13 +796,24 @@ def _prepare_reception_procurements(self): group = rma.procurement_group_id if not group: group = group_model.create(rma._prepare_procurement_group_vals()) + product = self.product_id + if self.different_return_product: + if not self.return_product_id: + raise ValidationError( + _( + "The selected operation requires a return product different" + " from the originally delivered item. Please select the " + "product to return." + ) + ) + product = self.return_product_id procurements.append( group_model.Procurement( - rma.product_id, + product, rma.product_uom_qty, rma.product_uom, rma.location_id, - rma.product_id.display_name, + product.display_name, group.name, rma.company_id, rma._prepare_reception_procurement_vals(group), diff --git a/rma/models/rma_operation.py b/rma/models/rma_operation.py index 32ddef1fd..17a05af0e 100644 --- a/rma/models/rma_operation.py +++ b/rma/models/rma_operation.py @@ -19,6 +19,10 @@ class RmaOperation(models.Model): default="automatic_on_confirm", help="Define how the receipt action should be handled.", ) + different_return_product = fields.Boolean( + help="If checked, allows the return of a product different from the one " + "originally ordered. Used if the delivery is created automatically", + ) action_create_delivery = fields.Selection( [ ("manual_on_confirm", "Manually on Confirm"), diff --git a/rma/tests/test_rma_operation.py b/rma/tests/test_rma_operation.py index 49dc92b45..2957ed4bd 100644 --- a/rma/tests/test_rma_operation.py +++ b/rma/tests/test_rma_operation.py @@ -149,7 +149,13 @@ def test_07(self): ValidationError, msg="Complete the replacement information" ): rma.action_confirm() + rma.return_product_id = self.product_product.create( + {"name": "return Product test 1", "type": "product"} + ) 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") def test_08(self): """test refund, manually after confirm""" diff --git a/rma/views/rma_operation.xml b/rma/views/rma_operation.xml index 02de01896..1ed1d82f6 100644 --- a/rma/views/rma_operation.xml +++ b/rma/views/rma_operation.xml @@ -17,7 +17,13 @@ - + + + diff --git a/rma/views/rma_views.xml b/rma/views/rma_views.xml index e100dcac9..b95aaaeb1 100644 --- a/rma/views/rma_views.xml +++ b/rma/views/rma_views.xml @@ -272,6 +272,11 @@ force_save="1" attrs="{'readonly': ['|', ('picking_id', '!=', False), ('state', '!=', 'draft')]}" /> +