Skip to content

Commit 082405b

Browse files
committed
[MIG] sql_request_abstract: Migration to 19.0
1 parent e7d29ce commit 082405b

8 files changed

Lines changed: 85 additions & 75 deletions

File tree

sql_request_abstract/README.rst

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
15
====================
26
SQL Request Abstract
37
====================
@@ -13,44 +17,44 @@ SQL Request Abstract
1317
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1418
:target: https://odoo-community.org/page/development-status
1519
:alt: Beta
16-
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
20+
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
1721
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1822
:alt: License: AGPL-3
1923
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
20-
:target: https://github.com/OCA/reporting-engine/tree/18.0/sql_request_abstract
24+
:target: https://github.com/OCA/reporting-engine/tree/19.0/sql_request_abstract
2125
:alt: OCA/reporting-engine
2226
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/reporting-engine-18-0/reporting-engine-18-0-sql_request_abstract
27+
:target: https://translation.odoo-community.org/projects/reporting-engine-19-0/reporting-engine-19-0-sql_request_abstract
2428
:alt: Translate me on Weblate
2529
.. |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=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=19.0
2731
:alt: Try me on Runboat
2832

2933
|badge1| |badge2| |badge3| |badge4| |badge5|
3034

3135
This module provides an abstract model to manage SQL Select requests on
32-
database. It is not usefull for itself. You can see an exemple of
36+
database. It is not usefull for itself. You can see an example of
3337
implementation in the 'sql_export' module. (same repository).
3438

3539
Implemented features
3640
--------------------
3741

38-
- Add some restrictions in the sql request:
42+
- Add some restrictions in the sql request:
3943

40-
- you can only read datas. No update, deletion or creation are
41-
possible.
42-
- some tables are not allowed, because they could contains clear
43-
password or keys. For the time being ('ir_config_parameter').
44+
- you can only read datas. No update, deletion or creation are
45+
possible.
46+
- some tables are not allowed, because they could contains clear
47+
password or keys. For the time being ('ir_config_parameter').
4448

45-
- The request can be in a 'draft' or a 'SQL Valid' status. To be valid,
46-
the request has to be cleaned, checked and tested. All of this
47-
operations can be disabled in the inherited modules.
49+
- The request can be in a 'draft' or a 'SQL Valid' status. To be valid,
50+
the request has to be cleaned, checked and tested. All of this
51+
operations can be disabled in the inherited modules.
4852

49-
- This module two new groups:
53+
- This module adds two new groups:
5054

51-
- SQL Request / User : Can see all the sql requests by default and
52-
execute them, if they are valid.
53-
- SQL Request / Manager : has full access on sql requests.
55+
- SQL Request / User : Can see all the sql requests by default and
56+
execute them, if they are valid.
57+
- SQL Request / Manager : has full access on sql requests.
5458

5559
**Table of contents**
5660

@@ -103,7 +107,7 @@ Bug Tracker
103107
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
104108
In case of trouble, please check there if your issue has already been reported.
105109
If you spotted it first, help us to smash it by providing a detailed and welcomed
106-
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20sql_request_abstract%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
110+
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20sql_request_abstract%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
107111
108112
Do not contact contributors directly about support or help with technical issues.
109113
@@ -119,18 +123,12 @@ Authors
119123
Contributors
120124
------------
121125
122-
- Florian da Costa <florian.dacosta@akretion.com>
123-
- Sylvain LE GAL (https://twitter.com/legalsylvain)
124-
- Alfadil Tabar (alfadil.tabar@gmail.com)
125-
- Helly kapatel <helly.kapatel@initos.com>
126-
- Nguyen Minh Chien <chien@trobz.com>
127-
- Vo Hong Thien <thienvh@trobz.com>
128-
129-
Other credits
130-
-------------
131-
132-
The migration of this module from 17.0 to 18.0 was financially supported
133-
by Camptocamp.
126+
- Florian da Costa <florian.dacosta@akretion.com>
127+
- Sylvain LE GAL (https://twitter.com/legalsylvain)
128+
- Alfadil Tabar (alfadil.tabar@gmail.com)
129+
- Helly kapatel <helly.kapatel@initos.com>
130+
- Nguyen Minh Chien <chien@trobz.com>
131+
- Vo Hong Thien <thienvh@trobz.com>
134132
135133
Maintainers
136134
-----------
@@ -153,6 +151,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
153151
154152
|maintainer-legalsylvain|
155153
156-
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/18.0/sql_request_abstract>`_ project on GitHub.
154+
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/19.0/sql_request_abstract>`_ project on GitHub.
157155
158156
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

sql_request_abstract/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
{
66
"name": "SQL Request Abstract",
7-
"version": "18.0.1.0.0",
7+
"version": "19.0.1.0.0",
88
"author": "GRAP,Akretion,Odoo Community Association (OCA)",
99
"maintainers": ["legalsylvain"],
1010
"website": "https://github.com/OCA/reporting-engine",

sql_request_abstract/models/sql_request_mixin.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from psycopg2 import ProgrammingError
1313
from psycopg2.sql import SQL
1414

15-
from odoo import _, api, fields, models, tools
15+
from odoo import api, fields, models, tools
1616
from odoo.exceptions import UserError, ValidationError
1717

1818
from ..sql_db import get_external_cursor
@@ -87,7 +87,7 @@ def _default_user_ids(self):
8787
relation=_sql_request_groups_relation,
8888
column1="sql_id",
8989
column2="group_id",
90-
default=_default_group_ids,
90+
default=lambda self: self._default_group_ids(),
9191
)
9292

9393
user_ids = fields.Many2many(
@@ -96,7 +96,7 @@ def _default_user_ids(self):
9696
relation=_sql_request_users_relation,
9797
column1="sql_id",
9898
column2="user_id",
99-
default=_default_user_ids,
99+
default=lambda self: self._default_user_ids(),
100100
)
101101
use_external_database = fields.Boolean(
102102
help=(
@@ -112,7 +112,7 @@ def check_external_config(self):
112112
external_db_name = tools.config.get("external_db_name")
113113
if not external_db_name:
114114
raise ValidationError(
115-
_(
115+
self.env._(
116116
"You can't use an external database as there are no such "
117117
"configuration about this. Please contact "
118118
"your Odoo administrator to solve this issue."
@@ -200,7 +200,9 @@ def _execute_sql_request(
200200
res = False
201201
# Check if the request is in a valid state
202202
if self.state == "draft":
203-
raise UserError(_("It is not allowed to execute a not checked request."))
203+
raise UserError(
204+
self.env._("It is not allowed to execute a not checked request.")
205+
)
204206

205207
# Disable rollback if a creation of a view is asked
206208
if mode in ("view", "materialized_view"):
@@ -222,7 +224,7 @@ def _execute_sql_request(
222224
SQL(query), SQL(view_name)
223225
)
224226
else:
225-
raise UserError(_("Unimplemented mode : '%s'") % mode)
227+
raise UserError(self.env._("Unimplemented mode : '%s'", mode))
226228

227229
query_cr = self._get_cr_for_query()
228230

@@ -280,11 +282,11 @@ def _check_materialized_view_available(self):
280282
minor_version = float(".".join(res[:2]))
281283
if minor_version < 9.3:
282284
raise UserError(
283-
_(
285+
self.env._(
284286
"Materialized View requires PostgreSQL 9.3 or greater but"
285-
" PostgreSQL %s is currently installed."
287+
" PostgreSQL %s is currently installed.",
288+
minor_version,
286289
)
287-
% (minor_version)
288290
)
289291

290292
def _clean_query(self):
@@ -304,8 +306,10 @@ def _check_prohibited_words(self):
304306
is_not_safe = re.search(expr, query)
305307
if is_not_safe:
306308
raise UserError(
307-
_("The query is not allowed because it contains unsafe word '%s'")
308-
% (word)
309+
self.env._(
310+
"The query is not allowed because it contains unsafe word '%s'",
311+
word,
312+
)
309313
)
310314

311315
def _check_execution(self):
@@ -321,7 +325,7 @@ def _check_execution(self):
321325
res = self._hook_executed_request()
322326
except ProgrammingError as e:
323327
logger.exception("Failed query: %s", query)
324-
raise UserError(_("The SQL query is not valid:\n\n %s") % e) from e
328+
raise UserError(self.env._("The SQL query is not valid:\n\n %s", e)) from e
325329
finally:
326330
self._rollback_savepoint(rollback_name, query_cr)
327331
return res

sql_request_abstract/readme/CREDITS.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

sql_request_abstract/readme/DESCRIPTION.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
This module provides an abstract model to manage SQL Select requests on
2-
database. It is not usefull for itself. You can see an exemple of
2+
database. It is not usefull for itself. You can see an example of
33
implementation in the 'sql_export' module. (same repository).
44

55
## Implemented features
@@ -14,7 +14,7 @@ implementation in the 'sql_export' module. (same repository).
1414
the request has to be cleaned, checked and tested. All of this
1515
operations can be disabled in the inherited modules.
1616

17-
- This module two new groups:
17+
- This module adds two new groups:
1818
- SQL Request / User : Can see all the sql requests by default and
1919
execute them, if they are valid.
2020
- SQL Request / Manager : has full access on sql requests.

sql_request_abstract/security/ir_module_category.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@
33
<record model="ir.module.category" id="category_sql_abstract">
44
<field name="name">SQL Request</field>
55
</record>
6+
7+
<record model="res.groups.privilege" id="privilege_sql_request">
8+
<field name="name">SQL Request</field>
9+
<field name="category_id" ref="category_sql_abstract" />
10+
</record>
611
</odoo>

sql_request_abstract/security/res_groups.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
77
<odoo>
88
<record model="res.groups" id="group_sql_request_user">
99
<field name="name">User</field>
10-
<field name="category_id" ref="category_sql_abstract" />
10+
<field name="privilege_id" ref="privilege_sql_request" />
1111
</record>
1212
<record model="res.groups" id="group_sql_request_manager">
1313
<field name="name">Manager</field>
14-
<field name="category_id" ref="category_sql_abstract" />
15-
<field name="users" eval="[(4, ref('base.user_admin'))]" />
16-
<field name="implied_ids" eval="[(4, ref('group_sql_request_user'))]" />
14+
<field name="privilege_id" ref="privilege_sql_request" />
15+
<field name="user_ids" eval="[Command.link(ref('base.user_admin'))]" />
16+
<field
17+
name="implied_ids"
18+
eval="[Command.link(ref('group_sql_request_user'))]"
19+
/>
1720
</record>
1821
</odoo>

0 commit comments

Comments
 (0)