aheficent
7 years ago
committed by
David James
13 changed files with 228 additions and 107 deletions
-
5bi_sql_editor/README.rst
-
1bi_sql_editor/__init__.py
-
5bi_sql_editor/__openerp__.py
-
59bi_sql_editor/demo/bi_sql_view.xml
-
59bi_sql_editor/demo/bi_sql_view_demo.xml
-
18bi_sql_editor/demo/res_groups.xml
-
18bi_sql_editor/demo/res_groups_demo.xml
-
12bi_sql_editor/hooks.py
-
49bi_sql_editor/models/bi_sql_view.py
-
6bi_sql_editor/models/bi_sql_view_field.py
-
3bi_sql_editor/tests/__init__.py
-
75bi_sql_editor/tests/test_bi_sql_view.py
-
3bi_sql_editor/views/view_bi_sql_view.xml
@ -1,3 +1,4 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
|
|
||||
from . import models |
from . import models |
||||
|
from .hooks import uninstall_hook |
@ -1,59 +0,0 @@ |
|||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||
<!-- |
|
||||
Copyright (C) 2014 - Today GRAP (http://www.grap.coop) |
|
||||
@author Sylvain LE GAL (https://twitter.com/legalsylvain) |
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|
||||
--> |
|
||||
|
|
||||
<openerp><data> |
|
||||
|
|
||||
<record id="incorrect_sql_view" model="bi.sql.view"> |
|
||||
<field name="name">Draft Incorrect SQL View</field> |
|
||||
<field name="technical_name">incorrect_view</field> |
|
||||
<field name="query"><![CDATA[ |
|
||||
SELECT * |
|
||||
FROM unexisting_table |
|
||||
ORDER BY unexisting_field |
|
||||
]]> |
|
||||
</field> |
|
||||
</record> |
|
||||
|
|
||||
<record id="partner_sql_view" model="bi.sql.view"> |
|
||||
<field name="name">Partners View</field> |
|
||||
<field name="technical_name">partners_view</field> |
|
||||
<field name="query"><![CDATA[ |
|
||||
SELECT |
|
||||
name as x_name, |
|
||||
street as x_street, |
|
||||
company_id as x_company_id |
|
||||
FROM res_partner |
|
||||
ORDER BY name |
|
||||
]]> |
|
||||
</field> |
|
||||
</record> |
|
||||
|
|
||||
<function model="bi.sql.view" name="button_validate_sql_expression" eval="([ref('partner_sql_view')])"/> |
|
||||
|
|
||||
<record id="module_sql_view" model="bi.sql.view"> |
|
||||
<field name="name">Modules by Authors</field> |
|
||||
<field name="technical_name">modules_view</field> |
|
||||
<field name="is_materialized" eval="0" /> |
|
||||
<field name="query"><![CDATA[ |
|
||||
SELECT |
|
||||
name as x_name, |
|
||||
case |
|
||||
when author ilike '%OpenERP SA%' THEN 'Odoo SA' |
|
||||
when author ilike '%Odoo Community Association (OCA)%' THEN 'OCA' |
|
||||
else 'Undefined Author' END as x_author_type |
|
||||
FROM ir_module_module |
|
||||
]]> |
|
||||
</field> |
|
||||
</record> |
|
||||
|
|
||||
<function model="bi.sql.view" name="button_validate_sql_expression" eval="([ref('module_sql_view')])"/> |
|
||||
|
|
||||
<function model="bi.sql.view" name="button_create_sql_view_and_model" eval="([ref('module_sql_view')])"/> |
|
||||
|
|
||||
<function model="bi.sql.view" name="button_create_ui" eval="([ref('module_sql_view')])"/> |
|
||||
|
|
||||
</data></openerp> |
|
@ -0,0 +1,59 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!-- |
||||
|
Copyright (C) 2014 - Today GRAP (http://www.grap.coop) |
||||
|
@author Sylvain LE GAL (https://twitter.com/legalsylvain) |
||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
--> |
||||
|
|
||||
|
<odoo> |
||||
|
<data noupdate="1"> |
||||
|
|
||||
|
<record id="incorrect_sql_view" model="bi.sql.view"> |
||||
|
<field name="name">Draft Incorrect SQL View</field> |
||||
|
<field name="technical_name">incorrect_view</field> |
||||
|
<field name="query"><![CDATA[ |
||||
|
SELECT * |
||||
|
FROM unexisting_table |
||||
|
ORDER BY unexisting_field |
||||
|
]]> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="partner_sql_view" model="bi.sql.view"> |
||||
|
<field name="name">Partners View</field> |
||||
|
<field name="technical_name">partners_view</field> |
||||
|
<field name="query"><![CDATA[ |
||||
|
SELECT |
||||
|
name as x_name, |
||||
|
street as x_street, |
||||
|
company_id as x_company_id |
||||
|
FROM res_partner |
||||
|
ORDER BY name |
||||
|
]]> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="module_sql_view" model="bi.sql.view"> |
||||
|
<field name="name">Modules by Authors</field> |
||||
|
<field name="technical_name">modules_view</field> |
||||
|
<field name="is_materialized" eval="0" /> |
||||
|
<field name="query"><![CDATA[ |
||||
|
SELECT |
||||
|
name as x_name, |
||||
|
case |
||||
|
when author ilike '%OpenERP SA%' THEN 'Odoo SA' |
||||
|
when author ilike '%Odoo Community Association (OCA)%' THEN 'OCA' |
||||
|
else 'Undefined Author' END as x_author_type |
||||
|
FROM ir_module_module |
||||
|
]]> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<function model="bi.sql.view" name="button_validate_sql_expression" eval="([ref('module_sql_view')])"/> |
||||
|
|
||||
|
<function model="bi.sql.view" name="button_create_sql_view_and_model" eval="([ref('module_sql_view')])"/> |
||||
|
|
||||
|
<function model="bi.sql.view" name="button_create_ui" eval="([ref('module_sql_view')])"/> |
||||
|
|
||||
|
</data> |
||||
|
</odoo> |
@ -1,18 +0,0 @@ |
|||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||
<!-- |
|
||||
Copyright (C) 2014 - Today GRAP (http://www.grap.coop) |
|
||||
@author Sylvain LE GAL (https://twitter.com/legalsylvain) |
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|
||||
--> |
|
||||
|
|
||||
<openerp><data> |
|
||||
|
|
||||
<record id="base.group_no_one" model="res.groups"> |
|
||||
<field name="users" eval="[(4, ref('base.user_root'))]" /> |
|
||||
</record> |
|
||||
|
|
||||
<record id="sql_request_abstract.group_sql_request_user" model="res.groups"> |
|
||||
<field name="users" eval="[(4, ref('base.user_demo'))]" /> |
|
||||
</record> |
|
||||
|
|
||||
</data></openerp> |
|
@ -0,0 +1,18 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!-- |
||||
|
Copyright (C) 2014 - Today GRAP (http://www.grap.coop) |
||||
|
@author Sylvain LE GAL (https://twitter.com/legalsylvain) |
||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
--> |
||||
|
|
||||
|
<odoo> |
||||
|
<data> |
||||
|
<record id="base.group_no_one" model="res.groups"> |
||||
|
<field name="users" eval="[(4, ref('base.user_root'))]" /> |
||||
|
</record> |
||||
|
|
||||
|
<record id="sql_request_abstract.group_sql_request_user" model="res.groups"> |
||||
|
<field name="users" eval="[(4, ref('base.user_demo'))]" /> |
||||
|
</record> |
||||
|
</data> |
||||
|
</odoo> |
@ -0,0 +1,12 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Copyright 2015-2017 Onestein (<http://www.onestein.eu>) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
from openerp import SUPERUSER_ID |
||||
|
from openerp.api import Environment |
||||
|
|
||||
|
|
||||
|
def uninstall_hook(cr, registry): |
||||
|
env = Environment(cr, SUPERUSER_ID, {}) |
||||
|
recs = env['bi.sql.view'].search([]) |
||||
|
for rec in recs: |
||||
|
rec.button_set_draft() |
@ -0,0 +1,3 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
from . import test_bi_sql_view |
@ -0,0 +1,75 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Copyright 2017 Onestein (<http://www.onestein.eu>) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from openerp.tests.common import TransactionCase, at_install, post_install |
||||
|
from openerp.exceptions import AccessError |
||||
|
|
||||
|
|
||||
|
class TestBiSqlViewEditor(TransactionCase): |
||||
|
|
||||
|
def setUp(self): |
||||
|
super(TestBiSqlViewEditor, self).setUp() |
||||
|
self.res_partner = self.env['res.partner'] |
||||
|
self.res_users = self.env['res.users'] |
||||
|
self.bi_sql_view = self.env['bi.sql.view'] |
||||
|
self.group_bi_user = self.env.ref( |
||||
|
'sql_request_abstract.group_sql_request_manager') |
||||
|
self.group_user = self.env.ref( |
||||
|
'base.group_user') |
||||
|
self.view = self.bi_sql_view.create({ |
||||
|
'name': 'Partners View 2', |
||||
|
'is_materialized': False, |
||||
|
'technical_name': 'partners_view_2', |
||||
|
'query': "SELECT name as x_name, street as x_street," |
||||
|
"company_id as x_company_id FROM res_partner " |
||||
|
"ORDER BY name" |
||||
|
}) |
||||
|
self.company = self.env.ref('base.main_company') |
||||
|
# Create bi user |
||||
|
self.bi_user = self._create_user('bi_user', [self.group_bi_user], |
||||
|
self.company) |
||||
|
self.no_bi_user = self._create_user('no_bi_user', [self.group_user], |
||||
|
self.company) |
||||
|
|
||||
|
def _create_user(self, login, groups, company): |
||||
|
"""Create a user.""" |
||||
|
group_ids = [group.id for group in groups] |
||||
|
user = self.res_users.create({ |
||||
|
'name': 'Test BI User', |
||||
|
'login': login, |
||||
|
'password': 'demo', |
||||
|
'email': 'example@yourcompany.com', |
||||
|
'company_id': company.id, |
||||
|
'groups_id': [(6, 0, group_ids)] |
||||
|
}) |
||||
|
return user |
||||
|
|
||||
|
@at_install(False) |
||||
|
@post_install(True) |
||||
|
def test_process_view(self): |
||||
|
view = self.view |
||||
|
self.assertEqual(view.state, 'draft', 'state not draft') |
||||
|
view.button_validate_sql_expression() |
||||
|
self.assertEqual(view.state, 'sql_valid', 'state not sql_valid') |
||||
|
|
||||
|
def test_copy(self): |
||||
|
copy_view = self.view.copy() |
||||
|
self.assertEqual( |
||||
|
copy_view.name, 'Partners View 2 (Copy)', 'Wrong name') |
||||
|
|
||||
|
def test_security(self): |
||||
|
with self.assertRaises(AccessError): |
||||
|
self.bi_sql_view.sudo(self.no_bi_user.id).search( |
||||
|
[('name', '=', 'Partners View 2')]) |
||||
|
bi = self.bi_sql_view.sudo(self.bi_user.id).search( |
||||
|
[('name', '=', 'Partners View 2')]) |
||||
|
self.assertEqual(len(bi), 1, 'Bi user should not have access to ' |
||||
|
'bi %s' % self.view.name) |
||||
|
|
||||
|
def test_unlink(self): |
||||
|
self.assertEqual(self.view.state, 'draft', 'state not draft') |
||||
|
self.view.button_validate_sql_expression() |
||||
|
self.view.unlink() |
||||
|
res = self.bi_sql_view.search([('name', '=', 'Partners View 2')]) |
||||
|
self.assertEqual(len(res), 0, 'View not deleted') |
Write
Preview
Loading…
Cancel
Save
Reference in new issue