From 14d91d05c3a1505e91c766e6bfb1862cd4c7b5af Mon Sep 17 00:00:00 2001 From: GuillemCForgeFlow Date: Tue, 25 Jun 2024 17:45:14 +0200 Subject: [PATCH] [IMP]bi_sql_editor: scheduled action periodicity settings refactor `Action Settings` page to have all settings, renamed to `Settings`. Added the settings to be able to customize the periodicity of the Scheduled Action that will refresh the Materialized view. --- bi_sql_editor/README.rst | 15 ++-- bi_sql_editor/models/bi_sql_view.py | 33 ++++++-- bi_sql_editor/readme/CONFIGURE.md | 13 ++- bi_sql_editor/static/description/index.html | 16 ++-- bi_sql_editor/views/view_bi_sql_view.xml | 90 +++++++++++---------- 5 files changed, 104 insertions(+), 63 deletions(-) diff --git a/bi_sql_editor/README.rst b/bi_sql_editor/README.rst index aab31bac0a..a432e0692d 100644 --- a/bi_sql_editor/README.rst +++ b/bi_sql_editor/README.rst @@ -117,11 +117,16 @@ to make reporting depending on the current companies of the user. |image4| -- 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, which can be changed in order to have the report accessible + from a different place within Odoo. + - **Scheduled Action periodicity**: By going to the Settings page, + you can customize the frequency for which you want to run the + Scheduled Action that will refresh the Materialized view. - Finally, click on 'Create UI', to create new menu, action, graph view and search view. diff --git a/bi_sql_editor/models/bi_sql_view.py b/bi_sql_editor/models/bi_sql_view.py index e1b38f71d2..dd762388b9 100644 --- a/bi_sql_editor/models/bi_sql_view.py +++ b/bi_sql_editor/models/bi_sql_view.py @@ -136,27 +136,23 @@ 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", @@ -164,11 +160,28 @@ def _default_parent_menu_id(self): help="Cron Task that will refresh the materialized view", ondelete="cascade", ) + 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) 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): @@ -387,7 +400,11 @@ def _prepare_model_access(self): return res 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, @@ -397,9 +414,9 @@ def _prepare_cron(self): "state": "code", "code": "model._refresh_materialized_view_cron(%s)" % self.ids, "numbercall": -1, - "interval_number": 1, - "interval_type": "days", - "nextcall": now + timedelta(days=1), + "interval_number": interval_number, + "interval_type": interval_type, + "nextcall": now + timedelta(**date_interval_dict), "active": True, } diff --git a/bi_sql_editor/readme/CONFIGURE.md b/bi_sql_editor/readme/CONFIGURE.md index 187afad59d..3531e1f366 100644 --- a/bi_sql_editor/readme/CONFIGURE.md +++ b/bi_sql_editor/readme/CONFIGURE.md @@ -34,10 +34,15 @@ to make reporting depending on the current companies of the user. ![](../static/description/04_materialized_view_setting.png) -- 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, which can be + changed in order to have the report accessible from a different place within + Odoo. + - **Scheduled Action periodicity**: By going to the Settings page, you can + customize the frequency for which you want to run the Scheduled Action that + will refresh the Materialized view. - Finally, click on 'Create UI', to create new menu, action, graph view and search view. diff --git a/bi_sql_editor/static/description/index.html b/bi_sql_editor/static/description/index.html index d4ee7a4f7d..10310226b9 100644 --- a/bi_sql_editor/static/description/index.html +++ b/bi_sql_editor/static/description/index.html @@ -453,11 +453,17 @@

Configuration

image4

-
  • 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:

    +
  • Finally, click on ‘Create UI’, to create new menu, action, graph view and search view.

    diff --git a/bi_sql_editor/views/view_bi_sql_view.xml b/bi_sql_editor/views/view_bi_sql_view.xml index 4590e19a14..0e468705d3 100644 --- a/bi_sql_editor/views/view_bi_sql_view.xml +++ b/bi_sql_editor/views/view_bi_sql_view.xml @@ -185,53 +185,61 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - - - + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + +