mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[14.0][FIX] Added a better ux to select or write reason of refund
This commit is contained in:
@@ -146,10 +146,17 @@ class RmaRefund(models.TransientModel):
|
|||||||
journal = self.env["account.journal"].search(
|
journal = self.env["account.journal"].search(
|
||||||
[("type", "=", "purchase")], limit=1
|
[("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 = {
|
values = {
|
||||||
"payment_reference": rma_line.rma_id.name or rma_line.name,
|
"payment_reference": rma_number_ref,
|
||||||
"invoice_origin": rma_line.rma_id.name or rma_line.name,
|
"invoice_origin": rma_number_ref,
|
||||||
"ref": False,
|
"ref": ref,
|
||||||
"move_type": "in_refund" if rma_line.type == "supplier" else "out_refund",
|
"move_type": "in_refund" if rma_line.type == "supplier" else "out_refund",
|
||||||
"journal_id": journal.id,
|
"journal_id": journal.id,
|
||||||
"fiscal_position_id": rma_line.partner_id.property_account_position_id.id,
|
"fiscal_position_id": rma_line.partner_id.property_account_position_id.id,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
"data": [
|
"data": [
|
||||||
"views/rma_operation_view.xml",
|
"views/rma_operation_view.xml",
|
||||||
"views/rma_order_line_view.xml",
|
"views/rma_order_line_view.xml",
|
||||||
|
"wizard/rma_refund_view.xml",
|
||||||
],
|
],
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"auto_install": True,
|
"auto_install": True,
|
||||||
|
|||||||
@@ -1,20 +1,39 @@
|
|||||||
# Copyright (C) 2023 ForgeFlow S.L.
|
# Copyright (C) 2023 ForgeFlow S.L.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# 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):
|
class RmaRefund(models.TransientModel):
|
||||||
|
|
||||||
_inherit = "rma.refund"
|
_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
|
@api.model
|
||||||
def _prepare_refund(self, wizard, rma_line):
|
def _prepare_refund(self, wizard, rma_line):
|
||||||
values = super(RmaRefund, self)._prepare_refund(wizard, rma_line)
|
values = super(RmaRefund, self)._prepare_refund(wizard, rma_line)
|
||||||
if rma_line.refund_reason_id:
|
if rma_line.refund_reason_id:
|
||||||
values.update(
|
values.update(
|
||||||
{
|
{
|
||||||
"reason_id": rma_line.refund_reason_id.id,
|
"reason_id": wizard.refund_reason_id.id,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return values
|
return values
|
||||||
|
|||||||
22
rma_refund_reason/wizard/rma_refund_view.xml
Normal file
22
rma_refund_reason/wizard/rma_refund_view.xml
Normal 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>
|
||||||
Reference in New Issue
Block a user