mirror of
https://github.com/OCA/rma.git
synced 2025-02-16 17:11:47 +02:00
[IMP] rma: finish RMA manually
Sometimes there's no choice to return, refund or replace an RMA for different reasons. For example, when the customer doesn't want to repair the product because that would be too expensive. We still want finish the RMA and document the reasons. This improvement allows it. TT34164
This commit is contained in:
committed by
Nikolaus Weingartmair
parent
913da6319b
commit
5e9904b93c
@@ -2,6 +2,7 @@
|
||||
|
||||
from . import account_move
|
||||
from . import rma
|
||||
from . import rma_finalization
|
||||
from . import rma_operation
|
||||
from . import rma_tag
|
||||
from . import rma_team
|
||||
|
||||
@@ -6,6 +6,11 @@ from odoo import fields, models
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = "res.config.settings"
|
||||
|
||||
group_rma_manual_finalization = fields.Boolean(
|
||||
string="Finish RMA manually choosing a reason",
|
||||
help="Allow to finish an RMA without returning back a product or refunding",
|
||||
implied_group="rma.group_rma_manual_finalization",
|
||||
)
|
||||
send_rma_confirmation = fields.Boolean(
|
||||
related="company_id.send_rma_confirmation",
|
||||
readonly=False,
|
||||
|
||||
@@ -67,6 +67,14 @@ class Rma(models.Model):
|
||||
states={"locked": [("readonly", True)], "cancelled": [("readonly", True)]},
|
||||
)
|
||||
tag_ids = fields.Many2many(comodel_name="rma.tag", string="Tags")
|
||||
finalization_id = fields.Many2one(
|
||||
string="Finalization Reason",
|
||||
comodel_name="rma.finalization",
|
||||
copy=False,
|
||||
readonly=True,
|
||||
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
|
||||
tracking=True,
|
||||
)
|
||||
company_id = fields.Many2one(
|
||||
comodel_name="res.company",
|
||||
default=lambda self: self.env.company,
|
||||
@@ -171,6 +179,7 @@ class Rma(models.Model):
|
||||
("refunded", "Refunded"),
|
||||
("returned", "Returned"),
|
||||
("replaced", "Replaced"),
|
||||
("finished", "Finished"),
|
||||
("locked", "Locked"),
|
||||
("cancelled", "Canceled"),
|
||||
],
|
||||
@@ -245,6 +254,9 @@ class Rma(models.Model):
|
||||
can_be_locked = fields.Boolean(
|
||||
compute="_compute_can_be_locked",
|
||||
)
|
||||
can_be_finished = fields.Boolean(
|
||||
compute="_compute_can_be_finished",
|
||||
)
|
||||
remaining_qty = fields.Float(
|
||||
string="Remaining delivered qty",
|
||||
digits="Product Unit of Measure",
|
||||
@@ -388,6 +400,14 @@ class Rma(models.Model):
|
||||
"replaced",
|
||||
]
|
||||
|
||||
@api.depends("state", "remaining_qty")
|
||||
def _compute_can_be_finished(self):
|
||||
for rma in self:
|
||||
rma.can_be_finished = (
|
||||
rma.state in {"received", "waiting_replacement", "waiting_return"}
|
||||
and rma.remaining_qty > 0
|
||||
)
|
||||
|
||||
@api.depends("product_uom_qty", "state", "remaining_qty", "remaining_qty_to_done")
|
||||
def _compute_can_be_split(self):
|
||||
"""Compute 'can_be_split'. This field controls the
|
||||
@@ -718,6 +738,21 @@ class Rma(models.Model):
|
||||
action["context"].update(active_id=self.id, active_ids=self.ids)
|
||||
return action
|
||||
|
||||
def action_finish(self):
|
||||
"""Invoked when a user wants to manually finalize the RMA"""
|
||||
self.ensure_one()
|
||||
self._ensure_can_be_returned()
|
||||
# Force active_id to avoid issues when coming from smart buttons
|
||||
# in other models
|
||||
action = (
|
||||
self.env.ref("rma.rma_finalization_wizard_action")
|
||||
.with_context(active_id=self.id)
|
||||
.read()[0]
|
||||
)
|
||||
action["context"] = dict(self.env.context)
|
||||
action["context"].update(active_id=self.id, active_ids=self.ids)
|
||||
return action
|
||||
|
||||
def action_cancel(self):
|
||||
"""Invoked when 'Cancel' button in rma form view is clicked."""
|
||||
self.mapped("reception_move_id")._action_cancel()
|
||||
|
||||
26
rma/models/rma_finalization.py
Normal file
26
rma/models/rma_finalization.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Copyright 2022 Tecnativa - David Vidal
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class RmaFinalization(models.Model):
|
||||
_description = "RMA Finalization Reason"
|
||||
_name = "rma.finalization"
|
||||
_order = "name"
|
||||
|
||||
active = fields.Boolean(default=True)
|
||||
name = fields.Char(
|
||||
string="Reason Name",
|
||||
required=True,
|
||||
translate=True,
|
||||
copy=False,
|
||||
)
|
||||
company_id = fields.Many2one(comodel_name="res.company")
|
||||
|
||||
_sql_constraints = [
|
||||
(
|
||||
"name_company_uniq",
|
||||
"unique (name, company_id)",
|
||||
"Finalization name already exists !",
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user