Skip to content

Commit

Permalink
[IMP]bi_sql_editor: scheduled action periodicity settings
Browse files Browse the repository at this point in the history
Based on changes done in: #903
  • Loading branch information
GuillemCForgeFlow committed Aug 30, 2024
1 parent c3f636d commit 7b28803
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 778 deletions.
197 changes: 0 additions & 197 deletions bi_sql_editor/README.rst

This file was deleted.

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.
Loading

0 comments on commit 7b28803

Please sign in to comment.