From e51ac7398675d0dc4b4f2f77f861f5456e806939 Mon Sep 17 00:00:00 2001
From: chien
Date: Thu, 21 Dec 2023 10:15:33 +0700
Subject: [PATCH] [MIG] bi_sql_editor: Migration to 17.0
---
bi_sql_editor/README.rst | 4 +-
bi_sql_editor/__manifest__.py | 2 +-
bi_sql_editor/hooks.py | 5 +-
bi_sql_editor/models/bi_sql_view.py | 30 +----
bi_sql_editor/models/bi_sql_view_field.py | 12 +-
bi_sql_editor/readme/USAGE.md | 2 +-
bi_sql_editor/static/description/index.html | 138 +++++++++-----------
bi_sql_editor/views/view_bi_sql_view.xml | 102 +++++++++------
8 files changed, 134 insertions(+), 161 deletions(-)
diff --git a/bi_sql_editor/README.rst b/bi_sql_editor/README.rst
index 866ba4c29..c976a655f 100644
--- a/bi_sql_editor/README.rst
+++ b/bi_sql_editor/README.rst
@@ -135,11 +135,11 @@ To use this module, you need to:
..
- |image1|
+ |usage-image1|
- You can switch to 'Graph' or 'tree' views as any report.
-.. |image1| image:: https://raw.githubusercontent.com/OCA/reporting-engine/17.0/bi_sql_editor/static/description/05_reporting_pivot.png
+.. |usage-image1| image:: https://raw.githubusercontent.com/OCA/reporting-engine/17.0/bi_sql_editor/static/description/05_reporting_pivot.png
Bug Tracker
===========
diff --git a/bi_sql_editor/__manifest__.py b/bi_sql_editor/__manifest__.py
index d352d52d1..9bf6453bc 100644
--- a/bi_sql_editor/__manifest__.py
+++ b/bi_sql_editor/__manifest__.py
@@ -5,7 +5,7 @@
{
"name": "BI SQL Editor",
"summary": "BI Views builder, based on Materialized or Normal SQL Views",
- "version": "16.0.1.0.5",
+ "version": "17.0.1.0.0",
"license": "AGPL-3",
"category": "Reporting",
"author": "GRAP,Odoo Community Association (OCA)",
diff --git a/bi_sql_editor/hooks.py b/bi_sql_editor/hooks.py
index 25fe633ed..d11a79c56 100644
--- a/bi_sql_editor/hooks.py
+++ b/bi_sql_editor/hooks.py
@@ -1,11 +1,8 @@
# Copyright 2015-2017 Onestein ()
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-from odoo import SUPERUSER_ID
-from odoo.api import Environment
-def uninstall_hook(cr, registry):
- env = Environment(cr, SUPERUSER_ID, {})
+def uninstall_hook(env):
recs = env["bi.sql.view"].search([])
for rec in recs:
rec.button_set_draft()
diff --git a/bi_sql_editor/models/bi_sql_view.py b/bi_sql_editor/models/bi_sql_view.py
index 4276e27dc..d8bf66088 100644
--- a/bi_sql_editor/models/bi_sql_view.py
+++ b/bi_sql_editor/models/bi_sql_view.py
@@ -59,8 +59,6 @@ class BiSQLView(models.Model):
is_materialized = fields.Boolean(
string="Is Materialized View",
default=True,
- readonly=True,
- states={"draft": [("readonly", False)], "sql_valid": [("readonly", False)]},
)
materialized_text = fields.Char(compute="_compute_materialized_text", store=True)
@@ -75,8 +73,6 @@ class BiSQLView(models.Model):
view_order = fields.Char(
required=True,
- readonly=False,
- states={"ui_valid": [("readonly", True)]},
default="pivot,graph,tree",
help="Comma-separated text. Possible values:" ' "graph", "pivot" or "tree"',
)
@@ -93,28 +89,20 @@ class BiSQLView(models.Model):
domain_force = fields.Text(
string="Extra Rule Definition",
default="[]",
- readonly=True,
help="Define here access restriction to data.\n"
" Take care to use field name prefixed by 'x_'."
" A global 'ir.rule' will be created."
" A typical Multi Company rule is for exemple \n"
" ['|', ('x_company_id','child_of', [user.company_id.id]),"
"('x_company_id','=',False)].",
- states={"draft": [("readonly", False)], "sql_valid": [("readonly", False)]},
)
computed_action_context = fields.Text(compute="_compute_computed_action_context")
action_context = fields.Text(
default="{}",
- readonly=True,
help="Define here a context that will be used"
" by default, when creating the action.",
- states={
- "draft": [("readonly", False)],
- "sql_valid": [("readonly", False)],
- "model_valid": [("readonly", False)],
- },
)
bi_sql_view_field_ids = fields.One2many(
@@ -161,12 +149,6 @@ class BiSQLView(models.Model):
rule_id = fields.Many2one(string="Odoo Rule", comodel_name="ir.rule", readonly=True)
- group_ids = fields.Many2many(
- comodel_name="res.groups",
- readonly=True,
- states={"draft": [("readonly", False)], "sql_valid": [("readonly", False)]},
- )
-
sequence = fields.Integer(string="sequence")
# Constrains Section
@@ -522,8 +504,7 @@ class BiSQLView(models.Model):
def _drop_view(self):
for sql_view in self:
self._log_execute(
- "DROP %s VIEW IF EXISTS %s"
- % (sql_view.materialized_text, sql_view.view_name)
+ f"DROP {sql_view.materialized_text} VIEW IF EXISTS {sql_view.view_name}"
)
sql_view.size = False
@@ -552,12 +533,7 @@ class BiSQLView(models.Model):
lambda x: x.is_index is True
):
self._log_execute(
- "CREATE INDEX %(index_name)s ON %(view_name)s (%(field_name)s);"
- % {
- "index_name": sql_field.index_name,
- "view_name": sql_view.view_name,
- "field_name": sql_field.name,
- }
+ f"CREATE INDEX {sql_field.index_name} ON {sql_view.view_name} ({sql_field.name});"
)
def _create_model_and_fields(self):
@@ -639,7 +615,7 @@ class BiSQLView(models.Model):
field_ids = []
for column in columns:
existing_field = self.bi_sql_view_field_ids.filtered(
- lambda x: x.name == column[1]
+ lambda x, c=column: x.name == c[1]
)
if existing_field:
# Update existing field
diff --git a/bi_sql_editor/models/bi_sql_view_field.py b/bi_sql_editor/models/bi_sql_view_field.py
index eab5ba35d..f098f20c2 100644
--- a/bi_sql_editor/models/bi_sql_view_field.py
+++ b/bi_sql_editor/models/bi_sql_view_field.py
@@ -76,34 +76,29 @@ class BiSQLViewField(models.Model):
help="Check this box if you want to create"
" an index on that field. This is recommended for searchable and"
" groupable fields, to reduce duration",
- states={"model_valid": [("readonly", True)], "ui_valid": [("readonly", True)]},
)
is_group_by = fields.Boolean(
string="Is Group by",
help="Check this box if you want to create"
" a 'group by' option in the search view",
- states={"ui_valid": [("readonly", True)]},
)
index_name = fields.Char(compute="_compute_index_name")
graph_type = fields.Selection(
selection=_GRAPH_TYPE_SELECTION,
- states={"ui_valid": [("readonly", True)]},
)
tree_visibility = fields.Selection(
selection=_TREE_VISIBILITY_SELECTION,
default="available",
required=True,
- states={"ui_valid": [("readonly", True)]},
)
field_description = fields.Char(
help="This will be used as the name of the Odoo field, displayed for users",
required=True,
- states={"model_valid": [("readonly", True)], "ui_valid": [("readonly", True)]},
)
ttype = fields.Selection(
@@ -113,7 +108,6 @@ class BiSQLViewField(models.Model):
" Odoo field that will be created. Keep empty if you don't want to"
" create a new field. If empty, this field will not be displayed"
" neither available for search or group by function",
- states={"model_valid": [("readonly", True)], "ui_valid": [("readonly", True)]},
)
selection = fields.Text(
@@ -123,28 +117,24 @@ class BiSQLViewField(models.Model):
" List of options, specified as a Python expression defining a list of"
" (key, label) pairs. For example:"
" [('blue','Blue'), ('yellow','Yellow')]",
- states={"model_valid": [("readonly", True)], "ui_valid": [("readonly", True)]},
)
many2one_model_id = fields.Many2one(
comodel_name="ir.model",
string="Model",
help="For 'Many2one' Odoo field.\n" " Comodel of the field.",
- states={"model_valid": [("readonly", True)], "ui_valid": [("readonly", True)]},
)
group_operator = fields.Selection(
selection=_GROUP_OPERATOR_SELECTION,
help="By default, Odoo will sum the values when grouping. If you wish "
"to alter the behaviour, choose an alternate Group Operator",
- states={"model_valid": [("readonly", True)], "ui_valid": [("readonly", True)]},
)
field_context = fields.Char(
default="{}",
help="Context value that will be inserted for this field in all the views."
" Important note : please write a context with single quote.",
- states={"ui_valid": [("readonly", True)]},
)
# Constrains Section
@@ -255,7 +245,7 @@ class BiSQLViewField(models.Model):
return ""
visibility_text = ""
if self.tree_visibility == "invisible":
- visibility_text = 'invisible="1"'
+ visibility_text = 'column_invisible="1"'
elif self.tree_visibility == "optional_hide":
visibility_text = 'optional="hide"'
elif self.tree_visibility == "optional_show":
diff --git a/bi_sql_editor/readme/USAGE.md b/bi_sql_editor/readme/USAGE.md
index 1d3742de5..26aa5841f 100644
--- a/bi_sql_editor/readme/USAGE.md
+++ b/bi_sql_editor/readme/USAGE.md
@@ -3,6 +3,6 @@ To use this module, you need to:
1. Go to 'Dashboards \> SQL Reports'
2. Select the desired report
-> 
+> 
- You can switch to 'Graph' or 'tree' views as any report.
diff --git a/bi_sql_editor/static/description/index.html b/bi_sql_editor/static/description/index.html
index 702588824..844d6d215 100644
--- a/bi_sql_editor/static/description/index.html
+++ b/bi_sql_editor/static/description/index.html
@@ -1,4 +1,3 @@
-
@@ -369,38 +368,43 @@ ul.auto-toc {
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2cd8ab59abe1f67505f360059541525311a4e5f9d41ecf7e5713ea9bedb55540
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
+
This module extends the functionality of reporting, to support creation
-of extra custom reports.
-It allows user to write a custom SQL request. (Generally, admin users)
-
Once written, a new model is generated, and user can map the selected field
-with odoo fields.
-Then user ends the process, creating new menu, action and graph view.
-
Technically, the module create SQL View (or materialized view, if option is
-checked). Materialized view duplicates datas, but request are fastest. If
-materialized view is enabled, this module will create a cron task to refresh
-the data).
+of extra custom reports. It allows user to write a custom SQL request.
+(Generally, admin users)
+
Once written, a new model is generated, and user can map the selected
+field with odoo fields. Then user ends the process, creating new menu,
+action and graph view.
+
Technically, the module create SQL View (or materialized view, if option
+is checked). Materialized view duplicates datas, but request are
+fastest. If materialized view is enabled, this module will create a cron
+task to refresh the data).
By default, users member of ‘SQL Request / User’ can see all the views.
-You can specify extra groups that have the right to access to a specific view.
+You can specify extra groups that have the right to access to a specific
+view.
Warning
-
This module is intended for technician people in a company and for Odoo integrators.
+
This module is intended for technician people in a company and for Odoo
+integrators.
It requires the user to know SQL syntax and Odoo models.
-
If you don’t have such skills, do not try to use this module specially on a production
-environment.
+
If you don’t have such skills, do not try to use this module specially
+on a production environment.
Use Cases
this module is interesting for the following use cases
-
You want to realize technical SQL requests, that Odoo framework doesn’t allow
-(For exemple, UNION with many SELECT) A typical use case is if you want to have
-Sale Orders and PoS Orders datas in a same table
-
You want to customize an Odoo report, removing some useless fields and adding
-some custom ones. In that case, you can simply select the fields of the original
-report (sale.report model for exemple), and add your custom fields
-
You have a lot of data, and classical SQL Views have very bad performance.
-In that case, MATERIALIZED VIEW will be a good solution to reduce display duration
+
You want to realize technical SQL requests, that Odoo framework
+doesn’t allow (For exemple, UNION with many SELECT) A typical use
+case is if you want to have Sale Orders and PoS Orders datas in a
+same table
+
You want to customize an Odoo report, removing some useless fields
+and adding some custom ones. In that case, you can simply select the
+fields of the original report (sale.report model for exemple), and
+add your custom fields
+
You have a lot of data, and classical SQL Views have very bad
+performance. In that case, MATERIALIZED VIEW will be a good solution
+to reduce display duration
Table of contents
@@ -408,12 +412,7 @@ In that case, MATERIALIZED VIEW will be a good solution to reduce display durati
@@ -422,14 +421,10 @@ In that case, MATERIALIZED VIEW will be a good solution to reduce display durati
Go to Dashboard / Configuration / SQL Views
tip your SQL request
-
-
-
+
Select the group(s) that could have access to the view
-
-
-
+
Optionnaly, you can add a domain.
@@ -439,31 +434,27 @@ to make reporting depending on the current companies of the user.
Click on the button ‘Validate SQL Expression’
-
Once the sql request checked, the module analyses the column of the view,
-and propose field mapping. For each field, you can decide to create an index
-and set if it will be displayed on the pivot graph as a column, a row or a
-measure.
-
-
-
+
Once the sql request checked, the module analyses the column of the
+view, and propose field mapping. For each field, you can decide to
+create an index and set if it will be displayed on the pivot graph as
+a column, a row or a measure.
+
-
Click on the button ‘Create SQL elements’. (this step could
-take a while, if view is materialized)
+
Click on the button ‘Create SQL elements’. (this step could take a
+while, if view is materialized)
If it’s a MATERIALIZED view:
-
a cron task is created to refresh
-the view. You can so define the frequency of the refresh.
+
a cron task is created to refresh the view. You can so define
+the frequency of the refresh.
the size of view (and the indexes is displayed)
-
-
-
+
-
Finally, click on ‘Create UI’, to create new menu, action, graph view and
-search view.
+
Finally, click on ‘Create UI’, to create new menu, action, graph view
+and search view.
@@ -474,11 +465,9 @@ search view.
Go to ‘Dashboards > SQL Reports’
Select the desired report
+
-
-
-
-
+
You can switch to ‘Graph’ or ‘tree’ views as any report.
@@ -488,43 +477,42 @@ search view.
Bugs are tracked on GitHub Issues.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-feedback.
OCA, or the Odoo Community Association, is a nonprofit organization whose
@@ -532,11 +520,9 @@ mission is to support the collaborative development of Odoo features and
promote its widespread use.