diff --git a/rma_refund_reason/README.rst b/rma_refund_reason/README.rst new file mode 100644 index 000000000..b7b2f043e --- /dev/null +++ b/rma_refund_reason/README.rst @@ -0,0 +1,62 @@ +============================= +RMA Refund Reason Integration +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:2e403ef31b1be93acf0bed913183ea60c20dc9f6279eee6ae5fab018049bfb44 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-ForgeFlow%2Fstock--rma-lightgray.png?logo=github + :target: https://github.com/ForgeFlow/stock-rma/tree/18.0/rma_refund_reason + :alt: ForgeFlow/stock-rma + +|badge1| |badge2| |badge3| + +Add refund reason on rma refund creation process + +The default return reason can be configured in the RMA operations + +**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 +------- + +* ForgeFlow + +Contributors +------------ + +- Christopher Ormaza + +Maintainers +----------- + +This module is part of the `ForgeFlow/stock-rma `_ project on GitHub. + +You are welcome to contribute. diff --git a/rma_refund_reason/__init__.py b/rma_refund_reason/__init__.py new file mode 100644 index 000000000..9b4296142 --- /dev/null +++ b/rma_refund_reason/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/rma_refund_reason/__manifest__.py b/rma_refund_reason/__manifest__.py new file mode 100644 index 000000000..14cf34259 --- /dev/null +++ b/rma_refund_reason/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright (C) 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "RMA Refund Reason Integration", + "version": "18.0.1.0.0", + "summary": "RMA Refund Reason Integration", + "category": "RMA", + "author": "ForgeFlow", + "website": "https://github.com/ForgeFlow", + "license": "AGPL-3", + "depends": ["rma_account", "account_invoice_refund_reason"], + "data": [ + "views/rma_operation_view.xml", + "views/rma_order_line_view.xml", + "wizard/rma_refund_view.xml", + ], + "installable": True, + "auto_install": True, +} diff --git a/rma_refund_reason/models/__init__.py b/rma_refund_reason/models/__init__.py new file mode 100644 index 000000000..c82dd91e6 --- /dev/null +++ b/rma_refund_reason/models/__init__.py @@ -0,0 +1,2 @@ +from . import rma_operation +from . import rma_order_line diff --git a/rma_refund_reason/models/rma_operation.py b/rma_refund_reason/models/rma_operation.py new file mode 100644 index 000000000..d8e4d8f0c --- /dev/null +++ b/rma_refund_reason/models/rma_operation.py @@ -0,0 +1,13 @@ +# Copyright (C) 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class RmaOperation(models.Model): + _inherit = "rma.operation" + + refund_reason_id = fields.Many2one( + comodel_name="account.move.refund.reason", + string="Refund reason", + ) diff --git a/rma_refund_reason/models/rma_order_line.py b/rma_refund_reason/models/rma_order_line.py new file mode 100644 index 000000000..8afa7bd82 --- /dev/null +++ b/rma_refund_reason/models/rma_order_line.py @@ -0,0 +1,20 @@ +# Copyright (C) 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class RmaOrderLine(models.Model): + _inherit = "rma.order.line" + + refund_reason_id = fields.Many2one( + comodel_name="account.move.refund.reason", + string="Refund reason", + ) + + @api.onchange("operation_id") + def _onchange_operation_id(self): + result = super()._onchange_operation_id() + if self.operation_id: + self.refund_reason_id = self.operation_id.refund_reason_id.id + return result diff --git a/rma_refund_reason/pyproject.toml b/rma_refund_reason/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/rma_refund_reason/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/rma_refund_reason/readme/CONTRIBUTORS.md b/rma_refund_reason/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..9b6d3655b --- /dev/null +++ b/rma_refund_reason/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Christopher Ormaza \<\> diff --git a/rma_refund_reason/readme/DESCRIPTION.md b/rma_refund_reason/readme/DESCRIPTION.md new file mode 100644 index 000000000..2adaa1f46 --- /dev/null +++ b/rma_refund_reason/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +Add refund reason on rma refund creation process + +The default return reason can be configured in the RMA operations diff --git a/rma_refund_reason/static/description/index.html b/rma_refund_reason/static/description/index.html new file mode 100644 index 000000000..6070cc6a7 --- /dev/null +++ b/rma_refund_reason/static/description/index.html @@ -0,0 +1,417 @@ + + + + + +RMA Refund Reason Integration + + + +
+

RMA Refund Reason Integration

+ + +

Beta License: AGPL-3 ForgeFlow/stock-rma

+

Add refund reason on rma refund creation process

+

The default return reason can be configured in the RMA operations

+

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

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is part of the ForgeFlow/stock-rma project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/rma_refund_reason/tests/__init__.py b/rma_refund_reason/tests/__init__.py new file mode 100644 index 000000000..94cc012e7 --- /dev/null +++ b/rma_refund_reason/tests/__init__.py @@ -0,0 +1 @@ +from . import test_rma_refund_reason diff --git a/rma_refund_reason/tests/test_rma_refund_reason.py b/rma_refund_reason/tests/test_rma_refund_reason.py new file mode 100644 index 000000000..f4b1592a1 --- /dev/null +++ b/rma_refund_reason/tests/test_rma_refund_reason.py @@ -0,0 +1,74 @@ +# Copyright (C) 2025 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo.addons.rma_account.tests.test_account_move_line_rma_order_line import ( + TestAccountMoveLineRmaOrderLine, +) + + +class TestRmaStockAccountSale(TestAccountMoveLineRmaOrderLine): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.operation_receive_refund = cls.env.ref( + "rma_account.rma_operation_customer_refund" + ) + cls.product_test_refund = cls.env["product.product"].create( + {"name": "Test Refund"} + ) + cls.refund_reason = cls.env["account.move.refund.reason"].create( + {"name": "Rma Refund"} + ) + + def test_rma_refund_reason(self): + products2move = [ + (self.product_test_refund, 1), + ] + rma = self._create_rma(products2move, self.partner1) + rma_line = rma.rma_line_ids + rma_line.operation_id = self.operation_receive_refund + rma_line.refund_reason_id = self.refund_reason + for rma in rma_line: + if rma.price_unit == 0: + rma.price_unit = 100.0 + rma_line.action_rma_approve() + wizard = self.rma_make_picking.with_context( + **{ + "active_id": 1, + "active_ids": rma_line.ids, + "active_model": "rma.order.line", + "picking_type": "incoming", + } + ).create({}) + operation = self.env["rma.operation"].search( + [("type", "=", "customer"), ("refund_policy", "=", "received")], limit=1 + ) + rma_line.write({"operation_id": operation.id}) + rma_line.write({"refund_policy": "received"}) + + wizard._create_picking() + res = rma_line.action_view_in_shipments() + if "res_id" in res: + picking = self.env["stock.picking"].browse(res["res_id"]) + else: + picking_ids = self.env["stock.picking"].search(res["domain"]) + picking = self.env["stock.picking"].browse(picking_ids) + picking.button_validate() + make_refund = self.rma_refund_wiz.with_context( + **{ + "customer": True, + "active_ids": rma_line.ids, + "active_model": "rma.order.line", + } + ).create({}) + self.assertEqual(make_refund.refund_reason_id, self.refund_reason) + for item in make_refund.item_ids: + item.write( + { + "qty_to_refund": 1.0, + } + ) + make_refund.invoice_refund() + refund_invoice = rma_line.mapped("refund_line_ids.move_id") + self.assertEqual(refund_invoice.reason_id, self.refund_reason) diff --git a/rma_refund_reason/views/rma_operation_view.xml b/rma_refund_reason/views/rma_operation_view.xml new file mode 100644 index 000000000..5d5f41376 --- /dev/null +++ b/rma_refund_reason/views/rma_operation_view.xml @@ -0,0 +1,13 @@ + + + + rma.operation.form.view + rma.operation + + + + + + + + diff --git a/rma_refund_reason/views/rma_order_line_view.xml b/rma_refund_reason/views/rma_order_line_view.xml new file mode 100644 index 000000000..5be3f04bb --- /dev/null +++ b/rma_refund_reason/views/rma_order_line_view.xml @@ -0,0 +1,13 @@ + + + + rma.order.line.form.view + rma.order.line + + + + + + + + diff --git a/rma_refund_reason/wizard/__init__.py b/rma_refund_reason/wizard/__init__.py new file mode 100644 index 000000000..72f20b3f9 --- /dev/null +++ b/rma_refund_reason/wizard/__init__.py @@ -0,0 +1 @@ +from . import rma_refund diff --git a/rma_refund_reason/wizard/rma_refund.py b/rma_refund_reason/wizard/rma_refund.py new file mode 100644 index 000000000..2d05ef165 --- /dev/null +++ b/rma_refund_reason/wizard/rma_refund.py @@ -0,0 +1,38 @@ +# Copyright (C) 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class RmaRefund(models.TransientModel): + _inherit = "rma.refund" + + @api.model + def _get_refund_reason(self): + active_ids = self.env.context.get("active_ids", False) + return ( + active_ids + and self.env["rma.order.line"].browse(active_ids[0]).refund_reason_id.id + or False + ) + + refund_reason_id = fields.Many2one( + comodel_name="account.move.refund.reason", + string="Refund Reason", + default=lambda self: self._get_refund_reason(), + ) + + @api.onchange("refund_reason_id") + def _onchange_refund_reason_id(self): + self.description = self.refund_reason_id.name + + @api.model + def _prepare_refund(self, wizard, rma_line): + values = super()._prepare_refund(wizard, rma_line) + if rma_line.refund_reason_id: + values.update( + { + "reason_id": wizard.refund_reason_id.id, + } + ) + return values diff --git a/rma_refund_reason/wizard/rma_refund_view.xml b/rma_refund_reason/wizard/rma_refund_view.xml new file mode 100644 index 000000000..75163fbb6 --- /dev/null +++ b/rma_refund_reason/wizard/rma_refund_view.xml @@ -0,0 +1,20 @@ + + + + + rma.refund.form.view + rma.refund + 99 + + + + + + + + +