[14.0][FIX] Added a better ux to select or write reason of refund

This commit is contained in:
Christopher Ormaza
2023-09-19 07:31:21 -05:00
parent 2f76541806
commit 3ae7171da5
4 changed files with 54 additions and 5 deletions

View File

@@ -146,10 +146,17 @@ class RmaRefund(models.TransientModel):
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,

View File

@@ -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,

View File

@@ -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

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Inherit Form View to Modify it -->
<record id="view_rma_refund" model="ir.ui.view">
<field name="name">rma.refund.form.view</field>
<field name="model">rma.refund</field>
<field name="priority">99</field>
<field name="inherit_id" ref="rma_account.view_rma_refund" />
<field name="arch" type="xml">
<xpath expr="//field[@name='description']" position="replace">
<field name="description" invisible="1" />
<field
name="refund_reason_id"
options="{'no_create': True}"
required="1"
/>
</xpath>
</field>
</record>
</odoo>