Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions rma_account/wizards/rma_refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions rma_refund_reason/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 21 additions & 2 deletions rma_refund_reason/wizard/rma_refund.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions rma_refund_reason/wizard/rma_refund_view.xml
Original file line number Diff line number Diff line change
@@ -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>
Loading