Skip to content

Commit

Permalink
[IMP]bi_sql_editor: override parent menu with editable parameter
Browse files Browse the repository at this point in the history
When creating the UI for the SQL view, it is now possible to override the Parent Menu which will be used when creating the UI Menu for the report itself, if none is set, it will be created under the `SQL Reports` menu + it will be assigned as the Parent Menu as none has been provided.
Also, added the explanation on the `CONFIGURE.rst` file to have the description updated.
  • Loading branch information
GuillemCForgeFlow committed Jun 4, 2024
1 parent bea2980 commit 8c1cbd6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
24 changes: 23 additions & 1 deletion bi_sql_editor/models/bi_sql_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,24 @@ class BiSQLView(models.Model):
model_id = fields.Many2one(
string="Odoo Model", comodel_name="ir.model", readonly=True
)
# UI related fields
# 1. Editable fields, which can be set by the user (optional) before
# creating the UI elements
parent_menu_id = fields.Many2one(
string="Parent Odoo Menu",
comodel_name="ir.ui.menu",
help="By assigning a value to this field before manually creating the "
"UI, you're overwriting the parent menu on which the menu related to "
"the SQL report will be created.",
readonly=True,
states={
"draft": [("readonly", False)],
"sql_valid": [("readonly", False)],
"model_valid": [("readonly", False)],
},
)

# 2. Readonly fields, non editable by the user
tree_view_id = fields.Many2one(
string="Odoo Tree View", comodel_name="ir.ui.view", readonly=True
)
Expand Down Expand Up @@ -490,9 +507,14 @@ def _prepare_action_name(self):

def _prepare_menu(self):
self.ensure_one()
parent_id = (
self.parent_menu_id.id
or self.env.ref("bi_sql_editor.menu_bi_sql_editor").id
)
self.write({"parent_menu_id": parent_id})
return {
"name": self.name,
"parent_id": self.env.ref("bi_sql_editor.menu_bi_sql_editor").id,
"parent_id": parent_id,
"action": "ir.actions.act_window,%s" % self.action_id.id,
"sequence": self.sequence,
}
Expand Down
5 changes: 5 additions & 0 deletions bi_sql_editor/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ To configure this module, you need to:
.. figure:: ../static/description/04_materialized_view_setting.png
:width: 800 px

* Before applying the final step, you can also add a specific Parent Menu to
use when creating the UI Menu for the report. That way you can set the access
for the Report in specific places if you wish to, otherwise it will default to
have the `SQL Views` menu.

* Finally, click on 'Create UI', to create new menu, action, graph view and
search view.
17 changes: 11 additions & 6 deletions bi_sql_editor/views/view_bi_sql_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,17 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
/>
</group>
<group string="User Interface">
<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 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>
</group>
</page>
Expand Down

0 comments on commit 8c1cbd6

Please sign in to comment.