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/wizard/stock_picking_return.py b/rma/wizard/stock_picking_return.py
index 3bed8265a..cf9fe49fd 100644
--- a/rma/wizard/stock_picking_return.py
+++ b/rma/wizard/stock_picking_return.py
@@ -18,6 +18,14 @@ class ReturnPickingLine(models.TransientModel):
store=True,
readonly=False,
)
+ 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="rma_operation_id.different_return_product"
+ )
@api.depends("wizard_id.rma_operation_id")
def _compute_rma_operation_id(self):
@@ -34,6 +42,7 @@ def _prepare_rma_vals(self):
"product_uom": self.product_id.uom_id.id,
"location_id": self.wizard_id.location_id.id or self.move_id.location_id.id,
"operation_id": self.rma_operation_id.id,
+ "return_product_id": self.return_product_id.id,
}
diff --git a/rma/wizard/stock_picking_return_views.xml b/rma/wizard/stock_picking_return_views.xml
index ce127da35..ed6e062f9 100644
--- a/rma/wizard/stock_picking_return_views.xml
+++ b/rma/wizard/stock_picking_return_views.xml
@@ -13,6 +13,11 @@
name="rma_operation_id"
attrs="{'column_invisible': [('parent.create_rma', '=', False)], 'required': [('parent.create_rma', '=', True), ('quantity', '>', 0)]}"
/>
+
+
diff --git a/rma_sale/tests/test_rma_sale.py b/rma_sale/tests/test_rma_sale.py
index f670f2918..003340c86 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
@@ -232,7 +233,7 @@ def test_manual_refund_no_quantity_impact(self):
self.assertEqual(order_line.qty_delivered, 5)
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)
+ self.assertFalse(rma.reception_move_id.sale_line_id)
rma.action_confirm()
rma.reception_move_id.quantity_done = rma.product_uom_qty
rma.reception_move_id.picking_id._action_done()
@@ -248,7 +249,6 @@ 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()
@@ -266,3 +266,27 @@ def test_no_manual_refund_quantity_impact(self):
picking.move_ids.quantity_done = rma.product_uom_qty
picking._action_done()
self.assertEqual(order.order_line.qty_delivered, 5)
+
+ 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)]}"
/>
+
+