Skip to content

Commit e12143d

Browse files
sakthi-shanatchuthan
authored andcommitted
[MIG] report_async: Migration to 17.0
1 parent 21310d5 commit e12143d

File tree

4 files changed

+34
-46
lines changed

4 files changed

+34
-46
lines changed

report_async/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"license": "AGPL-3",
99
"website": "https://github.com/OCA/reporting-engine",
1010
"category": "Generic Modules",
11-
"depends": ["queue_job"],
11+
"depends": ["queue_job", "spreadsheet_dashboard"],
1212
"data": [
1313
"security/ir.model.access.csv",
1414
"security/ir_rule.xml",

report_async/models/ir_actions.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
33

4-
from odoo import api, models
4+
from odoo import SUPERUSER_ID, api, models
55

66

77
class IrActionsActWindow(models.Model):
@@ -10,17 +10,17 @@ class IrActionsActWindow(models.Model):
1010
@api.model
1111
def name_search(self, name, args=None, operator="ilike", limit=100):
1212
if self._context.get("access_sudo", False):
13-
self = self.sudo()
13+
self = self.with_user(SUPERUSER_ID)
1414
return super().name_search(name, args, operator, limit)
1515

1616
@api.model
17-
def search(self, args, offset=0, limit=None, order=None, count=False):
17+
def search(self, args, offset=0, limit=None, order=None):
1818
if self._context.get("access_sudo", False):
19-
self = self.sudo()
20-
return super().search(args, offset, limit, order, count)
19+
self = self.with_user(SUPERUSER_ID)
20+
return super().search(args, offset, limit, order)
2121

22-
def _read(self, fields):
22+
def fetch(self, field_names):
2323
"""Add permission to read analytic account for do something."""
2424
if self._context.get("access_sudo", False):
25-
self = self.sudo()
26-
return super()._read(fields)
25+
self = self.with_user(SUPERUSER_ID)
26+
return super().fetch(field_names)

report_async/models/report_async.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import base64
55

6-
from odoo import _, api, fields, models
6+
from odoo import SUPERUSER_ID, _, api, fields, models
77
from odoo.exceptions import UserError
88
from odoo.tools.safe_eval import safe_eval
99

@@ -102,8 +102,7 @@ def _compute_file(self):
102102

103103
def run_now(self):
104104
self.ensure_one()
105-
action = self.env.ref(self.action_id.xml_id)
106-
result = action.sudo().read()[0]
105+
result = self.env[self.action_id.type]._for_xml_id(self.action_id.xml_id)
107106
ctx = safe_eval(result.get("context", {}))
108107
ctx.update({"async_process": False})
109108
result["context"] = ctx
@@ -113,24 +112,25 @@ def run_async(self):
113112
self.ensure_one()
114113
if not self.allow_async:
115114
raise UserError(_("Background process not allowed."))
116-
action = self.env.ref(self.action_id.xml_id)
117-
result = action.sudo().read()[0]
115+
result = self.env[self.action_id.type]._for_xml_id(self.action_id.xml_id)
118116
ctx = safe_eval(result.get("context", {}))
119117
ctx.update({"async_process": True})
120118
result["context"] = ctx
121119
return result
122120

123121
def view_files(self):
124122
self.ensure_one()
125-
action = self.env.ref("report_async.action_view_files")
126-
result = action.sudo().read()[0]
123+
result = self.env["ir.actions.act_window"]._for_xml_id(
124+
"report_async.action_view_files"
125+
)
127126
result["domain"] = [("id", "in", self.file_ids.ids)]
128127
return result
129128

130129
def view_jobs(self):
131130
self.ensure_one()
132-
action = self.env.ref("queue_job.action_queue_job")
133-
result = action.sudo().read()[0]
131+
result = self.env["ir.actions.act_window"]._for_xml_id(
132+
"queue_job.action_queue_job"
133+
)
134134
result["domain"] = [("id", "in", self.job_ids.ids)]
135135
result["context"] = {}
136136
return result
@@ -146,7 +146,7 @@ def run_report(self, docids, data, report_id, user_id):
146146
# Save report to attachment
147147
attachment = (
148148
self.env["ir.attachment"]
149-
.sudo()
149+
.with_user(SUPERUSER_ID)
150150
.create(
151151
{
152152
"name": out_name,

report_async/views/report_async.xml

+15-27
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,17 @@
1212
name="run_async"
1313
string="Run Background"
1414
icon="fa-cogs"
15-
attrs="{'invisible': [('allow_async', '=', False)]}"
15+
invisible="not allow_async"
1616
/>
1717
<button
1818
type="object"
1919
name="view_files"
2020
string="Files"
2121
icon="fa-copy"
22-
attrs="{'invisible': [('allow_async', '=', False)]}"
23-
/>
24-
<field name="allow_async" invisible="1" />
25-
<field
26-
name="job_status"
27-
attrs="{'invisible': [('allow_async', '=', False)]}"
22+
invisible="not allow_async"
2823
/>
24+
<field name="allow_async" column_invisible="1" />
25+
<field name="job_status" optional="hide" />
2926
<field name="email_notify" />
3027
</tree>
3128
</field>
@@ -38,8 +35,7 @@
3835
<div
3936
class="alert alert-warning"
4037
role="alert"
41-
attrs="{'invisible': ['|', ('job_status', 'in', ['done', 'failed', False]),
42-
('allow_async', '=', False)]}"
38+
invisible="not allow_async or (job_status in ['done', 'failed', False])"
4339
style="margin-bottom:0px;"
4440
>
4541
<p>
@@ -51,8 +47,7 @@
5147
<div
5248
class="alert alert-danger"
5349
role="alert"
54-
attrs="{'invisible': ['|', ('job_status', '!=', 'failed'),
55-
('allow_async', '=', False)]}"
50+
invisible="not allow_async or job_status != 'failed'"
5651
style="margin-bottom:0px;"
5752
>
5853
<p>
@@ -63,8 +58,7 @@
6358
<div
6459
class="alert alert-success"
6560
role="alert"
66-
attrs="{'invisible': ['|', ('job_status', '!=', 'done'),
67-
('allow_async', '=', False)]}"
61+
invisible="not allow_async or job_status != 'done'"
6862
style="margin-bottom:0px;"
6963
>
7064
<p>
@@ -75,7 +69,7 @@
7569
</p>
7670
</div>
7771
<sheet>
78-
<div class="oe_read_only oe_right oe_button_box" name="buttons">
72+
<div class="oe_button_box" name="button_box">
7973
<button
8074
type="object"
8175
name="run_now"
@@ -87,22 +81,22 @@
8781
name="run_async"
8882
string="Run Background"
8983
icon="fa-cogs"
90-
attrs="{'invisible': [('allow_async', '=', False)]}"
84+
invisible="not allow_async"
9185
/>
9286
<button
9387
type="object"
9488
name="view_files"
9589
string="Files"
9690
icon="fa-copy"
97-
attrs="{'invisible': [('allow_async', '=', False)]}"
91+
invisible="not allow_async"
9892
/>
9993
<button
10094
type="object"
10195
name="view_jobs"
10296
string="Jobs"
10397
icon="fa-align-justify"
10498
groups="queue_job.group_queue_job_manager"
105-
attrs="{'invisible': [('allow_async', '=', False)]}"
99+
invisible="not allow_async"
106100
/>
107101
</div>
108102
<group>
@@ -113,23 +107,17 @@
113107
context="{'access_sudo': True}"
114108
/>
115109
<field name="allow_async" />
116-
<field
117-
name="email_notify"
118-
attrs="{'invisible': [('allow_async', '=', False)]}"
119-
/>
110+
<field name="email_notify" invisible="not allow_async" />
120111
</group>
121112
<group>
122-
<field
123-
name="job_status"
124-
attrs="{'invisible': [('allow_async', '=', False)]}"
125-
/>
113+
<field name="job_status" invisible="not allow_async" />
126114
<field name="group_ids" widget="many2many_tags" />
127115
</group>
128116
<group
129117
name="job_info"
130118
string="Last Run Job Error"
131119
colspan="2"
132-
attrs="{'invisible': ['|', ('job_info', '=', False), ('allow_async', '=', False)]}"
120+
invisible="not allow_async or not job_info"
133121
>
134122
<field nolabel="1" name="job_info" />
135123
</group>
@@ -155,7 +143,7 @@
155143
</record>
156144
<menuitem
157145
id="menu_report_async"
158-
parent="base.menu_board_root"
146+
parent="spreadsheet_dashboard.spreadsheet_dashboard_menu_root"
159147
action="action_report_async"
160148
sequence="10"
161149
/>

0 commit comments

Comments
 (0)