Skip to content

Commit 5261de6

Browse files
committed
[IMP] rma: allow return different product
1 parent 957a298 commit 5261de6

File tree

10 files changed

+97
-4
lines changed

10 files changed

+97
-4
lines changed

rma/models/rma.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,14 @@ def _domain_location_id(self):
329329
show_create_refund = fields.Boolean(
330330
string="Show Create refund Button", compute="_compute_show_refund_replace"
331331
)
332+
return_product_id = fields.Many2one(
333+
"product.product",
334+
help="Product to be returned if it's different from the originally delivered "
335+
"item.",
336+
)
337+
different_return_product = fields.Boolean(
338+
related="operation_id.different_return_product"
339+
)
332340

333341
@api.depends("operation_id.action_create_receipt", "state", "reception_move_id")
334342
def _compute_show_create_receipt(self):
@@ -788,13 +796,24 @@ def _prepare_reception_procurements(self):
788796
group = rma.procurement_group_id
789797
if not group:
790798
group = group_model.create(rma._prepare_procurement_group_vals())
799+
product = self.product_id
800+
if self.different_return_product:
801+
if not self.return_product_id:
802+
raise ValidationError(
803+
_(
804+
"The selected operation requires a return product different"
805+
" from the originally delivered item. Please select the "
806+
"product to return."
807+
)
808+
)
809+
product = self.return_product_id
791810
procurements.append(
792811
group_model.Procurement(
793-
rma.product_id,
812+
product,
794813
rma.product_uom_qty,
795814
rma.product_uom,
796815
rma.location_id,
797-
rma.product_id.display_name,
816+
product.display_name,
798817
group.name,
799818
rma.company_id,
800819
rma._prepare_reception_procurement_vals(group),

rma/models/rma_operation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class RmaOperation(models.Model):
1919
default="automatic_on_confirm",
2020
help="Define how the receipt action should be handled.",
2121
)
22+
different_return_product = fields.Boolean(
23+
help="If checked, allows the return of a product different from the one "
24+
"originally ordered. Used if the delivery is created automatically",
25+
)
2226
action_create_delivery = fields.Selection(
2327
[
2428
("manual_on_confirm", "Manually on Confirm"),

rma/tests/test_rma_operation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,13 @@ def test_07(self):
149149
ValidationError, msg="Complete the replacement information"
150150
):
151151
rma.action_confirm()
152+
rma.return_product_id = self.product_product.create(
153+
{"name": "return Product test 1", "type": "product"}
154+
)
152155
rma.action_confirm()
156+
self.assertEqual(rma.delivery_move_ids.product_id, rma.product_id)
157+
self.assertEqual(rma.reception_move_id.product_id, rma.return_product_id)
158+
self.assertEqual(rma.state, "waiting_return")
153159

154160
def test_08(self):
155161
"""test refund, manually after confirm"""

rma/views/rma_operation.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
<field name="action_create_receipt" />
1818

1919
</group>
20-
<group />
20+
<group>
21+
<field
22+
name="different_return_product"
23+
widget="boolean_toggle"
24+
attrs="{'invisible': [('action_create_receipt', '=', False)]}"
25+
/>
26+
</group>
2127
<group>
2228
<field name="action_create_delivery" />
2329

rma/views/rma_views.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@
272272
force_save="1"
273273
attrs="{'readonly': ['|', ('picking_id', '!=', False), ('state', '!=', 'draft')]}"
274274
/>
275+
<field
276+
name="return_product_id"
277+
force_save="1"
278+
attrs="{'readonly': ['|', ('picking_id', '!=', False), ('state', '!=', 'draft')], 'invisible': [('different_return_product', '=', False)], 'required': [('different_return_product', '=', True)]}"
279+
/>
275280
<field name="uom_category_id" invisible="1" />
276281
<label for="product_uom_qty" />
277282
<div class="o_row">
@@ -352,6 +357,7 @@
352357
<field name="show_create_refund" invisible="1" />
353358
<field name="show_create_return" invisible="1" />
354359
<field name="show_create_replace" invisible="1" />
360+
<field name="different_return_product" invisible="1" />
355361
<field name="can_be_split" invisible="1" />
356362
<field name="can_be_locked" invisible="1" />
357363
<field name="can_be_finished" invisible="1" />

rma/wizard/stock_picking_return.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ class ReturnPickingLine(models.TransientModel):
1818
store=True,
1919
readonly=False,
2020
)
21+
return_product_id = fields.Many2one(
22+
"product.product",
23+
help="Product to be returned if it's different from the originally delivered "
24+
"item.",
25+
)
26+
different_return_product = fields.Boolean(
27+
related="rma_operation_id.different_return_product"
28+
)
2129

2230
@api.depends("wizard_id.rma_operation_id")
2331
def _compute_rma_operation_id(self):
@@ -34,6 +42,7 @@ def _prepare_rma_vals(self):
3442
"product_uom": self.product_id.uom_id.id,
3543
"location_id": self.wizard_id.location_id.id or self.move_id.location_id.id,
3644
"operation_id": self.rma_operation_id.id,
45+
"return_product_id": self.return_product_id.id,
3746
}
3847

3948

rma/wizard/stock_picking_return_views.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
name="rma_operation_id"
1414
attrs="{'column_invisible': [('parent.create_rma', '=', False)], 'required': [('parent.create_rma', '=', True), ('quantity', '>', 0)]}"
1515
/>
16+
<field
17+
name="return_product_id"
18+
attrs="{'column_invisible': [('parent.create_rma', '=', False)], 'invisible': [('different_return_product', '=', False)], 'required': [('different_return_product', '=', True)]}"
19+
/>
20+
<field name="different_return_product" invisible="1" />
1621
</xpath>
1722
<field name="product_return_moves" position="before">
1823
<group name="group_rma">

rma_sale/tests/test_rma_sale.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Copyright 2023 Tecnativa - Pedro M. Baeza
44
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
55

6+
from odoo.exceptions import ValidationError
67
from odoo.tests import Form, TransactionCase
78
from odoo.tests.common import users
89

@@ -248,8 +249,31 @@ def test_no_manual_refund_quantity_impact(self):
248249
wizard = self._rma_sale_wizard(order)
249250
rma = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"])
250251
self.assertEqual(rma.reception_move_id.sale_line_id, order_line)
251-
rma.action_confirm()
252252
self.assertFalse(rma.can_be_refunded)
253253
rma.reception_move_id.quantity_done = rma.product_uom_qty
254254
rma.reception_move_id.picking_id._action_done()
255255
self.assertEqual(order.order_line.qty_delivered, 0)
256+
257+
def test_return_different_product(self):
258+
self.operation.action_create_delivery = False
259+
self.operation.different_return_product = True
260+
self.operation.action_create_refund = "update_quantity"
261+
order = self.sale_order
262+
order_line = order.order_line
263+
self.assertEqual(order_line.qty_delivered, 5)
264+
wizard = self._rma_sale_wizard(order)
265+
with self.assertRaises(
266+
ValidationError, msg="Complete the replacement information"
267+
):
268+
rma = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"])
269+
return_product = self.product_product.create(
270+
{"name": "return Product test 1", "type": "product"}
271+
)
272+
wizard.line_ids.return_product_id = return_product
273+
rma = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"])
274+
self.assertEqual(rma.reception_move_id.sale_line_id, order_line)
275+
self.assertEqual(rma.reception_move_id.product_id, return_product)
276+
self.assertFalse(rma.can_be_refunded)
277+
rma.reception_move_id.quantity_done = rma.product_uom_qty
278+
rma.reception_move_id.picking_id._action_done()
279+
self.assertEqual(order.order_line.qty_delivered, 5)

rma_sale/wizard/sale_order_rma_wizard.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ class SaleOrderLineRmaWizard(models.TransientModel):
157157
comodel_name="sale.order.line",
158158
)
159159
description = fields.Text()
160+
return_product_id = fields.Many2one(
161+
"product.product",
162+
help="Product to be returned if it's different from the originally delivered "
163+
"item.",
164+
)
165+
different_return_product = fields.Boolean(
166+
related="operation_id.different_return_product"
167+
)
160168

161169
@api.depends("wizard_id.operation_id")
162170
def _compute_operation_id(self):
@@ -223,4 +231,5 @@ def _prepare_rma_values(self):
223231
"product_uom": self.uom_id.id,
224232
"operation_id": self.operation_id.id,
225233
"description": description,
234+
"return_product_id": self.return_product_id.id,
226235
}

rma_sale/wizard/sale_order_rma_wizard_views.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
name="operation_id"
3636
attrs="{'required': [('quantity', '>', 0)]}"
3737
/>
38+
<field
39+
name="return_product_id"
40+
attrs="{'invisible': [('different_return_product', '=', False)], 'required': [('different_return_product', '=', True)]}"
41+
/>
42+
<field name="different_return_product" invisible="1" />
3843
</tree>
3944
</field>
4045
</group>

0 commit comments

Comments
 (0)