mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[ADD] rma_reason_code
This commit is contained in:
committed by
Meritxell Abellan
parent
735847b8d1
commit
f90bfc59ef
4
rma_reason_code/models/__init__.py
Normal file
4
rma_reason_code/models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from . import reason_code
|
||||
from . import rma_order_line
|
||||
26
rma_reason_code/models/reason_code.py
Normal file
26
rma_reason_code/models/reason_code.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from random import randint
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class RMAReasonCode(models.Model):
|
||||
_name = "rma.reason.code"
|
||||
_description = "RMA Reason Code"
|
||||
|
||||
def _get_default_color(self):
|
||||
return randint(1, 11)
|
||||
|
||||
name = fields.Char("Code", required=True)
|
||||
description = fields.Text("Description")
|
||||
type = fields.Selection(
|
||||
[
|
||||
("customer", "Customer RMA"),
|
||||
("supplier", "Supplier RTV"),
|
||||
("both", "Both Customer and Supplier"),
|
||||
],
|
||||
default="both",
|
||||
required=True,
|
||||
)
|
||||
color = fields.Integer("Color", default=_get_default_color)
|
||||
44
rma_reason_code/models/rma_order_line.py
Normal file
44
rma_reason_code/models/rma_order_line.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class RMAOrderLine(models.Model):
|
||||
_inherit = "rma.order.line"
|
||||
|
||||
reason_code_ids = fields.Many2many(
|
||||
"rma.reason.code",
|
||||
"rma_order_line_reason_code_rel",
|
||||
string="Reason Code",
|
||||
domain="[('id', 'in', allowed_reason_code_ids)]",
|
||||
)
|
||||
allowed_reason_code_ids = fields.Many2many(
|
||||
comodel_name="rma.reason.code",
|
||||
compute="_compute_allowed_reason_code_ids",
|
||||
)
|
||||
|
||||
@api.depends("type")
|
||||
def _compute_allowed_reason_code_ids(self):
|
||||
for rec in self:
|
||||
codes = self.env["rma.reason.code"]
|
||||
if rec.type == "customer":
|
||||
codes = codes.search([("type", "in", ["customer", "both"])])
|
||||
else:
|
||||
codes = codes.search([("type", "in", ["supplier", "both"])])
|
||||
rec.allowed_reason_code_ids = codes
|
||||
|
||||
@api.constrains("reason_code_ids", "product_id")
|
||||
def _check_reason_code_ids(self):
|
||||
for rec in self:
|
||||
if rec.reason_code_ids and not any(
|
||||
rc in rec.allowed_reason_code_ids for rc in rec.reason_code_ids
|
||||
):
|
||||
raise ValidationError(
|
||||
_(
|
||||
"Any of the reason code selected is not allowed for "
|
||||
"this type of RMA (%s)."
|
||||
)
|
||||
% rec.type
|
||||
)
|
||||
Reference in New Issue
Block a user