Skip to content

Commit 4969682

Browse files
committed
[IMP] rma_delivery: Add carrier_id field to RMA
1 parent 0e694b4 commit 4969682

File tree

12 files changed

+82
-30
lines changed

12 files changed

+82
-30
lines changed

rma_delivery/README.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ To configure RMAs shipping strategy for your company:
4343

4444
#. Go to *Inventory > Configuration > Settings*
4545
#. Choose an *RMA delivery method strategy*.
46-
#. There are 3 possibilities:
46+
#. There are 4 possibilities:
4747

4848
- Fixed method: the method will always be the same. Select it on the field *Default RMA delivery method*
4949
(or leave it empty for no delivery method at all).
5050
- Customer method: the method will be the one configured on the partner.
5151
- Mixed method: the method will be the one configured on the partner, otherwise
5252
the fixed one will be chosen.
53+
- RMA method: the method will be configured in each RMA.
5354

5455
Usage
5556
=====
@@ -85,6 +86,7 @@ Contributors
8586
* `Tecnativa <https://www.tecnativa.com>`_:
8687

8788
* David Vidal
89+
* Víctor Martínez
8890

8991
* Souheil Bejaoui - ACSONE SA/NV <[email protected]>
9092

rma_delivery/__manifest__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
"maintainers": ["chienandalu"],
1212
"license": "AGPL-3",
1313
"depends": ["rma", "delivery"],
14-
"data": ["views/res_config_settings_views.xml"],
14+
"data": [
15+
"views/res_config_settings_views.xml",
16+
"views/rma_views.xml",
17+
],
1518
}

rma_delivery/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from . import res_company
22
from . import res_config_settings
33
from . import rma
4+
from . import stock_move

rma_delivery/models/res_company.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Company(models.Model):
1212
("fixed_method", "Fixed method"),
1313
("customer_method", "Customer method"),
1414
("mixed_method", "Customer method (fallback to fixed)"),
15+
("rma_method", "RMA method"),
1516
],
1617
string="RMA delivery method strategy",
1718
default="mixed_method",

rma_delivery/models/rma.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# Copyright 2022 Tecnativa - David Vidal
2+
# Copyright 2026 Tecnativa - Víctor Martínez
23
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3-
from odoo import models
4+
from odoo import fields, models
45

56

67
class Rma(models.Model):
78
_inherit = "rma"
89

10+
carrier_id = fields.Many2one(
11+
comodel_name="delivery.carrier",
12+
string="Carrier",
13+
)
14+
rma_delivery_strategy = fields.Selection(related="company_id.rma_delivery_strategy")
15+
916
def _get_default_carrier_id(self, company, partner):
1017
"""Gather the company option for default carrier on RMA returns. We could
1118
either:
@@ -25,27 +32,11 @@ def _get_default_carrier_id(self, company, partner):
2532
delivery_method = partner_method
2633
return delivery_method
2734

28-
def _prepare_returning_picking(self, picking_form, origin=None):
29-
res = super()._prepare_returning_picking(picking_form, origin)
30-
picking_form.carrier_id = self._get_default_carrier_id(
31-
picking_form.company_id, picking_form.partner_id
32-
)
33-
return res
34-
35-
def _set_carrier(self, pickings):
36-
for picking in pickings:
37-
picking.carrier_id = self._get_default_carrier_id(
38-
picking.company_id, picking.partner_id
35+
def _get_carrier(self):
36+
self.ensure_one()
37+
if self.rma_delivery_strategy == "rma":
38+
return self.carrier_id
39+
else:
40+
return self._get_default_carrier_id(
41+
self.company_id, self.partner_shipping_id
3942
)
40-
41-
def create_replace(self, scheduled_date, warehouse, product, qty, uom):
42-
existing_pickings = self.delivery_move_ids.picking_id
43-
res = super().create_replace(scheduled_date, warehouse, product, qty, uom)
44-
self._set_carrier(self.delivery_move_ids.picking_id - existing_pickings)
45-
return res
46-
47-
def create_return(self, scheduled_date, qty=None, uom=None):
48-
existing_pickings = self.delivery_move_ids.picking_id
49-
res = super().create_return(scheduled_date, qty=qty, uom=uom)
50-
self._set_carrier(self.delivery_move_ids.picking_id - existing_pickings)
51-
return res

rma_delivery/models/stock_move.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2026 Tecnativa - Víctor Martínez
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from odoo import models
4+
5+
6+
class StockMove(models.Model):
7+
_inherit = "stock.move"
8+
9+
def _get_new_picking_values(self):
10+
vals = super()._get_new_picking_values()
11+
if self.rma_id:
12+
carrier = self.rma_id._get_carrier()
13+
if carrier and any(rule.propagate_carrier for rule in self.rule_id):
14+
vals["carrier_id"] = carrier.id
15+
return vals

rma_delivery/readme/CONFIGURE.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ To configure RMAs shipping strategy for your company:
22

33
#. Go to *Inventory > Configuration > Settings*
44
#. Choose an *RMA delivery method strategy*.
5-
#. There are 3 possibilities:
5+
#. There are 4 possibilities:
66

77
- Fixed method: the method will always be the same. Select it on the field *Default RMA delivery method*
88
(or leave it empty for no delivery method at all).
99
- Customer method: the method will be the one configured on the partner.
1010
- Mixed method: the method will be the one configured on the partner, otherwise
1111
the fixed one will be chosen.
12+
- RMA method: the method will be configured in each RMA.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
* `Tecnativa <https://www.tecnativa.com>`_:
22

33
* David Vidal
4+
* Víctor Martínez
45

56
* Souheil Bejaoui - ACSONE SA/NV <[email protected]>

rma_delivery/static/description/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,13 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
392392
<ol class="arabic simple">
393393
<li>Go to <em>Inventory &gt; Configuration &gt; Settings</em></li>
394394
<li>Choose an <em>RMA delivery method strategy</em>.</li>
395-
<li>There are 3 possibilities:<ul>
395+
<li>There are 4 possibilities:<ul>
396396
<li>Fixed method: the method will always be the same. Select it on the field <em>Default RMA delivery method</em>
397397
(or leave it empty for no delivery method at all).</li>
398398
<li>Customer method: the method will be the one configured on the partner.</li>
399399
<li>Mixed method: the method will be the one configured on the partner, otherwise
400400
the fixed one will be chosen.</li>
401+
<li>RMA method: the method will be configured in each RMA.</li>
401402
</ul>
402403
</li>
403404
</ol>
@@ -433,6 +434,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
433434
<ul class="simple">
434435
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
435436
<li>David Vidal</li>
437+
<li>Víctor Martínez</li>
436438
</ul>
437439
</li>
438440
<li>Souheil Bejaoui - ACSONE SA/NV &lt;<a class="reference external" href="mailto:souheil.bejaoui&#64;acsone.eu">souheil.bejaoui&#64;acsone.eu</a>&gt;</li>

rma_delivery/tests/test_rma_delivery.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2022 Tecnativa - David Vidal
2+
# Copyright 2026 Tecnativa - Víctor Martínez
23
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
34
from odoo.tests import Form
45

@@ -143,3 +144,19 @@ def test_03_mixed_method(self):
143144
self.carrier,
144145
"The carrier isn't the one set in the company as default",
145146
)
147+
148+
def test_04_rma_method(self):
149+
self.company.rma_delivery_strategy = "rma_method"
150+
rma = self._create_confirm_receive(
151+
self.partner_shipping, self.product, 1, self.rma_loc
152+
)
153+
rma.carrier_id = self.carrier
154+
picking = self._return_to_customer(rma)
155+
self.assertEqual(picking.carrier_id, self.carrier)
156+
# Replace picking
157+
rma = self._create_confirm_receive(
158+
self.partner_shipping, self.product, 1, self.rma_loc
159+
)
160+
rma.carrier_id = self.carrier
161+
picking = self._return_to_customer(rma, "replace")
162+
self.assertEqual(picking.carrier_id, self.carrier)

0 commit comments

Comments
 (0)