Skip to content

Commit

Permalink
[MIG] report_async: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sakthi-shan authored and atchuthan committed Jun 11, 2024
1 parent 21310d5 commit e12143d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 46 deletions.
2 changes: 1 addition & 1 deletion report_async/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "AGPL-3",
"website": "https://github.com/OCA/reporting-engine",
"category": "Generic Modules",
"depends": ["queue_job"],
"depends": ["queue_job", "spreadsheet_dashboard"],
"data": [
"security/ir.model.access.csv",
"security/ir_rule.xml",
Expand Down
16 changes: 8 additions & 8 deletions report_async/models/ir_actions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import api, models
from odoo import SUPERUSER_ID, api, models


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

Check warning on line 14 in report_async/models/ir_actions.py

View check run for this annotation

Codecov / codecov/patch

report_async/models/ir_actions.py#L13-L14

Added lines #L13 - L14 were not covered by tests

@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
def search(self, args, offset=0, limit=None, order=None):
if self._context.get("access_sudo", False):
self = self.sudo()
return super().search(args, offset, limit, order, count)
self = self.with_user(SUPERUSER_ID)
return super().search(args, offset, limit, order)

Check warning on line 20 in report_async/models/ir_actions.py

View check run for this annotation

Codecov / codecov/patch

report_async/models/ir_actions.py#L19-L20

Added lines #L19 - L20 were not covered by tests

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

Check warning on line 25 in report_async/models/ir_actions.py

View check run for this annotation

Codecov / codecov/patch

report_async/models/ir_actions.py#L25

Added line #L25 was not covered by tests
return super().fetch(field_names)
20 changes: 10 additions & 10 deletions report_async/models/report_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import base64

from odoo import _, api, fields, models
from odoo import SUPERUSER_ID, _, api, fields, models
from odoo.exceptions import UserError
from odoo.tools.safe_eval import safe_eval

Expand Down Expand Up @@ -102,8 +102,7 @@ def _compute_file(self):

def run_now(self):
self.ensure_one()
action = self.env.ref(self.action_id.xml_id)
result = action.sudo().read()[0]
result = self.env[self.action_id.type]._for_xml_id(self.action_id.xml_id)
ctx = safe_eval(result.get("context", {}))
ctx.update({"async_process": False})
result["context"] = ctx
Expand All @@ -113,24 +112,25 @@ def run_async(self):
self.ensure_one()
if not self.allow_async:
raise UserError(_("Background process not allowed."))
action = self.env.ref(self.action_id.xml_id)
result = action.sudo().read()[0]
result = self.env[self.action_id.type]._for_xml_id(self.action_id.xml_id)
ctx = safe_eval(result.get("context", {}))
ctx.update({"async_process": True})
result["context"] = ctx
return result

def view_files(self):
self.ensure_one()
action = self.env.ref("report_async.action_view_files")
result = action.sudo().read()[0]
result = self.env["ir.actions.act_window"]._for_xml_id(
"report_async.action_view_files"
)
result["domain"] = [("id", "in", self.file_ids.ids)]
return result

def view_jobs(self):
self.ensure_one()
action = self.env.ref("queue_job.action_queue_job")
result = action.sudo().read()[0]
result = self.env["ir.actions.act_window"]._for_xml_id(
"queue_job.action_queue_job"
)
result["domain"] = [("id", "in", self.job_ids.ids)]
result["context"] = {}
return result
Expand All @@ -146,7 +146,7 @@ def run_report(self, docids, data, report_id, user_id):
# Save report to attachment
attachment = (
self.env["ir.attachment"]
.sudo()
.with_user(SUPERUSER_ID)
.create(
{
"name": out_name,
Expand Down
42 changes: 15 additions & 27 deletions report_async/views/report_async.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@
name="run_async"
string="Run Background"
icon="fa-cogs"
attrs="{'invisible': [('allow_async', '=', False)]}"
invisible="not allow_async"
/>
<button
type="object"
name="view_files"
string="Files"
icon="fa-copy"
attrs="{'invisible': [('allow_async', '=', False)]}"
/>
<field name="allow_async" invisible="1" />
<field
name="job_status"
attrs="{'invisible': [('allow_async', '=', False)]}"
invisible="not allow_async"
/>
<field name="allow_async" column_invisible="1" />
<field name="job_status" optional="hide" />
<field name="email_notify" />
</tree>
</field>
Expand All @@ -38,8 +35,7 @@
<div
class="alert alert-warning"
role="alert"
attrs="{'invisible': ['|', ('job_status', 'in', ['done', 'failed', False]),
('allow_async', '=', False)]}"
invisible="not allow_async or (job_status in ['done', 'failed', False])"
style="margin-bottom:0px;"
>
<p>
Expand All @@ -51,8 +47,7 @@
<div
class="alert alert-danger"
role="alert"
attrs="{'invisible': ['|', ('job_status', '!=', 'failed'),
('allow_async', '=', False)]}"
invisible="not allow_async or job_status != 'failed'"
style="margin-bottom:0px;"
>
<p>
Expand All @@ -63,8 +58,7 @@
<div
class="alert alert-success"
role="alert"
attrs="{'invisible': ['|', ('job_status', '!=', 'done'),
('allow_async', '=', False)]}"
invisible="not allow_async or job_status != 'done'"
style="margin-bottom:0px;"
>
<p>
Expand All @@ -75,7 +69,7 @@
</p>
</div>
<sheet>
<div class="oe_read_only oe_right oe_button_box" name="buttons">
<div class="oe_button_box" name="button_box">
<button
type="object"
name="run_now"
Expand All @@ -87,22 +81,22 @@
name="run_async"
string="Run Background"
icon="fa-cogs"
attrs="{'invisible': [('allow_async', '=', False)]}"
invisible="not allow_async"
/>
<button
type="object"
name="view_files"
string="Files"
icon="fa-copy"
attrs="{'invisible': [('allow_async', '=', False)]}"
invisible="not allow_async"
/>
<button
type="object"
name="view_jobs"
string="Jobs"
icon="fa-align-justify"
groups="queue_job.group_queue_job_manager"
attrs="{'invisible': [('allow_async', '=', False)]}"
invisible="not allow_async"
/>
</div>
<group>
Expand All @@ -113,23 +107,17 @@
context="{'access_sudo': True}"
/>
<field name="allow_async" />
<field
name="email_notify"
attrs="{'invisible': [('allow_async', '=', False)]}"
/>
<field name="email_notify" invisible="not allow_async" />
</group>
<group>
<field
name="job_status"
attrs="{'invisible': [('allow_async', '=', False)]}"
/>
<field name="job_status" invisible="not allow_async" />
<field name="group_ids" widget="many2many_tags" />
</group>
<group
name="job_info"
string="Last Run Job Error"
colspan="2"
attrs="{'invisible': ['|', ('job_info', '=', False), ('allow_async', '=', False)]}"
invisible="not allow_async or not job_info"
>
<field nolabel="1" name="job_info" />
</group>
Expand All @@ -155,7 +143,7 @@
</record>
<menuitem
id="menu_report_async"
parent="base.menu_board_root"
parent="spreadsheet_dashboard.spreadsheet_dashboard_menu_root"
action="action_report_async"
sequence="10"
/>
Expand Down

0 comments on commit e12143d

Please sign in to comment.