[14.0][MIG] report_async

This commit is contained in:
newtratip
2021-12-20 20:09:18 +07:00
committed by Kitti U
parent 266f4b1933
commit f61b08b01e
13 changed files with 52 additions and 915 deletions

View File

@@ -3,3 +3,4 @@
from . import report_async
from . import ir_report
from . import ir_actions

View File

@@ -0,0 +1,26 @@
# 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
class IrActionsActWindow(models.Model):
_inherit = "ir.actions.act_window"
@api.model
def name_search(self, name, args=None, operator="ilike", limit=100):
if self._context.get("access_sudo", False):
self = self.sudo()
return super().name_search(name, args, operator, limit)
@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
if self._context.get("access_sudo", False):
self = self.sudo()
return super().search(args, offset, limit, order, count)
def _read(self, fields):
"""Add permission to read analytic account for do something."""
if self._context.get("access_sudo", False):
self = self.sudo()
return super()._read(fields)

View File

@@ -7,16 +7,14 @@ from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.tools.safe_eval import safe_eval
from odoo.addons.queue_job.job import job
# Define all supported report_type
REPORT_TYPES_FUNC = {
"qweb-pdf": "render_qweb_pdf",
"qweb-text": "render_qweb_text",
"qweb-xml": "render_qweb_xml",
"csv": "render_csv",
"qweb-pdf": "_render_qweb_pdf",
"qweb-text": "_render_qweb_text",
"qweb-xml": "_render_qweb_xml",
"csv": "_render_csv",
"excel": "render_excel",
"xlsx": "render_xlsx",
"xlsx": "_render_xlsx",
}
@@ -106,7 +104,7 @@ class ReportAsync(models.Model):
def run_now(self):
self.ensure_one()
action = self.env.ref(self.action_id.xml_id)
result = action.read()[0]
result = action.sudo().read()[0]
ctx = safe_eval(result.get("context", {}))
ctx.update({"async_process": False})
result["context"] = ctx
@@ -117,7 +115,7 @@ class ReportAsync(models.Model):
if not self.allow_async:
raise UserError(_("Background process not allowed."))
action = self.env.ref(self.action_id.xml_id)
result = action.read()[0]
result = action.sudo().read()[0]
ctx = safe_eval(result.get("context", {}))
ctx.update({"async_process": True})
result["context"] = ctx
@@ -126,20 +124,19 @@ class ReportAsync(models.Model):
def view_files(self):
self.ensure_one()
action = self.env.ref("report_async.action_view_files")
result = action.read()[0]
result = action.sudo().read()[0]
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.read()[0]
result = action.sudo().read()[0]
result["domain"] = [("id", "in", self.job_ids.ids)]
result["context"] = {}
return result
@api.model
@job
def run_report(self, docids, data, report_id, user_id):
report = self.env["ir.actions.report"].browse(report_id)
func = REPORT_TYPES_FUNC[report.report_type]