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')]}"
/>
+
@@ -352,6 +357,7 @@
+
diff --git a/rma_sale/tests/test_rma_sale.py b/rma_sale/tests/test_rma_sale.py
index a62c150b1..a47512016 100644
--- a/rma_sale/tests/test_rma_sale.py
+++ b/rma_sale/tests/test_rma_sale.py
@@ -3,6 +3,7 @@
# Copyright 2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
+from odoo.exceptions import ValidationError
from odoo.tests import Form, TransactionCase
from odoo.tests.common import users
@@ -248,8 +249,31 @@ def test_no_manual_refund_quantity_impact(self):
wizard = self._rma_sale_wizard(order)
rma = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"])
self.assertEqual(rma.reception_move_id.sale_line_id, order_line)
- rma.action_confirm()
self.assertFalse(rma.can_be_refunded)
rma.reception_move_id.quantity_done = rma.product_uom_qty
rma.reception_move_id.picking_id._action_done()
self.assertEqual(order.order_line.qty_delivered, 0)
+
+ def test_return_different_product(self):
+ self.operation.action_create_delivery = False
+ self.operation.different_return_product = True
+ self.operation.action_create_refund = "update_quantity"
+ order = self.sale_order
+ order_line = order.order_line
+ self.assertEqual(order_line.qty_delivered, 5)
+ wizard = self._rma_sale_wizard(order)
+ with self.assertRaises(
+ ValidationError, msg="Complete the replacement information"
+ ):
+ rma = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"])
+ return_product = self.product_product.create(
+ {"name": "return Product test 1", "type": "product"}
+ )
+ wizard.line_ids.return_product_id = return_product
+ rma = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"])
+ self.assertEqual(rma.reception_move_id.sale_line_id, order_line)
+ self.assertEqual(rma.reception_move_id.product_id, return_product)
+ self.assertFalse(rma.can_be_refunded)
+ rma.reception_move_id.quantity_done = rma.product_uom_qty
+ rma.reception_move_id.picking_id._action_done()
+ self.assertEqual(order.order_line.qty_delivered, 5)
diff --git a/rma_sale/wizard/sale_order_rma_wizard.py b/rma_sale/wizard/sale_order_rma_wizard.py
index 60146c84f..69c35d6a3 100644
--- a/rma_sale/wizard/sale_order_rma_wizard.py
+++ b/rma_sale/wizard/sale_order_rma_wizard.py
@@ -157,6 +157,14 @@ class SaleOrderLineRmaWizard(models.TransientModel):
comodel_name="sale.order.line",
)
description = fields.Text()
+ 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("wizard_id.operation_id")
def _compute_operation_id(self):
@@ -223,4 +231,5 @@ def _prepare_rma_values(self):
"product_uom": self.uom_id.id,
"operation_id": self.operation_id.id,
"description": description,
+ "return_product_id": self.return_product_id.id,
}
diff --git a/rma_sale/wizard/sale_order_rma_wizard_views.xml b/rma_sale/wizard/sale_order_rma_wizard_views.xml
index 24e0f0cb4..02da5b965 100644
--- a/rma_sale/wizard/sale_order_rma_wizard_views.xml
+++ b/rma_sale/wizard/sale_order_rma_wizard_views.xml
@@ -35,6 +35,11 @@
name="operation_id"
attrs="{'required': [('quantity', '>', 0)]}"
/>
+
+