-
-
Notifications
You must be signed in to change notification settings - Fork 560
Expand file tree
/
Copy pathqueue_job.py
More file actions
43 lines (36 loc) · 1.37 KB
/
queue_job.py
File metadata and controls
43 lines (36 loc) · 1.37 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
# Copyright 2019 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from odoo import fields, models
class QueueJob(models.Model):
_inherit = "queue.job"
job_is_profiled = fields.Boolean(
string="Profiled",
default=False,
help="Whether this job has been profiled or not.",
compute="_compute_job_is_profiled",
)
def _compute_job_is_profiled(self):
for job in self:
# don't care about perf as this is loaded only on the job form view
profile_name = job.job_function_id._profile_make_name(job)
job.job_is_profiled = bool(job._profiler_get_record(profile_name))
def _profiler_get_record(self, profile_name):
IrProfile = self.env["ir.profile"]
return IrProfile.search(
[("name", "=", profile_name)],
limit=1,
)
def action_view_profile(self):
self.ensure_one()
profile_name = self.job_function_id._profile_make_name(self)
profile = self._profiler_get_record(profile_name)
if not profile:
return {"type": "ir.actions.act_window_close"}
return {
"type": "ir.actions.act_window",
"name": "Profile",
"res_model": "ir.profile",
"view_mode": "form",
"res_id": profile.id,
"target": "current",
}