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

[17.0][IMP]bi_sql_editor: scheduled action periodicity settings #903

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
15 changes: 10 additions & 5 deletions bi_sql_editor/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 25 additions & 8 deletions bi_sql_editor/models/bi_sql_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,39 +136,52 @@ 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",
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):
Expand Down Expand Up @@ -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,
Expand All @@ -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,
}

Expand Down
13 changes: 9 additions & 4 deletions bi_sql_editor/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
16 changes: 11 additions & 5 deletions bi_sql_editor/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,17 @@ <h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
</blockquote>
<p><img alt="image4" src="https://raw.githubusercontent.com/OCA/reporting-engine/17.0/bi_sql_editor/static/description/04_materialized_view_setting.png" /></p>
</li>
<li><p class="first">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 <tt class="docutils literal">SQL Views</tt> menu, which can be
changed before creating the UI elements in order to have the report
accessible from a different place within Odoo.</p>
<li><p class="first">Before creating the UI elements: you can modify two specific settings
based on your needs:</p>
<ul class="simple">
<li><strong>Parent Menu</strong>: Apply a Parent Menu to use for when creating the
UI elements. By default, it will be set with the <tt class="docutils literal">SQL Views</tt>
menu, which can be changed in order to have the report accessible
from a different place within Odoo.</li>
<li><strong>Scheduled Action periodicity</strong>: 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.</li>
</ul>
</li>
<li><p class="first">Finally, click on ‘Create UI’, to create new menu, action, graph view
and search view.</p>
Expand Down
90 changes: 49 additions & 41 deletions bi_sql_editor/views/view_bi_sql_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,53 +185,61 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
</field>

<page name="page_security" position="after">
<page string="Action Settings">
<group string="Computed Context">
<field
name="computed_action_context"
nolabel="1"
colspan="2"
<page string="Settings" name="page_settings">
<group name="action_settings" string="Action Settings">
<group string="Computed Context">
<field
name="computed_action_context"
nolabel="1"
colspan="2"
/>
</group>
<group string="Custom Context">
<field
name="action_context"
readonly="state not in ('draft', 'sql_valid', 'model_valid')"
nolabel="1"
colspan="2"
widget="ace"
options="{'mode': 'python'}"
/>
</group>
</group>
<group name="ir_cron_settings" string="Scheduled Action settings">
<field
name="cron_interval_number"
readonly="state == 'ui_valid'"
/>
</group>
<group string="Custom Context">
<field
name="action_context"
readonly="state not in ('draft', 'sql_valid', 'model_valid')"
nolabel="1"
colspan="2"
widget="ace"
options="{'mode': 'python'}"
<field
name="cron_interval_type"
readonly="state == 'ui_valid'"
/>
</group>
</page>
<page string="Extras Information">
<group>
<group string="Model">
<field name="model_name" />
<field
name="model_id"
invisible="state == 'draft'"
/>
</group>
<group string="User Interface">
<group string="UI Parameters">
<field
</group>
</page>
<page string="Extras Information">
<group>
<group string="Model">
<field name="model_name" />
<field name="model_id" invisible="state == 'draft'" />
</group>
<group string="User Interface">
<group string="UI Parameters">
<field
name="parent_menu_id"
readonly="state == 'ui_valid'"
/>
</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>
</group>
</page>

<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>
</group>
</page>
</page>

<field name="group_ids" position="attributes">
Expand Down
Loading