Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions rma_delivery/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

==================================================================
Return Merchandise Authorization Management - Link with deliveries
==================================================================
Expand All @@ -17,7 +13,7 @@ Return Merchandise Authorization Management - Link with deliveries
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frma-lightgray.png?logo=github
Expand All @@ -33,7 +29,7 @@ Return Merchandise Authorization Management - Link with deliveries
|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of the RMA module to allow to choose a default
behavior for the shipping method used on the RMA returns to the customer.
behavior for the shipping method used on the RMA receipt/returns to the customer.

**Table of contents**

Expand All @@ -56,6 +52,17 @@ To configure RMAs shipping strategy for your company:
the fixed one will be chosen.
- RMA method: the method will be configured in each RMA.


#. Choose an *RMA reception method strategy*.
#. There are 4 possibilities:

- Fixed method: the method will always be the same. Select it on the field *Default RMA delivery method*
(or leave it empty for no delivery method at all).
- Customer method: the method will be the one configured on the partner.
- Mixed method: the method will be the one configured on the partner, otherwise
the fixed one will be chosen.


Usage
=====

Expand Down
15 changes: 15 additions & 0 deletions rma_delivery/models/res_company.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2022 Tecnativa - David Vidal
# Copyright 2026 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models
Expand All @@ -21,3 +22,17 @@ class Company(models.Model):
comodel_name="delivery.carrier",
string="Default RMA delivery method",
)
rma_reception_strategy = fields.Selection(
selection=[
("fixed_method", "Fixed method"),
("customer_method", "Customer method"),
("mixed_method", "Customer method (fallback to fixed)"),
("rma_method", "RMA method"),
],
string="RMA reception method strategy",
default="mixed_method",
)
rma_fixed_reception_strategy = fields.Many2one(
comodel_name="delivery.carrier",
string="Default RMA reception method",
)
9 changes: 9 additions & 0 deletions rma_delivery/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2022 Tecnativa - David Vidal
# Copyright 2026 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models

Expand All @@ -14,3 +15,11 @@ class ResConfigSettings(models.TransientModel):
related="company_id.rma_fixed_delivery_method",
readonly=False,
)
rma_reception_strategy = fields.Selection(
related="company_id.rma_reception_strategy",
readonly=False,
)
rma_fixed_reception_strategy = fields.Many2one(
related="company_id.rma_fixed_reception_strategy",
readonly=False,
)
35 changes: 35 additions & 0 deletions rma_delivery/models/rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ class Rma(models.Model):
string="Carrier",
)
rma_delivery_strategy = fields.Selection(related="company_id.rma_delivery_strategy")
reception_carrier_id = fields.Many2one(
comodel_name="delivery.carrier",
string="Reception Carrier",
)
rma_reception_strategy = fields.Selection(
related="company_id.rma_reception_strategy"
)

def _get_default_carrier_id(self, company, partner):
"""Gather the company option for default carrier on RMA returns. We could
Expand Down Expand Up @@ -40,3 +47,31 @@ def _get_carrier(self):
return self._get_default_carrier_id(
self.company_id, self.partner_shipping_id
)

def _get_default_reception_carrier_id(self, company, partner):
"""Gather the company option for default carrier on RMA reception.
We could either:
- Get a fixed method
- Get the partner's defined method (or his commercial entity one)
- Get the partner's and fallback to a fixed one if defined
"""
strategy = company.rma_reception_strategy
delivery_method = company.rma_fixed_reception_strategy
partner_method = (
partner.property_delivery_carrier_id
or partner.commercial_partner_id.property_delivery_carrier_id
)
if strategy == "customer_method" or (
strategy == "mixed_method" and partner_method
):
delivery_method = partner_method
return delivery_method

def _get_reception_carrier(self):
self.ensure_one()
if self.rma_reception_strategy == "rma_method":
return self.reception_carrier_id
else:
return self._get_default_reception_carrier_id(
self.company_id, self.partner_shipping_id
)
7 changes: 5 additions & 2 deletions rma_delivery/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ class StockMove(models.Model):

def _get_new_picking_values(self):
vals = super()._get_new_picking_values()
carrier = self.env["delivery.carrier"]
if self.rma_id:
carrier = self.rma_id[0]._get_carrier()
if carrier and any(rule.propagate_carrier for rule in self.rule_id):
vals["carrier_id"] = carrier.id
elif self.rma_receiver_ids:
carrier = self.rma_receiver_ids[0]._get_reception_carrier()
if carrier and any(rule.propagate_carrier for rule in self.rule_id):
vals["carrier_id"] = carrier.id
return vals
11 changes: 11 additions & 0 deletions rma_delivery/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@ To configure RMAs shipping strategy for your company:
- Mixed method: the method will be the one configured on the partner, otherwise
the fixed one will be chosen.
- RMA method: the method will be configured in each RMA.


#. Choose an *RMA reception method strategy*.
#. There are 4 possibilities:

- Fixed method: the method will always be the same. Select it on the field *Default RMA delivery method*
(or leave it empty for no delivery method at all).
- Customer method: the method will be the one configured on the partner.
- Mixed method: the method will be the one configured on the partner, otherwise
the fixed one will be chosen.

2 changes: 1 addition & 1 deletion rma_delivery/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
This module extends the functionality of the RMA module to allow to choose a default
behavior for the shipping method used on the RMA returns to the customer.
behavior for the shipping method used on the RMA receipt/returns to the customer.
39 changes: 21 additions & 18 deletions rma_delivery/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Return Merchandise Authorization Management - Link with deliveries</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,23 +360,18 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="return-merchandise-authorization-management-link-with-deliveries">
<h1 class="title">Return Merchandise Authorization Management - Link with deliveries</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="return-merchandise-authorization-management-link-with-deliveries">
<h1>Return Merchandise Authorization Management - Link with deliveries</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:921f8abef9821857ab5b0434e129debe09dd34ddbf9ac38141c39adf1c8b68ac
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rma/tree/16.0/rma_delivery"><img alt="OCA/rma" src="https://img.shields.io/badge/github-OCA%2Frma-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rma-16-0/rma-16-0-rma_delivery"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rma&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rma/tree/16.0/rma_delivery"><img alt="OCA/rma" src="https://img.shields.io/badge/github-OCA%2Frma-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rma-16-0/rma-16-0-rma_delivery"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rma&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of the RMA module to allow to choose a default
behavior for the shipping method used on the RMA returns to the customer.</p>
behavior for the shipping method used on the RMA receipt/returns to the customer.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -392,7 +387,7 @@ <h1>Return Merchandise Authorization Management - Link with deliveries</h1>
</ul>
</div>
<div class="section" id="configuration">
<h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>To configure RMAs shipping strategy for your company:</p>
<ol class="arabic simple">
<li>Go to <em>Inventory &gt; Configuration &gt; Settings</em></li>
Expand All @@ -406,10 +401,19 @@ <h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
<li>RMA method: the method will be configured in each RMA.</li>
</ul>
</li>
<li>Choose an <em>RMA reception method strategy</em>.</li>
<li>There are 4 possibilities:<ul>
<li>Fixed method: the method will always be the same. Select it on the field <em>Default RMA delivery method</em>
(or leave it empty for no delivery method at all).</li>
<li>Customer method: the method will be the one configured on the partner.</li>
<li>Mixed method: the method will be the one configured on the partner, otherwise
the fixed one will be chosen.</li>
</ul>
</li>
</ol>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>To use this module, you need to:</p>
<ol class="arabic simple">
<li>Go to a RMA which has received quantities.</li>
Expand All @@ -419,23 +423,23 @@ <h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
</ol>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/rma/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/rma/issues/new?body=module:%20rma_delivery%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>David Vidal</li>
Expand All @@ -446,7 +450,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -461,6 +465,5 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
45 changes: 45 additions & 0 deletions rma_delivery/tests/test_rma_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def setUpClass(cls):
cls.partner.property_delivery_carrier_id = cls.carrier_customer
cls.partner_shipping.property_delivery_carrier_id = False
cls.company.rma_fixed_delivery_method = cls.carrier
cls.company.rma_fixed_reception_strategy = cls.carrier

def _return_to_customer(self, rma, delivery_type="return"):
"""Helper to return the rma"""
Expand Down Expand Up @@ -160,3 +161,47 @@ def test_04_rma_method(self):
rma.carrier_id = self.carrier
picking = self._return_to_customer(rma, "replace")
self.assertEqual(picking.carrier_id, self.carrier)

def test_reception_01_fixed_method(self):
self.company.rma_reception_strategy = "fixed_method"
rma = self._create_rma(self.partner_shipping, self.product, 1, self.rma_loc)
rma.action_confirm()
self.assertEqual(rma.reception_move_id.picking_id.carrier_id, self.carrier)

def test_reception_02_customer_method(self):
self.company.rma_reception_strategy = "customer_method"
rma = self._create_rma(self.partner_shipping, self.product, 1, self.rma_loc)
rma.action_confirm()
self.assertEqual(
rma.reception_move_id.picking_id.carrier_id,
self.carrier_customer,
)
carrier_2 = self.env["delivery.carrier"].create(
{"name": "Test delivery method", "product_id": self.carrier_product.id}
)
self.partner_shipping.property_delivery_carrier_id = carrier_2
rma2 = self._create_rma(self.partner_shipping, self.product, 1, self.rma_loc)
rma2.action_confirm()
self.assertEqual(
rma2.reception_move_id.picking_id.carrier_id,
carrier_2,
)

def test_reception_03_mixed_method(self):
self.company.rma_reception_strategy = "mixed_method"
rma = self._create_rma(self.partner_shipping, self.product, 1, self.rma_loc)
rma.action_confirm()
self.assertEqual(
rma.reception_move_id.picking_id.carrier_id, self.carrier_customer
)
self.partner.property_delivery_carrier_id = False
rma2 = self._create_rma(self.partner_shipping, self.product, 1, self.rma_loc)
rma2.action_confirm()
self.assertEqual(rma2.reception_move_id.picking_id.carrier_id, self.carrier)

def test_reception_04_rma_method(self):
self.company.rma_reception_strategy = "rma_method"
rma = self._create_rma(self.partner_shipping, self.product, 1, self.rma_loc)
rma.reception_carrier_id = self.carrier
rma.action_confirm()
self.assertEqual(rma.reception_move_id.picking_id.carrier_id, self.carrier)
27 changes: 27 additions & 0 deletions rma_delivery/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,33 @@
</div>
</div>
</div>
<div class="o_setting_right_pane">
<label for="rma_reception_strategy" />
<div class="text-muted">
RMA reception strategy
</div>
<div class="content-group">
<div class="mt16">
<field
name="rma_reception_strategy"
class="o_light_label"
/>
</div>
</div>
<div
class="content-group"
attrs="{'invisible': [('rma_reception_strategy', 'in', ('customer_method', 'rma_method'))]}"
>
<label for="rma_fixed_reception_strategy" />
<div class="mt16">
<field
name="rma_fixed_reception_strategy"
class="o_light_label"
widget="selection"
/>
</div>
</div>
</div>
</div>
</xpath>
</field>
Expand Down
5 changes: 5 additions & 0 deletions rma_delivery/views/rma_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
name="carrier_id"
attrs="{'invisible': [('rma_delivery_strategy', '!=', 'rma_method')], 'readonly': [('show_create_refund', '=', False),('show_create_replace', '=', False),('show_create_return', '=', False)]}"
/>
<field name="rma_reception_strategy" invisible="1" />
<field
name="reception_carrier_id"
attrs="{'invisible': [('rma_reception_strategy', '!=', 'rma_method')], 'readonly': [('state', '!=', 'draft')]}"
/>
</field>
</field>
</record>
Expand Down