diff --git a/rma_account/wizards/rma_refund.py b/rma_account/wizards/rma_refund.py index 909a833f4..66729a119 100644 --- a/rma_account/wizards/rma_refund.py +++ b/rma_account/wizards/rma_refund.py @@ -146,10 +146,17 @@ def _prepare_refund(self, wizard, rma_line): journal = self.env["account.journal"].search( [("type", "=", "purchase")], limit=1 ) + rma_number_ref = rma_line.rma_id.name or rma_line.name + reason = wizard.description + if reason == rma_number_ref: + reason = False + ref = _("Refund created by %s, %s") % (rma_number_ref, reason) + if not reason: + ref = _("Refund created by %s") % rma_number_ref values = { - "payment_reference": rma_line.rma_id.name or rma_line.name, - "invoice_origin": rma_line.rma_id.name or rma_line.name, - "ref": False, + "payment_reference": rma_number_ref, + "invoice_origin": rma_number_ref, + "ref": ref, "move_type": "in_refund" if rma_line.type == "supplier" else "out_refund", "journal_id": journal.id, "fiscal_position_id": rma_line.partner_id.property_account_position_id.id, diff --git a/rma_refund_reason/__manifest__.py b/rma_refund_reason/__manifest__.py index b9731f09e..ea9b04480 100644 --- a/rma_refund_reason/__manifest__.py +++ b/rma_refund_reason/__manifest__.py @@ -13,6 +13,7 @@ "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/wizard/rma_refund.py b/rma_refund_reason/wizard/rma_refund.py index 555283a60..11ecba046 100644 --- a/rma_refund_reason/wizard/rma_refund.py +++ b/rma_refund_reason/wizard/rma_refund.py @@ -1,20 +1,39 @@ # Copyright (C) 2023 ForgeFlow S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, models +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(RmaRefund, self)._prepare_refund(wizard, rma_line) if rma_line.refund_reason_id: values.update( { - "reason_id": rma_line.refund_reason_id.id, + "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..b9ea27c8a --- /dev/null +++ b/rma_refund_reason/wizard/rma_refund_view.xml @@ -0,0 +1,22 @@ + + + + + + rma.refund.form.view + rma.refund + 99 + + + + + + + + + +