Skip to content

Commit fb97765

Browse files
committed
[MIG] bi_sql_editor: Migration to 18.0
1 parent 067db7a commit fb97765

File tree

9 files changed

+95
-94
lines changed

9 files changed

+95
-94
lines changed

bi_sql_editor/README.rst

+18-10
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ BI SQL Editor
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
20-
:target: https://github.com/OCA/reporting-engine/tree/17.0/bi_sql_editor
20+
:target: https://github.com/OCA/reporting-engine/tree/18.0/bi_sql_editor
2121
:alt: OCA/reporting-engine
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/reporting-engine-17-0/reporting-engine-17-0-bi_sql_editor
23+
:target: https://translation.odoo-community.org/projects/reporting-engine-18-0/reporting-engine-18-0-bi_sql_editor
2424
:alt: Translate me on Weblate
2525
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=17.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=18.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -126,10 +126,10 @@ to make reporting depending on the current companies of the user.
126126
- Finally, click on 'Create UI', to create new menu, action, graph view
127127
and search view.
128128

129-
.. |image1| image:: https://raw.githubusercontent.com/OCA/reporting-engine/17.0/bi_sql_editor/static/description/01_sql_request.png
130-
.. |image2| image:: https://raw.githubusercontent.com/OCA/reporting-engine/17.0/bi_sql_editor/static/description/02_security_access.png
131-
.. |image3| image:: https://raw.githubusercontent.com/OCA/reporting-engine/17.0/bi_sql_editor/static/description/03_field_mapping.png
132-
.. |image4| image:: https://raw.githubusercontent.com/OCA/reporting-engine/17.0/bi_sql_editor/static/description/04_materialized_view_setting.png
129+
.. |image1| image:: https://raw.githubusercontent.com/OCA/reporting-engine/18.0/bi_sql_editor/static/description/01_sql_request.png
130+
.. |image2| image:: https://raw.githubusercontent.com/OCA/reporting-engine/18.0/bi_sql_editor/static/description/02_security_access.png
131+
.. |image3| image:: https://raw.githubusercontent.com/OCA/reporting-engine/18.0/bi_sql_editor/static/description/03_field_mapping.png
132+
.. |image4| image:: https://raw.githubusercontent.com/OCA/reporting-engine/18.0/bi_sql_editor/static/description/04_materialized_view_setting.png
133133

134134
Usage
135135
=====
@@ -145,15 +145,15 @@ To use this module, you need to:
145145

146146
- You can switch to 'Graph' or 'tree' views as any report.
147147

148-
.. |usage-image1| image:: https://raw.githubusercontent.com/OCA/reporting-engine/17.0/bi_sql_editor/static/description/05_reporting_pivot.png
148+
.. |usage-image1| image:: https://raw.githubusercontent.com/OCA/reporting-engine/18.0/bi_sql_editor/static/description/05_reporting_pivot.png
149149

150150
Bug Tracker
151151
===========
152152

153153
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
154154
In case of trouble, please check there if your issue has already been reported.
155155
If you spotted it first, help us to smash it by providing a detailed and welcomed
156-
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20bi_sql_editor%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
156+
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20bi_sql_editor%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
157157

158158
Do not contact contributors directly about support or help with technical issues.
159159

@@ -176,6 +176,8 @@ Contributors
176176

177177
- Guillem Casassas guillem.casassas@forgeflow.com
178178

179+
- Thien Vo thienvh@trobz.com
180+
179181
- This module is highly inspired by the work of
180182

181183
- Onestein: (http://www.onestein.nl/) Module:
@@ -189,6 +191,12 @@ Contributors
189191
grap/odoo-addons-misc/pos_sale_reporting link:
190192
https://github.com/grap/odoo-addons-misc/tree/7.0/pos_sale_reporting
191193

194+
Other credits
195+
-------------
196+
197+
The migration of this module from 17.0 to 18.0 was financially supported
198+
by Camptocamp.
199+
192200
Maintainers
193201
-----------
194202

@@ -210,6 +218,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
210218

211219
|maintainer-legalsylvain|
212220

213-
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/17.0/bi_sql_editor>`_ project on GitHub.
221+
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/18.0/bi_sql_editor>`_ project on GitHub.
214222

215223
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

bi_sql_editor/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"name": "BI SQL Editor",
77
"summary": "BI Views builder, based on Materialized or Normal SQL Views",
8-
"version": "17.0.1.1.0",
8+
"version": "18.0.1.0.0",
99
"license": "AGPL-3",
1010
"category": "Reporting",
1111
"author": "GRAP,Odoo Community Association (OCA)",

bi_sql_editor/models/bi_sql_view.py

+32-53
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from odoo import SUPERUSER_ID, _, api, fields, models
1111
from odoo.exceptions import UserError, ValidationError
12-
from odoo.tools import sql, table_columns
12+
from odoo.tools import sql
1313
from odoo.tools.safe_eval import safe_eval
1414

1515
_logger = logging.getLogger(__name__)
@@ -44,14 +44,12 @@ class BiSQLView(models.Model):
4444

4545
view_name = fields.Char(
4646
compute="_compute_view_name",
47-
readonly=True,
4847
store=True,
4948
help="Full name of the SQL view",
5049
)
5150

5251
model_name = fields.Char(
5352
compute="_compute_model_name",
54-
readonly=True,
5553
store=True,
5654
help="Full Qualified Name of the transient model that will" " be created.",
5755
)
@@ -65,16 +63,15 @@ class BiSQLView(models.Model):
6563

6664
size = fields.Char(
6765
string="Database Size",
68-
readonly=True,
6966
help="Size of the materialized view and its indexes",
7067
)
7168

7269
state = fields.Selection(selection_add=_STATE_SQL_EDITOR)
7370

7471
view_order = fields.Char(
7572
required=True,
76-
default="pivot,graph,tree",
77-
help="Comma-separated text. Possible values:" ' "graph", "pivot" or "tree"',
73+
default="pivot,graph,list",
74+
help="Comma-separated text. Possible values:" ' "graph", "pivot" or "list"',
7875
)
7976

8077
query = fields.Text(
@@ -111,9 +108,7 @@ class BiSQLView(models.Model):
111108
inverse_name="bi_sql_view_id",
112109
)
113110

114-
model_id = fields.Many2one(
115-
string="Odoo Model", comodel_name="ir.model", readonly=True
116-
)
111+
model_id = fields.Many2one(string="Odoo Model", comodel_name="ir.model")
117112
# UI related fields
118113
# 1. Editable fields, which can be set by the user (optional) before
119114
# creating the UI elements
@@ -133,39 +128,30 @@ def _default_parent_menu_id(self):
133128
)
134129

135130
# 2. Readonly fields, non editable by the user
136-
tree_view_id = fields.Many2one(
137-
string="Odoo Tree View", comodel_name="ir.ui.view", readonly=True
138-
)
131+
tree_view_id = fields.Many2one(string="Odoo List View", comodel_name="ir.ui.view")
139132

140-
graph_view_id = fields.Many2one(
141-
string="Odoo Graph View", comodel_name="ir.ui.view", readonly=True
142-
)
133+
graph_view_id = fields.Many2one(string="Odoo Graph View", comodel_name="ir.ui.view")
143134

144-
pivot_view_id = fields.Many2one(
145-
string="Odoo Pivot View", comodel_name="ir.ui.view", readonly=True
146-
)
135+
pivot_view_id = fields.Many2one(string="Odoo Pivot View", comodel_name="ir.ui.view")
147136

148137
search_view_id = fields.Many2one(
149-
string="Odoo Search View", comodel_name="ir.ui.view", readonly=True
138+
string="Odoo Search View", comodel_name="ir.ui.view"
150139
)
151140

152141
action_id = fields.Many2one(
153-
string="Odoo Action", comodel_name="ir.actions.act_window", readonly=True
142+
string="Odoo Action", comodel_name="ir.actions.act_window"
154143
)
155144

156-
menu_id = fields.Many2one(
157-
string="Odoo Menu", comodel_name="ir.ui.menu", readonly=True
158-
)
145+
menu_id = fields.Many2one(string="Odoo Menu", comodel_name="ir.ui.menu")
159146

160147
cron_id = fields.Many2one(
161148
string="Odoo Cron",
162149
comodel_name="ir.cron",
163-
readonly=True,
164150
help="Cron Task that will refresh the materialized view",
165151
ondelete="cascade",
166152
)
167153

168-
rule_id = fields.Many2one(string="Odoo Rule", comodel_name="ir.rule", readonly=True)
154+
rule_id = fields.Many2one(string="Odoo Rule", comodel_name="ir.rule")
169155

170156
sequence = fields.Integer(string="sequence")
171157

@@ -183,9 +169,9 @@ def _check_view_order(self):
183169
for rec in self:
184170
if rec.view_order:
185171
for vtype in rec.view_order.split(","):
186-
if vtype not in ("graph", "pivot", "tree"):
172+
if vtype not in ("graph", "pivot", "list"):
187173
raise UserError(
188-
_("Only graph, pivot or tree views are supported")
174+
_("Only graph, pivot or list views are supported")
189175
)
190176

191177
# Compute Section
@@ -244,15 +230,15 @@ def write(self, vals):
244230
rec.menu_id.sequence = rec.sequence
245231
return res
246232

247-
def unlink(self):
233+
@api.ondelete(at_uninstall=False)
234+
def _check_unlink_constraints(self):
248235
if any(view.state not in ("draft", "sql_valid") for view in self):
249236
raise UserError(
250237
_(
251-
"You can only unlink draft views."
238+
"You can only unlink draft views. "
252239
"If you want to delete them, first set them to draft."
253240
)
254241
)
255-
return super().unlink()
256242

257243
def copy(self, default=None):
258244
self.ensure_one()
@@ -395,8 +381,7 @@ def _prepare_cron(self):
395381
.search([("model", "=", self._name)], limit=1)
396382
.id,
397383
"state": "code",
398-
"code": "model._refresh_materialized_view_cron(%s)" % self.ids,
399-
"numbercall": -1,
384+
"code": f"model._refresh_materialized_view_cron({self.ids})",
400385
"interval_number": 1,
401386
"interval_type": "days",
402387
"nextcall": now + timedelta(days=1),
@@ -416,11 +401,11 @@ def _prepare_tree_view(self):
416401
self.ensure_one()
417402
return {
418403
"name": self.name,
419-
"type": "tree",
404+
"type": "list",
420405
"model": self.model_id.model,
421406
"arch": """<?xml version="1.0"?>"""
422-
"""<tree name="Analysis">{}"""
423-
"""</tree>""".format(
407+
"""<list name="Analysis">{}"""
408+
"""</list>""".format(
424409
"".join([x._prepare_tree_field() for x in self.bi_sql_view_field_ids])
425410
),
426411
}
@@ -477,7 +462,7 @@ def _prepare_action(self):
477462
self.ensure_one()
478463
view_mode = self.view_order
479464
first_view = view_mode.split(",")[0]
480-
if first_view == "tree":
465+
if first_view == "list":
481466
view_id = self.tree_view_id.id
482467
elif first_view == "pivot":
483468
view_id = self.pivot_view_id.id
@@ -510,13 +495,13 @@ def _prepare_menu(self):
510495
return {
511496
"name": self.name,
512497
"parent_id": self.parent_menu_id.id,
513-
"action": "ir.actions.act_window,%s" % self.action_id.id,
498+
"action": f"ir.actions.act_window,{self.action_id.id}",
514499
"sequence": self.sequence,
515500
}
516501

517502
# Custom Section
518503
def _log_execute(self, req):
519-
_logger.info("Executing SQL Request %s ..." % req)
504+
_logger.info(f"Executing SQL Request {req} ...")
520505
self.env.cr.execute(req)
521506

522507
def _drop_view(self):
@@ -562,7 +547,7 @@ def _create_model_and_fields(self):
562547
sql_view.rule_id = self.env["ir.rule"].create(self._prepare_rule()).id
563548
# Drop table, created by the ORM
564549
if sql.table_exists(self._cr, sql_view.view_name):
565-
req = "DROP TABLE %s" % sql_view.view_name
550+
req = f"DROP TABLE {sql_view.view_name}"
566551
self._log_execute(req)
567552

568553
def _create_model_access(self):
@@ -585,18 +570,15 @@ def _drop_model_and_fields(self):
585570

586571
def _hook_executed_request(self):
587572
self.ensure_one()
588-
req = (
589-
"""
573+
req = f"""
590574
SELECT attnum,
591575
attname AS column,
592576
format_type(atttypid, atttypmod) AS type
593577
FROM pg_attribute
594-
WHERE attrelid = '%s'::regclass
578+
WHERE attrelid = '{self.view_name}'::regclass
595579
AND NOT attisdropped
596580
AND attnum > 0
597581
ORDER BY attnum;"""
598-
% self.view_name
599-
)
600582
self._log_execute(req)
601583
return self.env.cr.fetchall()
602584

@@ -606,8 +588,7 @@ def _prepare_request_check_execution(self):
606588

607589
def _prepare_request_for_execution(self):
608590
self.ensure_one()
609-
query = (
610-
"""
591+
query = f"""
611592
SELECT
612593
CAST(row_number() OVER () as integer) AS id,
613594
CAST(Null as timestamp without time zone) as create_date,
@@ -616,10 +597,8 @@ def _prepare_request_for_execution(self):
616597
CAST(Null as integer) as write_uid,
617598
my_query.*
618599
FROM
619-
(%s) as my_query
600+
({self.query}) as my_query
620601
"""
621-
% self.query
622-
)
623602
return f"CREATE {self.materialized_text} VIEW {self.view_name} AS ({query});"
624603

625604
def _check_execution(self):
@@ -689,9 +668,9 @@ def _refresh_materialized_view(self):
689668

690669
def _refresh_size(self):
691670
for sql_view in self:
692-
req = "SELECT pg_size_pretty(pg_total_relation_size('%s'));" % (
693-
sql_view.view_name
694-
)
671+
req = f"""SELECT pg_size_pretty(pg_total_relation_size(
672+
'{sql_view.view_name}'
673+
));"""
695674
self._log_execute(req)
696675
sql_view.size = self.env.cr.fetchone()[0]
697676

@@ -700,7 +679,7 @@ def check_manual_fields(self, model):
700679
# early on install / startup - particularly problematic during upgrade
701680
if model._name.startswith(
702681
self._model_prefix
703-
) and "group_operator" in table_columns(self.env.cr, "bi_sql_view_field"):
682+
) and "group_operator" in sql.table_columns(self.env.cr, "bi_sql_view_field"):
704683
# Use SQL instead of ORM, as ORM might not be fully initialised -
705684
# we have no control over the order that fields are defined!
706685
# We are not concerned about user security rules.

bi_sql_editor/models/bi_sql_view_field.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,8 @@ def _check_index_materialized(self):
149149
# Compute Section
150150
def _compute_index_name(self):
151151
for sql_field in self:
152-
sql_field.index_name = "{}_{}".format(
153-
sql_field.bi_sql_view_id.view_name,
154-
sql_field.name,
152+
sql_field.index_name = (
153+
f"{sql_field.bi_sql_view_id.view_name}_{sql_field.name}"
155154
)
156155

157156
# Overload Section
@@ -209,8 +208,8 @@ def _model_mapping(self):
209208
field name. Sample :
210209
{'account_id': 'account.account'; 'product_id': 'product.product'}
211210
"""
212-
relation_fields = self.env["ir.model.fields"].search(
213-
[("ttype", "=", "many2one")]
211+
relation_fields = (
212+
self.env["ir.model.fields"].sudo().search([("ttype", "=", "many2one")])
214213
)
215214
res = {}
216215
keys_to_pop = []

bi_sql_editor/readme/CONTRIBUTORS.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
- Guillem Casassas <guillem.casassas@forgeflow.com>
88

9+
- Thien Vo <thienvh@trobz.com>
10+
911
- This module is highly inspired by the work of
1012
- Onestein: (<http://www.onestein.nl/>) Module:
1113
OCA/server-tools/bi_view_editor. Link:

bi_sql_editor/readme/CREDITS.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp.

0 commit comments

Comments
 (0)