Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions report_async/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
============
Report Async
============

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
:target: https://github.com/OCA/reporting-engine/tree/14.0/report_async
:alt: OCA/reporting-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/reporting-engine-14-0/reporting-engine-14-0-report_async
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/143/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

The new menu "Report Center" is the central place to host your reports in one place.
From here, there are 2 ways to launch the report,

1. Run Now - run report immediately as per normal.
2. Run Background - put the report execution to queue job.

There are additional settings under *Reports* -> *Async Options* for specific reports using async options:

- Async report - Whether the report should be async.
- Min of Records - How many records required to trigger async reports.
- Mail Recipient - This by defualt is the logged in user's email, but can be reconfigured in a popup dialog.

By using the queue job, option 2 is great for long running report.
The report file will be saved for later use, with the option to send report
by email as soon as it is ready.

Notes:

* Only user with Technical Feature rights can manage the report.
* Every internal user will have right to execute the report allowed for his/her groups.
* The files created are owned and viewable only by the person who run the report.
* Job queue manager can also see all jobs for each reports.

**Table of contents**

.. contents::
:local:

Usage
=====

Menu: Dashboard > Report Center

As Technical Feature users, you can manage reports for Report Center.

- **Report:** choose the report (a window action). Although the option show all window actions
it only make sense for window actions that launch reports.
- **Allow Async:** check this, if you want the report to run in background too, suitable for
report that return file as result, i.e., pdf/xlsx/csv/txt.
- **Email Notification:** if checked, once the background process is completed, email with link to download
report will be sent.
- **Groups:** select user groups allowed to use this report. If left blank, all user can use.

As normal user, you can run your reports from Report Center

- **Run Now button:** to run report immediately as per normal.
- **Run Background button:** to run report asynchronously. Fall back to run now, if not report that produce file.
- **Job Status:** show status of the latest run job. If job fail, exception error will also shown
- **Files:** show all files being produced by the job as run by the user.
- **Jobs:** show all jobs triggered by this report as run by the user. Only job queue manager have access to this button.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_async%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Ecosoft

Contributors
~~~~~~~~~~~~

* `Ecosoft <http://ecosoft.co.th>`__:

* Kitti U. <kittiu@ecosoft.co.th>
* Saran Lim. <saranl@ecosoft.co.th>
* Tharathip Chaweewongphan <tharathipc@ecosoft.co.th>

* `Therp <http://therp.nl>`__:

- Nikos Tsirintanis <nikos@therp.nl>

* `Sunflower IT <https://sunflowerweb.nl>`__:

* Tom Blauwendraat <tom@sunflowerweb.nl>
* Kevin Kamau <kevin@sunflowerweb.nl>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-kittiu| image:: https://github.com/kittiu.png?size=40px
:target: https://github.com/kittiu
:alt: kittiu

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-kittiu|

This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/14.0/report_async>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions report_async/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from . import models
from . import wizard
27 changes: 27 additions & 0 deletions report_async/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
{
"name": "Report Async",
"summary": "Central place to run reports live or async",
"version": "14.0.1.0.0",
"author": "Ecosoft, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/reporting-engine",
"category": "Generic Modules",
"depends": ["queue_job"],
"data": [
"security/ir.model.access.csv",
"security/ir_rule.xml",
"views/assets.xml",
"data/mail_template.xml",
"data/queue_job_function_data.xml",
"views/report_async.xml",
"wizard/print_report_wizard.xml",
"views/ir_actions_report.xml",
],
"qweb": ["static/src/xml/report_async.xml"],
"demo": ["demo/report_async_demo.xml"],
"installable": True,
"maintainers": ["kittiu"],
"development_status": "Beta",
}
73 changes: 73 additions & 0 deletions report_async/data/mail_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="1">
<record id="async_report_delivery" model="mail.template">
<field name="name">Report Async: New Report Available</field>
<field name="model_id" ref="base.model_ir_attachment" />
<field name="subject">Your report is available, ${object.name}</field>
<field
name="email_from"
>${object.company_id.partner_id.email_formatted|safe}</field>
<field name="partner_to">${user.partner_id.id}</field>
<field name="body_html" type="html">
<table
border="0"
cellpadding="0"
cellspacing="0"
style="background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;"
>
<tr>
<td align="center">
<table
border="0"
cellpadding="0"
cellspacing="0"
width="590"
style="padding: 16px; background-color: white; color: #454748; border-collapse:separate;"
>
<tbody>
<tr>
<td align="center" style="min-width: 590px;">
<table
border="0"
cellpadding="0"
cellspacing="0"
width="590"
style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;"
>
<tr>
<td
valign="top"
style="font-size: 13px;"
>
% set base_url_async = object.env['ir.config_parameter'].sudo().get_param('web.base.url.async_reports')
% set base_url = base_url_async or object.env['ir.config_parameter'].sudo().get_param('web.base.url')
% set download_url = '%s/web/content/ir.attachment/%s/datas/%s?download=true' % (base_url, object.id, object.name, )
<div>
Dear ${object.create_uid.partner_id.name or ''},
<br /><br />
Your requested report, ${object.name}, is available for <b
>
<a
href='${download_url}'
>download</a>
</b>.
<br /><br />
Have a nice day!<br />
--<br />${object.company_id.name}
</div>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</field>
<field name="auto_delete" eval="True" />
</record>
</data>
</odoo>
6 changes: 6 additions & 0 deletions report_async/data/queue_job_function_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<odoo noupdate="1">
<record id="job_function_report_async_run_report" model="queue.job.function">
<field name="model_id" ref="report_async.model_report_async" />
<field name="method">run_report</field>
</record>
</odoo>
7 changes: 7 additions & 0 deletions report_async/demo/report_async_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="report_async_print_document" model="report.async">
<field name="action_id" eval="ref('report_async.action_print_report_wizard')" />
<field name="allow_async" eval="0" />
</record>
</odoo>
7 changes: 7 additions & 0 deletions report_async/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +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 . import report_async
from . import ir_report
from . import ir_actions
from . import queue_job
26 changes: 26 additions & 0 deletions report_async/models/ir_actions.py
Original file line number Diff line number Diff line change
@@ -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)
35 changes: 35 additions & 0 deletions report_async/models/ir_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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 fields, models

# Define all supported report_type
REPORT_TYPES = ["qweb-pdf", "qweb-text", "qweb-xml", "csv", "excel", "xlsx"]


class Report(models.Model):
_inherit = "ir.actions.report"

async_report = fields.Boolean(default=False)
async_no_records = fields.Integer(
string="Min of Records",
default=100,
help="Min no of records to use async report functionality; e.g 100+",
)
async_mail_recipient = fields.Char(
string="Mail Recipient",
help="The email that will receive the async report",
default=lambda self: self.env.user.email,
)

def report_action(self, docids, data=None, config=True):
res = super(Report, self).report_action(docids, data=data, config=config)
if res["context"].get("async_process", False):
rpt_async_id = res["context"]["active_id"]
report_async = self.env["report.async"].browse(rpt_async_id)
if res["report_type"] in REPORT_TYPES:
report_async.with_delay().run_report(
res["context"].get("active_ids", []), data, self.id, self._uid
)
return {}
return res
30 changes: 30 additions & 0 deletions report_async/models/queue_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2022 Sunflower IT (https://sunflowerweb.nl/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import api, models


class QueueJob(models.Model):
_inherit = "queue.job"

@api.model
def create(self, values):
res = super(QueueJob, self).create(values)
if (
"model_name" in values
and values["model_name"] == "report.async"
and "kwargs" in values
and "to_email" in values["kwargs"]
):
followers = self._find_partner(res, values["kwargs"]["to_email"])
if followers:
res.message_subscribe(partner_ids=followers)
return res

def _find_partner(self, record, email):
partner = self.env["res.partner"].search([("email", "=", email)], limit=1)
followers = record.message_follower_ids.mapped("partner_id")
ids = [x for x in partner.ids if x not in followers.ids]
if partner and ids:
return ids
return None
Loading