2021-03-23 19:15:27 +00:00
|
|
|
# Copyright 2017 ForgeFlow S.L. (https://www.forgeflow.com)
|
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
|
|
|
|
|
|
|
from flectra import _, api, fields, models
|
|
|
|
|
|
|
|
|
|
|
|
class TierDefinition(models.Model):
|
|
|
|
_name = "tier.definition"
|
|
|
|
_description = "Tier Definition"
|
|
|
|
|
|
|
|
@api.model
|
|
|
|
def _get_default_name(self):
|
|
|
|
return _("New Tier Validation")
|
|
|
|
|
|
|
|
@api.model
|
|
|
|
def _get_tier_validation_model_names(self):
|
|
|
|
res = []
|
|
|
|
return res
|
|
|
|
|
|
|
|
name = fields.Char(
|
|
|
|
string="Description",
|
|
|
|
required=True,
|
|
|
|
default=lambda self: self._get_default_name(),
|
|
|
|
translate=True,
|
|
|
|
)
|
|
|
|
model_id = fields.Many2one(
|
|
|
|
comodel_name="ir.model",
|
|
|
|
string="Referenced Model",
|
|
|
|
domain=lambda self: [("model", "in", self._get_tier_validation_model_names())],
|
|
|
|
)
|
|
|
|
model = fields.Char(related="model_id.model", index=True, store=True)
|
|
|
|
review_type = fields.Selection(
|
|
|
|
string="Validated by",
|
|
|
|
default="individual",
|
|
|
|
selection=[
|
|
|
|
("individual", "Specific user"),
|
2021-08-01 02:14:00 +00:00
|
|
|
("group", "Any user in a specific group"),
|
|
|
|
("field", "Field in related record"),
|
2021-03-23 19:15:27 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
reviewer_id = fields.Many2one(comodel_name="res.users", string="Reviewer")
|
|
|
|
reviewer_group_id = fields.Many2one(
|
|
|
|
comodel_name="res.groups", string="Reviewer group"
|
|
|
|
)
|
2021-08-01 02:14:00 +00:00
|
|
|
reviewer_field_id = fields.Many2one(
|
|
|
|
comodel_name="ir.model.fields",
|
|
|
|
string="Reviewer field",
|
|
|
|
domain="[('id', 'in', valid_reviewer_field_ids)]",
|
|
|
|
)
|
|
|
|
valid_reviewer_field_ids = fields.One2many(
|
|
|
|
comodel_name="ir.model.fields",
|
|
|
|
compute="_compute_domain_reviewer_field",
|
|
|
|
)
|
2021-03-23 19:15:27 +00:00
|
|
|
definition_type = fields.Selection(
|
|
|
|
string="Definition", selection=[("domain", "Domain")], default="domain"
|
|
|
|
)
|
|
|
|
definition_domain = fields.Char()
|
|
|
|
active = fields.Boolean(default=True)
|
|
|
|
sequence = fields.Integer(default=30)
|
|
|
|
company_id = fields.Many2one(
|
|
|
|
comodel_name="res.company",
|
|
|
|
string="Company",
|
|
|
|
default=lambda self: self.env.company,
|
|
|
|
)
|
|
|
|
notify_on_create = fields.Boolean(
|
|
|
|
string="Notify Reviewers on Creation",
|
|
|
|
help="If set, all possible reviewers will be notified by email when "
|
|
|
|
"this definition is triggered.",
|
|
|
|
)
|
|
|
|
has_comment = fields.Boolean(string="Comment", default=False)
|
|
|
|
approve_sequence = fields.Boolean(
|
|
|
|
string="Approve by sequence",
|
|
|
|
default=False,
|
|
|
|
help="Approval order by the specified sequence number",
|
|
|
|
)
|
|
|
|
|
|
|
|
@api.onchange("review_type")
|
|
|
|
def onchange_review_type(self):
|
|
|
|
self.reviewer_id = None
|
|
|
|
self.reviewer_group_id = None
|
2021-08-01 02:14:00 +00:00
|
|
|
|
|
|
|
@api.depends("review_type", "model_id")
|
|
|
|
def _compute_domain_reviewer_field(self):
|
|
|
|
for rec in self:
|
|
|
|
rec.valid_reviewer_field_ids = self.env["ir.model.fields"].search(
|
|
|
|
[("model", "=", rec.model), ("relation", "=", "res.users")]
|
|
|
|
)
|