diff --git a/rma_batch_reason/README.rst b/rma_batch_reason/README.rst new file mode 100644 index 000000000..76eb98e62 --- /dev/null +++ b/rma_batch_reason/README.rst @@ -0,0 +1,96 @@ +================ +RMA Batch Reason +================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:0540653949a33aac87c23b7a236532945f44b0ab922584d6192a87ef331c380e + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_batch_reason + :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_batch_reason + :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| + +Managing return reasons at the batch level. + +This addon extends the RMA Batch functionality by introducing a reason +field that can be set at the batch level. When a reason is assigned: + +- All RMAs within that batch automatically inherit the batch's reason +- Individual RMAs can override the batch reason if needed + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module: + +1. Go to RMA > RMA Batches +2. Create or open an RMA Batch +3. In the form, locate the "Reason" field (added after the Operation + field) +4. Select a reason from the dropdown +5. The reason will automatically be applied to all RMAs +6. Individual RMAs can override the batch reason by setting their own + reason + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ACSONE SA/NV + +Contributors +------------ + +- Stéphane Mangin - ACSONE SA/NV stephane.mangin@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. + +This module is part of the `OCA/rma `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/rma_batch_reason/__init__.py b/rma_batch_reason/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/rma_batch_reason/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/rma_batch_reason/__manifest__.py b/rma_batch_reason/__manifest__.py new file mode 100644 index 000000000..1903f4ed4 --- /dev/null +++ b/rma_batch_reason/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "RMA Batch Reason", + "summary": """Add reason field to RMA batches and propagate to RMAs""", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "website": "https://github.com/OCA/rma", + "author": "ACSONE SA/NV, Odoo Community Association (OCA)", + "depends": [ + "rma_batch", + "rma_reason", + ], + "data": [ + "views/rma_batch.xml", + ], + "installable": True, +} diff --git a/rma_batch_reason/models/__init__.py b/rma_batch_reason/models/__init__.py new file mode 100644 index 000000000..45ea6224e --- /dev/null +++ b/rma_batch_reason/models/__init__.py @@ -0,0 +1,2 @@ +from . import rma_batch +from . import rma diff --git a/rma_batch_reason/models/rma.py b/rma_batch_reason/models/rma.py new file mode 100644 index 000000000..f3e7454fa --- /dev/null +++ b/rma_batch_reason/models/rma.py @@ -0,0 +1,17 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class Rma(models.Model): + _inherit = "rma" + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if vals.get("batch_id") and not vals.get("reason_id"): + batch = self.env["rma.batch"].browse(vals["batch_id"]) + if batch.reason_id: + vals["reason_id"] = batch.reason_id.id + return super().create(vals_list) diff --git a/rma_batch_reason/models/rma_batch.py b/rma_batch_reason/models/rma_batch.py new file mode 100644 index 000000000..52514dee1 --- /dev/null +++ b/rma_batch_reason/models/rma_batch.py @@ -0,0 +1,24 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class RmaBatch(models.Model): + _inherit = "rma.batch" + + reason_id = fields.Many2one( + "rma.reason", + string="Reason", + help="Reason for the return, applied to all RMAs in the batch.", + ) + + @api.onchange("reason_id") + def _onchange_reason_id(self): + for rec in self: + if rec.state != "draft": + continue + if rec.reason_id: + rec.rma_ids.filtered( + lambda r: not r.reason_id + ).reason_id = rec.reason_id diff --git a/rma_batch_reason/pyproject.toml b/rma_batch_reason/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/rma_batch_reason/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/rma_batch_reason/readme/CONTRIBUTORS.md b/rma_batch_reason/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..4b716c746 --- /dev/null +++ b/rma_batch_reason/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Stéphane Mangin - ACSONE SA/NV + diff --git a/rma_batch_reason/readme/DESCRIPTION.md b/rma_batch_reason/readme/DESCRIPTION.md new file mode 100644 index 000000000..fa829b190 --- /dev/null +++ b/rma_batch_reason/readme/DESCRIPTION.md @@ -0,0 +1,8 @@ +Managing return reasons at the batch level. + +This addon extends the RMA Batch functionality by introducing a reason field that +can be set at the batch level. When a reason is assigned: + +- All RMAs within that batch automatically inherit the batch's reason +- Individual RMAs can override the batch reason if needed + diff --git a/rma_batch_reason/readme/USAGE.md b/rma_batch_reason/readme/USAGE.md new file mode 100644 index 000000000..1edc01671 --- /dev/null +++ b/rma_batch_reason/readme/USAGE.md @@ -0,0 +1,9 @@ +To use this module: + +1. Go to RMA > RMA Batches +2. Create or open an RMA Batch +3. In the form, locate the "Reason" field (added after the Operation field) +4. Select a reason from the dropdown +5. The reason will automatically be applied to all RMAs +7. Individual RMAs can override the batch reason by setting their own reason + diff --git a/rma_batch_reason/static/description/index.html b/rma_batch_reason/static/description/index.html new file mode 100644 index 000000000..ebfa93b12 --- /dev/null +++ b/rma_batch_reason/static/description/index.html @@ -0,0 +1,444 @@ + + + + + +RMA Batch Reason + + + +
+

RMA Batch Reason

+ + +

Beta License: AGPL-3 OCA/rma Translate me on Weblate Try me on Runboat

+

Managing return reasons at the batch level.

+

This addon extends the RMA Batch functionality by introducing a reason +field that can be set at the batch level. When a reason is assigned:

+
    +
  • All RMAs within that batch automatically inherit the batch’s reason
  • +
  • Individual RMAs can override the batch reason if needed
  • +
+

Table of contents

+ +
+

Usage

+

To use this module:

+
    +
  1. Go to RMA > RMA Batches
  2. +
  3. Create or open an RMA Batch
  4. +
  5. In the form, locate the “Reason” field (added after the Operation +field)
  6. +
  7. Select a reason from the dropdown
  8. +
  9. The reason will automatically be applied to all RMAs
  10. +
  11. Individual RMAs can override the batch reason by setting their own +reason
  12. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

This module is part of the OCA/rma project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/rma_batch_reason/tests/__init__.py b/rma_batch_reason/tests/__init__.py new file mode 100644 index 000000000..f658adb5e --- /dev/null +++ b/rma_batch_reason/tests/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import common +from . import test_rma_batch_reason diff --git a/rma_batch_reason/tests/common.py b/rma_batch_reason/tests/common.py new file mode 100644 index 000000000..da3420c56 --- /dev/null +++ b/rma_batch_reason/tests/common.py @@ -0,0 +1,72 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import TransactionCase + + +class TestRmaBatchReasonCommon(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.reason = cls.env["rma.reason"].create( + { + "name": {"en_US": "Test Reason"}, + } + ) + cls.other_reason = cls.env["rma.reason"].create( + { + "name": {"en_US": "Other Reason"}, + } + ) + cls.partner = cls.env["res.partner"].create( + { + "name": "Test Partner", + } + ) + cls.product = cls.env["product.product"].create( + { + "name": "Test Product", + } + ) + cls.warehouse = cls.env["stock.warehouse"].search([], limit=1) + cls.location = cls.warehouse.lot_stock_id + cls.operation = cls.env["rma.operation"].create( + { + "name": "Test RMA Operation", + } + ) + + def _create_batch(self, reason=None): + """Helper to create a batch with optional reason.""" + vals = { + "partner_id": self.partner.id, + "partner_shipping_id": self.partner.id, + "partner_invoice_id": self.partner.id, + "company_id": self.env.company.id, + "location_id": self.location.id, + "operation_id": self.operation.id, + } + if reason: + vals["reason_id"] = reason.id + return self.env["rma.batch"].create(vals) + + def _create_rma(self, batch=None, reason=None, operation=None): + """Helper to create an RMA with optional batch and reason. + + If operation or reason is given it will override the one from batch if any.""" + vals = { + "partner_id": self.partner.id, + "product_id": self.product.id, + "product_uom_qty": 1.0, + } + if batch: + vals["batch_id"] = batch.id + if batch.operation_id: + vals["operation_id"] = batch.operation_id.id + if batch.reason_id: + vals["reason_id"] = batch.reason_id.id + if operation: + vals["operation_id"] = operation.id + if reason: + vals["reason_id"] = reason.id + return self.env["rma"].create(vals) diff --git a/rma_batch_reason/tests/test_rma_batch_reason.py b/rma_batch_reason/tests/test_rma_batch_reason.py new file mode 100644 index 000000000..85a514d6f --- /dev/null +++ b/rma_batch_reason/tests/test_rma_batch_reason.py @@ -0,0 +1,70 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import Form, tagged + +from .common import TestRmaBatchReasonCommon + + +@tagged("-at_install", "post_install") +class TestRmaBatchReason(TestRmaBatchReasonCommon): + def test_rma_creation_with_batch_reason(self): + batch = self._create_batch(reason=self.reason) + rma = self._create_rma(batch=batch) + self.assertEqual(rma.reason_id, self.reason) + + def test_batch_reason_onchange_propagates_to_draft_rmas(self): + batch = self._create_batch() + rma_with_reason = self._create_rma(batch=batch, reason=self.reason) + rma_without_reason = self._create_rma(batch=batch, reason=None) + with Form(batch) as batch_form: + batch_form.reason_id = self.other_reason + batch_form.save() + self.assertEqual(rma_with_reason.reason_id, self.reason) + self.assertEqual(rma_without_reason.reason_id, self.other_reason) + + def test_batch_reason_onchange_does_not_affect_non_draft(self): + batch = self._create_batch() + rma_draft = self._create_rma(batch=batch) + rma_canceled = self._create_rma(batch=batch, reason=self.reason) + rma_canceled.action_cancel() + with Form(batch) as batch_form: + batch_form.reason_id = self.other_reason + batch_form.save() + self.assertEqual(rma_draft.reason_id, self.other_reason) + self.assertEqual(rma_canceled.reason_id, self.reason) + + def test_batch_reason_onchange_all_rmas_already_set(self): + batch = self._create_batch() + rma1 = self._create_rma(batch=batch, reason=self.reason) + rma2 = self._create_rma(batch=batch, reason=self.other_reason) + with Form(batch) as batch_form: + batch_form.reason_id = self.env["rma.reason"].create({"name": "New Reason"}) + batch_form.save() + self.assertEqual(rma1.reason_id, self.reason) + self.assertEqual(rma2.reason_id, self.other_reason) + + def test_batch_reason_onchange_no_rmas(self): + batch = self._create_batch() + with Form(batch) as batch_form: + batch_form.reason_id = self.reason + batch_form.save() + self.assertEqual(batch.reason_id, self.reason) + + def test_batch_reason_onchange_propagates_to_new_rma_after_batch_reason_set(self): + batch = self._create_batch() + with Form(batch) as batch_form: + batch_form.reason_id = self.reason + batch_form.save() + rma = self._create_rma(batch=batch) + self.assertEqual(rma.reason_id, self.reason) + + def test_batch_reason_onchange_on_cancelled_batch(self): + """reason_id is readonly on cancelled batches but onchange should not fail + if reason_id is changed programmatically.""" + batch = self._create_batch(reason=self.reason) + rma = self._create_rma(batch=batch) + batch.action_cancel() + batch.reason_id = self.other_reason + batch._onchange_reason_id() + self.assertEqual(rma.reason_id, self.reason) diff --git a/rma_batch_reason/views/rma_batch.xml b/rma_batch_reason/views/rma_batch.xml new file mode 100644 index 000000000..f70e17973 --- /dev/null +++ b/rma_batch_reason/views/rma_batch.xml @@ -0,0 +1,19 @@ + + + + rma.batch.form.inherit.reason + rma.batch + + + + + + + + + + +