Skip to content
Open
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
157 changes: 157 additions & 0 deletions rma_sale_stock_restocking_fee_invoicing/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
=======================================
Rma Sale Stock Restocking Fee Invoicing
=======================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4c8ef119dafb288179ed2f770f06093332f3bfcc350cb2fbd7976b603579a8a7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/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
:target: https://github.com/OCA/rma/tree/18.0/rma_sale_stock_restocking_fee_invoicing
:alt: OCA/rma
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/rma-18-0/rma-18-0-rma_sale_stock_restocking_fee_invoicing
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/rma&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the standard RMA flow and the behavior of
``sale_stock_restocking_fee_invoicing`` by allowing:

- Fixed or percentage-based restocking fees.
- Restocking fees configurable on the RMA operation or directly on the
RMA itself.
- Automatic fee application at last step of RMA receipt.
- Integration with different refund strategies:

- Update sale order quantity.
- Manual refund after receipt.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

RMAs often involve administrative and logistic processing costs when
goods are returned. Depending on the company policy and the nature of
the return, these costs may be passed on to the customer as a
*restocking fee*. These restocking fees can be fixed before the customer
returns the product (in case of a late return demand for eg) or decided
in the middle of the return process (if the product is damaged for eg).

Configuration
=============

To enable and configure restocking fees for RMAs:

1. Go to **RMA / Configuration / Operations**.
2. Open the RMA operation for which restocking fees should apply.
3. Set **Restocking Fee Type**:

- **Fixed Amount**: A fixed amount will be added or invoiced.
- **Percentage**: A percentage of the original sale line subtotal is
used.

4. Set the **Restocking Fee Amount**:

- If *fixed*: monetary amount.
- If *percentage*: value between 0 and 100.

It is also possible to add, remove or change restocking fees directly on
the RMA, as soon as the last move of the return moves is not validated
yet.

Usage
=====

Applying a Restocking Fee
-------------------------

1. Create or select a sale order.
2. Deliver the products.
3. Initiate an RMA from the sale order.

The RMA operation determines how the fee will be applied:

1. Update Quantity Strategy
~~~~~~~~~~~~~~~~~~~~~~~~~~~

If the RMA operation "Refund Action" is "Update Quantities":

- A restocking fee sale order line is automatically added when the last
move of the reception chain is validated.
- The fee value depends on the selected fee type.

2. Manual Refund Strategy
~~~~~~~~~~~~~~~~~~~~~~~~~

If the RMA operation uses "Refund Action" is different than "Update
Quantities"

- A restocking fee invoice is automatically created when the last move
of the reception chain is validated.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/rma/issues>`_.
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
`feedback <https://github.com/OCA/rma/issues/new?body=module:%20rma_sale_stock_restocking_fee_invoicing%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ACSONE SA/NV

Contributors
------------

- Souheil Bejaoui - ACSONE SA/NV souheil.bejaoui@acsone.eu
- Marie Lejeune - ACSONE SA/NV marie.lejeune@acsone.eu

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-sbejaoui| image:: https://github.com/sbejaoui.png?size=40px
:target: https://github.com/sbejaoui
:alt: sbejaoui

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-sbejaoui|

This module is part of the `OCA/rma <https://github.com/OCA/rma/tree/18.0/rma_sale_stock_restocking_fee_invoicing>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions rma_sale_stock_restocking_fee_invoicing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions rma_sale_stock_restocking_fee_invoicing/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2025 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Rma Sale Stock Restocking Fee Invoicing",
"summary": """Extends the RMA flow to automatically apply fixed or percentage
restocking fees.""",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"maintainers": ["sbejaoui"],
"website": "https://github.com/OCA/rma",
"depends": [
"sale_stock_restocking_fee_invoicing",
"rma_sale",
"stock_move_propagate_first_move",
],
"data": ["views/rma_operation.xml", "views/rma.xml"],
"demo": [],
}
5 changes: 5 additions & 0 deletions rma_sale_stock_restocking_fee_invoicing/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import restocking_fee_mixin
from . import rma_operation
from . import rma
from . import sale_order
from . import stock_move
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2025 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class RestockingFeeMixin(models.AbstractModel):
_name = "restocking.fee.mixin"
_description = "Restocking Fee Mixin"

restocking_fee_type = fields.Selection(
[
("fixed", "Fixed Amount"),
("percent", "Percentage"),
],
help="Define whether the restocking fee is a fixed amount or a percentage.",
)

restocking_fee_amount = fields.Float()

@api.constrains("restocking_fee_type", "restocking_fee_amount")
def _check_restocking_fee_amount(self):
for rec in self:
if not rec.restocking_fee_type:
continue
if rec.restocking_fee_amount <= 0:
raise ValidationError(
_("Restocking fee amount must be greater than zero.")
)
if rec.restocking_fee_type == "percent":
if rec.restocking_fee_amount > 100:
raise ValidationError(
_("Restocking fee percentage cannot exceed 100%.")
)
163 changes: 163 additions & 0 deletions rma_sale_stock_restocking_fee_invoicing/models/rma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Copyright 2025 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import Command, _, api, fields, models
from odoo.exceptions import ValidationError


class Rma(models.Model):
_name = "rma"
_inherit = ["rma", "restocking.fee.mixin"]

restocking_fee_invoice_id = fields.Many2one(
comodel_name="account.move", readonly=True
)
manual_restocking_fee_invoice_needed = fields.Boolean(
compute="_compute_manual_restocking_fee_invoice_needed"
)
restocking_fee_type = fields.Selection(
compute="_compute_restocking_fee", store=True, readonly=False
)
restocking_fee_amount = fields.Float(
compute="_compute_restocking_fee", store=True, readonly=False
)
restocking_fee_visibility = fields.Boolean(
compute="_compute_restocking_fee_visibility"
)

@api.depends("operation_id")
def _compute_restocking_fee(self):
for rec in self:
rec.update(
{
"restocking_fee_type": rec.operation_id.restocking_fee_type,
"restocking_fee_amount": rec.operation_id.restocking_fee_amount,
}
)

@api.depends("operation_id")
def _compute_restocking_fee_visibility(self):
for rec in self:
rec.restocking_fee_visibility = bool(rec.action_create_receipt)

@api.depends(
"operation_id.action_create_receipt",
"operation_id.action_create_refund",
"restocking_fee_type",
"restocking_fee_invoice_id",
)
def _compute_manual_restocking_fee_invoice_needed(self):
for rec in self:
rec.manual_restocking_fee_invoice_needed = (
not rec.restocking_fee_invoice_id
and rec.operation_id.action_create_receipt
and rec.operation_id.action_create_refund != "update_quantity"
and rec.restocking_fee_type
)

def _prepare_reception_procurement_vals(self, group=None):
vals = super()._prepare_reception_procurement_vals(group=group)
vals["charge_restocking_fee"] = bool(self.restocking_fee_type)
return vals

def _create_restocking_fee_invoice(self):
for rec in self:
if not rec.manual_restocking_fee_invoice_needed:
continue
rec.restocking_fee_invoice_id = self.env["account.move"].create(
rec._prepare_restocking_fee_invoice_vals()
)

def _prepare_restocking_fee_invoice_vals(self):
self.ensure_one()
return {
"move_type": "out_invoice",
"company_id": self.company_id.id,
"partner_id": self.partner_invoice_id.id,
"invoice_line_ids": [
Command.create(self._prepare_restocking_fee_invoice_line_vals())
],
}

def _get_restocking_fee_invoice_line_name(self):
lang = self.partner_id.lang
return _(
"Restocking fee for %(prod_uom_qty)s %(prod_uom)s. RMA %(rma)s",
prod_uom_qty=self.product_uom_qty,
prod_uom=self.product_uom.with_context(lang=lang).name,
rma=self.name,
)

def _prepare_restocking_fee_invoice_line_vals(self):
self.ensure_one()
product_id = self.company_id.restocking_fee_product_id
if not product_id:
raise ValidationError(
_(
"No product configured for restocking fee. "
"Please fix the configuration into stock settings or "
"contact you administrator."
)
)
name = self.with_context(
lang=self.partner_id.lang
)._get_restocking_fee_invoice_line_name()
return {
"name": name,
"quantity": 1,
"product_uom_id": product_id.uom_id.id,
"product_id": product_id.id,
"price_unit": self._get_restocking_fee_amount(),
}

def action_view_restocking_fee_invoice(self):
self.ensure_one()
return {
"name": self.env._("Invoice"),
"type": "ir.actions.act_window",
"view_type": "form",
"view_mode": "form",
"res_model": "account.move",
"views": [(self.env.ref("account.view_move_form").id, "form")],
"res_id": self.restocking_fee_invoice_id.id,
}

def _get_restocking_fee_amount(self):
self.ensure_one()
if not self.restocking_fee_type:
return 0
if self.restocking_fee_type == "fixed":
return self.restocking_fee_amount
if self.sale_line_id:
price_unit = self.sale_line_id.price_unit
price_unit = self.sale_line_id.product_uom._compute_price(
price_unit, self.product_uom
)
else:
price_unit = self.product_id.lst_price
return (price_unit * (self.restocking_fee_amount / 100)) * self.product_uom_qty

def _get_related_moves(self):
"""
Get all chained moves from the reception move
"""
res_moves = self.mapped("reception_move_id")
done_moves = self.env["stock.move"]
moves_to_parse = res_moves
while moves_to_parse:
next_moves = moves_to_parse.mapped("move_dest_ids")
res_moves |= next_moves
done_moves |= moves_to_parse
moves_to_parse = next_moves - done_moves
return res_moves

def write(self, vals):
"""
Be able to propagate restocking fees on all moves of the chain
even if added once the reception move is already created.
"""
res = super().write(vals)
if "restocking_fee_type" in vals:
moves = self._get_related_moves()
moves.charge_restocking_fee = bool(vals["restocking_fee_type"])
return res
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2025 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class RmaOperation(models.Model):
_name = "rma.operation"
_inherit = ["rma.operation", "restocking.fee.mixin"]
Loading
Loading