Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[13.0][IMP]bi_sql_editor: scheduled action periodicity settings #925

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
38 changes: 30 additions & 8 deletions bi_sql_editor/models/bi_sql_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
from datetime import datetime
from datetime import datetime, timedelta

from psycopg2 import ProgrammingError

Expand All @@ -18,8 +18,9 @@

@api.model
def _instanciate(self, model_data):
""" Return a class for the custom model given by
parameters ``model_data``. """
"""Return a class for the custom model given by
parameters ``model_data``."""

# This monkey patch is meant to avoid create/search tables for those
# materialized views. Doing "super" doesn't work.
class CustomModel(models.Model):
Expand Down Expand Up @@ -181,33 +182,39 @@ def _default_parent_menu_id(self):
tree_view_id = fields.Many2one(
string="Odoo Tree View", comodel_name="ir.ui.view", readonly=True
)

graph_view_id = fields.Many2one(
string="Odoo Graph View", comodel_name="ir.ui.view", readonly=True
)

pivot_view_id = fields.Many2one(
string="Odoo Pivot View", comodel_name="ir.ui.view", readonly=True
)

search_view_id = fields.Many2one(
string="Odoo Search View", comodel_name="ir.ui.view", readonly=True
)

action_id = fields.Many2one(
string="Odoo Action", comodel_name="ir.actions.act_window", readonly=True
)

menu_id = fields.Many2one(
string="Odoo Menu", comodel_name="ir.ui.menu", readonly=True
)

# Scheduled Action related fields
cron_id = fields.Many2one(
string="Odoo Cron",
comodel_name="ir.cron",
readonly=True,
help="Cron Task that will refresh the materialized view",
)
cron_interval_number = fields.Integer(
help="Scheduled Action interval number", default=1, required=True
)
cron_interval_type = fields.Selection(
selection=lambda self: self._get_ir_cron_interval_type_selection(),
default="days",
required=True,
help="Scheduled Action interval type, same values as the ones "
"selectable in the Scheduled Action.",
)

rule_id = fields.Many2one(string="Odoo Rule", comodel_name="ir.rule", readonly=True)

Expand All @@ -219,6 +226,13 @@ def _default_parent_menu_id(self):

sequence = fields.Integer(string="sequence")

# Gets section
@api.model
def _get_ir_cron_interval_type_selection(self):
return self.env["ir.cron"].fields_get(allfields=["interval_type"])[
"interval_type"
]["selection"]

# Constrains Section
@api.constrains("is_materialized")
def _check_index_materialized(self):
Expand Down Expand Up @@ -403,6 +417,10 @@ def _prepare_model_access(self):

def _prepare_cron(self):
self.ensure_one()
now = datetime.now()
interval_number = self.cron_interval_number
interval_type = self.cron_interval_type
date_interval_dict = {interval_type: interval_number}
return {
"name": _("Refresh Materialized View %s") % self.view_name,
"user_id": SUPERUSER_ID,
Expand All @@ -412,6 +430,10 @@ def _prepare_cron(self):
"state": "code",
"code": "model._refresh_materialized_view_cron(%s)" % self.ids,
"numbercall": -1,
"interval_number": interval_number,
"interval_type": interval_type,
"nextcall": now + timedelta(**date_interval_dict),
"active": True,
}

def _prepare_rule(self):
Expand Down
13 changes: 9 additions & 4 deletions bi_sql_editor/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ To configure this module, you need to:
.. figure:: ../static/description/04_materialized_view_setting.png
:width: 800 px

* Before applying the final step, you will need to add a specific Parent Menu to
use when creating the UI Menu for the report. By default, it will be set with
the `SQL Views` menu, which can be changed before creating the UI elements in
order to have the report accessible from a different place within Odoo.
* Before creating the UI elements, you can modify two specific settings based on your
needs:

* **Parent Menu**: Apply a Parent Menu to use for when creating the UI elements. By
default, it will be set with the ``SQL Views`` menu, but you can change it to make
the report accessible from a different place within Odoo.

* **Scheduled Action periodicity**: To customize the frequency for running the
Scheduled Action that refreshes the Materialized view, go to the Settings page.

* Finally, click on 'Create UI', to create new menu, action, graph view and
search view.
49 changes: 30 additions & 19 deletions bi_sql_editor/views/view_bi_sql_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,28 +202,39 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<group string="Context">
<field name="action_context" nolabel="1" colspan="4" />
</group>
<group
name="ir_cron_settings"
string="Scheduled Action settings"
>
<field
name="cron_interval_number"
attrs="{'readonly': [('state', '=', 'ui_valid')]}"
/>
<field
name="cron_interval_type"
attrs="{'readonly': [('state', '=', 'ui_valid')]}"
/>
</group>
</page>
<page string="Extras Information">
<group>
<group string="Model">
<field name="model_name" />
<field
name="model_id"
attrs="{'invisible': [('state', '=', 'draft')]}"
/>
<group string="Model">
<field name="model_name" />
<field
name="model_id"
attrs="{'invisible': [('state', '=', 'draft')]}"
/>
</group>
<group string="User Interface">
<group string="UI Parameters">
<field name="parent_menu_id" />
</group>
<group string="User Interface">
<group string="UI Parameters">
<field name="parent_menu_id" />
</group>
<group string="UI Instances">
<field name="tree_view_id" />
<field name="graph_view_id" />
<field name="pivot_view_id" />
<field name="search_view_id" />
<field name="action_id" />
<field name="menu_id" />
</group>
<group string="UI Instances">
<field name="tree_view_id" />
<field name="graph_view_id" />
<field name="pivot_view_id" />
<field name="search_view_id" />
<field name="action_id" />
<field name="menu_id" />
</group>
</group>
</page>
Expand Down
Loading