From 6c3534e9422b800f8a79f10ff2af8c178d913a3b Mon Sep 17 00:00:00 2001 From: GuillemCForgeFlow Date: Tue, 4 Jun 2024 10:49:03 +0200 Subject: [PATCH] [IMP]bi_sql_editor: add parent menu as an editable parameter when creating UI elements When creating the UI for the SQL view, it is now possible to set a specific Parent Menu which will be used when creating the UI Menu for the report itself. The default value will be the `SQL Reports` menu. Also, added the explanation on the `CONFIGURE.rst` file to have the description updated. --- bi_sql_editor/README.rst | 8 ++++++++ bi_sql_editor/models/bi_sql_view.py | 20 +++++++++++++++++++- bi_sql_editor/readme/CONFIGURE.md | 5 +++++ bi_sql_editor/readme/CONTRIBUTORS.md | 4 +++- bi_sql_editor/static/description/index.html | 7 +++++++ bi_sql_editor/views/view_bi_sql_view.xml | 20 ++++++++++++++------ 6 files changed, 56 insertions(+), 8 deletions(-) diff --git a/bi_sql_editor/README.rst b/bi_sql_editor/README.rst index 3ac6991d60..69c124ac56 100644 --- a/bi_sql_editor/README.rst +++ b/bi_sql_editor/README.rst @@ -117,6 +117,12 @@ 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. + - Finally, click on 'Create UI', to create new menu, action, graph view and search view. @@ -168,6 +174,8 @@ Contributors - David James, WilldooIT (http://www.willdooit.com/) +- Guillem Casassas guillem.casassas@forgeflow.com + - This module is highly inspired by the work of - Onestein: (http://www.onestein.nl/) Module: diff --git a/bi_sql_editor/models/bi_sql_view.py b/bi_sql_editor/models/bi_sql_view.py index 42e4ee73d0..e1b38f71d2 100644 --- a/bi_sql_editor/models/bi_sql_view.py +++ b/bi_sql_editor/models/bi_sql_view.py @@ -114,7 +114,25 @@ 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 + @api.model + def _default_parent_menu_id(self): + return self.env.ref("bi_sql_editor.menu_bi_sql_editor") + + parent_menu_id = fields.Many2one( + string="Parent Odoo Menu", + comodel_name="ir.ui.menu", + required=True, + default=lambda self: self._default_parent_menu_id(), + 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.", + ) + + # 2. Readonly fields, non editable by the user tree_view_id = fields.Many2one( string="Odoo Tree View", comodel_name="ir.ui.view", readonly=True ) @@ -491,7 +509,7 @@ def _prepare_menu(self): self.ensure_one() return { "name": self.name, - "parent_id": self.env.ref("bi_sql_editor.menu_bi_sql_editor").id, + "parent_id": self.parent_menu_id.id, "action": "ir.actions.act_window,%s" % self.action_id.id, "sequence": self.sequence, } diff --git a/bi_sql_editor/readme/CONFIGURE.md b/bi_sql_editor/readme/CONFIGURE.md index 5b392945a4..187afad59d 100644 --- a/bi_sql_editor/readme/CONFIGURE.md +++ b/bi_sql_editor/readme/CONFIGURE.md @@ -34,5 +34,10 @@ 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. + - Finally, click on 'Create UI', to create new menu, action, graph view and search view. diff --git a/bi_sql_editor/readme/CONTRIBUTORS.md b/bi_sql_editor/readme/CONTRIBUTORS.md index 3999e458c1..c787a3c70e 100644 --- a/bi_sql_editor/readme/CONTRIBUTORS.md +++ b/bi_sql_editor/readme/CONTRIBUTORS.md @@ -4,7 +4,9 @@ - David James, WilldooIT () -- This module is highly inspired by the work of +- Guillem Casassas + +- This module is highly inspired by the work of - Onestein: () Module: OCA/server-tools/bi_view_editor. Link: diff --git a/bi_sql_editor/static/description/index.html b/bi_sql_editor/static/description/index.html index c75e72471e..7a7415bfbf 100644 --- a/bi_sql_editor/static/description/index.html +++ b/bi_sql_editor/static/description/index.html @@ -453,6 +453,12 @@

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.

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

  • @@ -496,6 +502,7 @@

    Contributors

  • Sylvain LE GAL (https://twitter.com/legalsylvain)
  • Richard deMeester, WilldooIT (http://www.willdooit.com/)
  • David James, WilldooIT (http://www.willdooit.com/)
  • +
  • Guillem Casassas guillem.casassas@forgeflow.com
  • This module is highly inspired by the work of
    • Onestein: (http://www.onestein.nl/) Module: OCA/server-tools/bi_view_editor. Link: diff --git a/bi_sql_editor/views/view_bi_sql_view.xml b/bi_sql_editor/views/view_bi_sql_view.xml index 1ee515a52a..4590e19a14 100644 --- a/bi_sql_editor/views/view_bi_sql_view.xml +++ b/bi_sql_editor/views/view_bi_sql_view.xml @@ -214,12 +214,20 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). /> - - - - - - + + + + + + + + + + +