diff --git a/rma_batch_sale_auto_detect/README.rst b/rma_batch_sale_auto_detect/README.rst new file mode 100644 index 000000000..5405b4123 --- /dev/null +++ b/rma_batch_sale_auto_detect/README.rst @@ -0,0 +1,84 @@ +========================== +Rma Batch Sale Auto Detect +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b39e6390c06d804b6d4e843a4949f6921d1f541ec02c505df8f2a788315a1ed9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_sale_auto_detect + :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_sale_auto_detect + :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 batch RMA process by adding automatic sale order +linking at batch level. It reuses the matching logic provided by the +module ``rma_sale_auto_detect``, but allows it to be executed on all +RMAs contained inside an ``rma.batch``. + +| A new batch state **Manual Treatment** is introduced. +| If at least one RMA in the batch fails to auto-match, the batch is + moved to this state, so the user can review and fix the unmatched RMAs + manually. + +**Table of contents** + +.. contents:: + :local: + +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 +------------ + +- Souheil Bejaoui souheil.bejaoui@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_sale_auto_detect/__init__.py b/rma_batch_sale_auto_detect/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/rma_batch_sale_auto_detect/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/rma_batch_sale_auto_detect/__manifest__.py b/rma_batch_sale_auto_detect/__manifest__.py new file mode 100644 index 000000000..34c216c84 --- /dev/null +++ b/rma_batch_sale_auto_detect/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Rma Batch Sale Auto Detect", + "summary": """This addon add an action to rma batch automatically detect rmas sale + order""", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/rma", + "depends": ["rma_batch", "rma_sale_auto_detect"], + "data": ["views/rma_batch.xml"], + "demo": [], +} diff --git a/rma_batch_sale_auto_detect/models/__init__.py b/rma_batch_sale_auto_detect/models/__init__.py new file mode 100644 index 000000000..45ea6224e --- /dev/null +++ b/rma_batch_sale_auto_detect/models/__init__.py @@ -0,0 +1,2 @@ +from . import rma_batch +from . import rma diff --git a/rma_batch_sale_auto_detect/models/rma.py b/rma_batch_sale_auto_detect/models/rma.py new file mode 100644 index 000000000..75af7d997 --- /dev/null +++ b/rma_batch_sale_auto_detect/models/rma.py @@ -0,0 +1,14 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class Rma(models.Model): + _inherit = "rma" + + def _onchange_order_id(self): + # allow user to select product then so in batch view + if not self.env.context.get("ignore_onchange_order_id", False): + return super()._onchange_order_id() + return {} diff --git a/rma_batch_sale_auto_detect/models/rma_batch.py b/rma_batch_sale_auto_detect/models/rma_batch.py new file mode 100644 index 000000000..e32008345 --- /dev/null +++ b/rma_batch_sale_auto_detect/models/rma_batch.py @@ -0,0 +1,32 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class RmaBatch(models.Model): + _inherit = "rma.batch" + + state = fields.Selection( + selection_add=[("manual", "Manual Treatment")], + help=( + "Represents the preparation and validation progress of the RMA batch:\n" + "- Draft: RMAs are being prepared\n" + "- Manual Treatment: One or more RMAs require manual matching\n" + "- Ready: All RMAs are completed and batch is ready to be confirmed\n" + "- Confirmed: The batch is validated and all RMAs are confirmed\n" + "- Cancelled: The batch is cancelled" + ), + ) + + def action_link_rma_to_sale_line(self): + self.rma_ids.action_link_rma_to_sale_line() + + def action_ready(self): + res = super().action_ready() + self.rma_ids.has_sale_auto_detect_issue = False + self.action_link_rma_to_sale_line() + for rec in self: + if any(rec.rma_ids.mapped("has_sale_auto_detect_issue")): + rec.state = "manual" + return res diff --git a/rma_batch_sale_auto_detect/pyproject.toml b/rma_batch_sale_auto_detect/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/rma_batch_sale_auto_detect/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/rma_batch_sale_auto_detect/readme/CONTRIBUTORS.md b/rma_batch_sale_auto_detect/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..dbdd727b4 --- /dev/null +++ b/rma_batch_sale_auto_detect/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Souheil Bejaoui diff --git a/rma_batch_sale_auto_detect/readme/DESCRIPTION.md b/rma_batch_sale_auto_detect/readme/DESCRIPTION.md new file mode 100644 index 000000000..e6ce4861c --- /dev/null +++ b/rma_batch_sale_auto_detect/readme/DESCRIPTION.md @@ -0,0 +1,8 @@ +This module extends the batch RMA process by adding automatic sale order +linking at batch level. It reuses the matching logic provided by the module +`rma_sale_auto_detect`, but allows it to be executed on all RMAs contained +inside an `rma.batch`. + +A new batch state **Manual Treatment** is introduced. +If at least one RMA in the batch fails to auto-match, the batch is moved to +this state, so the user can review and fix the unmatched RMAs manually. \ No newline at end of file diff --git a/rma_batch_sale_auto_detect/static/description/icon.png b/rma_batch_sale_auto_detect/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/rma_batch_sale_auto_detect/static/description/icon.png differ diff --git a/rma_batch_sale_auto_detect/static/description/index.html b/rma_batch_sale_auto_detect/static/description/index.html new file mode 100644 index 000000000..ad6e72cb1 --- /dev/null +++ b/rma_batch_sale_auto_detect/static/description/index.html @@ -0,0 +1,432 @@ + + + + + +Rma Batch Sale Auto Detect + + + +
+

Rma Batch Sale Auto Detect

+ + +

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

+

This module extends the batch RMA process by adding automatic sale order +linking at batch level. It reuses the matching logic provided by the +module rma_sale_auto_detect, but allows it to be executed on all +RMAs contained inside an rma.batch.

+
+
A new batch state Manual Treatment is introduced.
+
If at least one RMA in the batch fails to auto-match, the batch is +moved to this state, so the user can review and fix the unmatched RMAs +manually.
+
+

Table of contents

+ +
+

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_sale_auto_detect/tests/__init__.py b/rma_batch_sale_auto_detect/tests/__init__.py new file mode 100644 index 000000000..093e8514f --- /dev/null +++ b/rma_batch_sale_auto_detect/tests/__init__.py @@ -0,0 +1 @@ +from . import test_rma_batch_sale_auto_detect diff --git a/rma_batch_sale_auto_detect/tests/test_rma_batch_sale_auto_detect.py b/rma_batch_sale_auto_detect/tests/test_rma_batch_sale_auto_detect.py new file mode 100644 index 000000000..58ee0176c --- /dev/null +++ b/rma_batch_sale_auto_detect/tests/test_rma_batch_sale_auto_detect.py @@ -0,0 +1,54 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import tagged + +from odoo.addons.rma_sale_auto_detect.tests.common import TestRmaSaleAutoDetectBase + + +@tagged("-at_install", "post_install") +class TestRmaBatchSaleAutoDetect(TestRmaSaleAutoDetectBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.batch = cls.env["rma.batch"].create({"partner_id": cls.partner.id}) + + def _create_rma(self, partner, product, qty, operation): + rma = super()._create_rma(partner, product, qty, operation) + rma.batch_id = self.batch + return rma + + def test_0(self): + sale_order = self._create_and_confirm_sale_order( + self.partner, [(self.product, 5)], 30 + ) + self._process_picking(sale_order.picking_ids, self.product, 5) + rma = self._create_rma(self.partner, self.product, 5, self.operation) + sale_order2 = self._create_and_confirm_sale_order( + self.partner, [(self.product2, 5)], 60 + ) + self._process_picking(sale_order2.picking_ids, self.product2, 5) + rma2 = self._create_rma(self.partner, self.product2, 5, self.operation) + self.batch.action_ready() + self.assertEqual(self.batch.state, "manual") + self.assertTrue(rma.sale_line_id) + self.assertFalse(rma2.sale_line_id) + rma2.move_id = sale_order2.order_line.move_ids + self.batch.action_ready() + self.assertEqual(self.batch.state, "ready") + + def test_1(self): + sale_order = self._create_and_confirm_sale_order( + self.partner, [(self.product, 5)], 30 + ) + self._process_picking(sale_order.picking_ids, self.product, 5) + rma = self._create_rma(self.partner, self.product, 5, self.operation) + sale_order2 = self._create_and_confirm_sale_order( + self.partner, [(self.product2, 5)], 30 + ) + self._process_picking(sale_order2.picking_ids, self.product2, 5) + rma2 = self._create_rma(self.partner, self.product2, 5, self.operation) + self.batch.action_ready() + self.assertEqual(self.batch.state, "ready") + self.assertTrue(rma.sale_line_id) + self.assertTrue(rma2.sale_line_id) diff --git a/rma_batch_sale_auto_detect/views/rma_batch.xml b/rma_batch_sale_auto_detect/views/rma_batch.xml new file mode 100644 index 000000000..fb43a4a9a --- /dev/null +++ b/rma_batch_sale_auto_detect/views/rma_batch.xml @@ -0,0 +1,57 @@ + + + + + rma.batch + + + +