-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathcx_tower_plan_run_wizard.py
More file actions
55 lines (45 loc) · 1.94 KB
/
cx_tower_plan_run_wizard.py
File metadata and controls
55 lines (45 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from odoo import api, fields, models
class CxTowerPlanRunWizardFilter(models.TransientModel):
_inherit = "cx.tower.plan.run.wizard"
is_restricted_context = fields.Boolean(compute="_compute_is_restricted_context")
isolated_tag_ids = fields.Many2many(
comodel_name="cx.tower.tag",
compute="_compute_isolated_tag_ids",
string="Forced Tags",
)
@api.depends("jet_ids")
def _compute_is_restricted_context(self):
is_global_manager = self.env.user.has_group("cetmix_tower_server.group_manager")
for record in self:
jets = record.jet_ids or self.env["cx.tower.jet"].browse(
self.env.context.get("default_jet_ids", [])
)
is_isolated = bool(
jets and any(j.jet_template_id.isolation_mode for j in jets)
)
if is_global_manager:
is_manager = True
elif jets and all(self.env.user in j.manager_ids for j in jets):
is_manager = True
else:
is_manager = False
record.is_restricted_context = is_isolated and not is_manager
@api.depends("tag_ids")
def _compute_isolated_tag_ids(self):
for record in self:
record.isolated_tag_ids = record.tag_ids
@api.model
def default_get(self, fields_list):
res = super().default_get(fields_list)
if "default_jet_ids" in self.env.context:
jet_ids = self.env["cx.tower.jet"].browse(
self.env.context["default_jet_ids"]
)
if jet_ids:
template = jet_ids[0].jet_template_id
if template.isolation_mode:
if template.forced_applicability:
res["applicability"] = template.forced_applicability
if template.forced_plan_tag_ids:
res["tag_ids"] = [(6, 0, template.forced_plan_tag_ids.ids)]
return res