Browse Source

[MIG][10.0]sql_export v10

pull/1554/head
aheficent 7 years ago
committed by David Beal
parent
commit
929a6f6fab
  1. 13
      sql_export/README.rst
  2. 1
      sql_export/__init__.py
  3. 27
      sql_export/__manifest__.py
  4. 43
      sql_export/__openerp__.py
  5. 4
      sql_export/demo/sql_export.xml
  6. 2
      sql_export/models/__init__.py
  7. 25
      sql_export/models/sql_export.py
  8. 6
      sql_export/security/sql_export_security.xml
  9. 1
      sql_export/tests/__init__.py
  10. 4
      sql_export/tests/test_sql_query.py
  11. 23
      sql_export/views/sql_export_view.xml
  12. 2
      sql_export/wizard/__init__.py
  13. 26
      sql_export/wizard/wizard_file.py
  14. 8
      sql_export/wizard/wizard_file_view.xml

13
sql_export/README.rst

@ -5,14 +5,15 @@ SQL Export
========== ==========
Allow to export data in csv files FROM sql requests. Allow to export data in csv files FROM sql requests.
There are some restrictions in the sql sql request, you can only read datas.
There are some restrictions in the sql query, you can only read datas.
No update, deletion or creation are possible. No update, deletion or creation are possible.
A new menu named Export is created. A new menu named Export is created.
Known issues / Roadmap Known issues / Roadmap
====================== ======================
* Some words are prohibeted and can't be used is the query in anyways, even in a select query :
* Some words are prohibeted and can't be used is the query in anyways, even in
a select query :
* delete * delete
* drop * drop
* insert * insert
@ -28,6 +29,14 @@ See sql_request_abstract module to fix this issue.
since variables features has been introduced. This can be fixed by since variables features has been introduced. This can be fixed by
overloading _prepare_request_check_execution() function. overloading _prepare_request_check_execution() function.
Usage
=====
Dashboards > Sql Export.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/149/10.0
Bug Tracker Bug Tracker
=========== ===========

1
sql_export/__init__.py

@ -1,2 +1,3 @@
# -*- coding: utf-8 -*-
from . import models from . import models
from . import wizard from . import wizard

27
sql_export/__manifest__.py

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2015 Akretion (<http://www.akretion.com>)
# @author: Florian da Costa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'SQL Export',
'version': '10.0.1.0.0',
'author': 'Akretion,Odoo Community Association (OCA)',
'website': 'http://www.akretion.com',
'license': 'AGPL-3',
'category': 'Generic Modules/Others',
'summary': 'Export data in csv file with SQL requests',
'depends': [
'sql_request_abstract',
],
'data': [
'views/sql_export_view.xml',
'wizard/wizard_file_view.xml',
'security/sql_export_security.xml',
'security/ir.model.access.csv',
],
'demo': [
'demo/sql_export.xml',
],
'installable': True,
}

43
sql_export/__openerp__.py

@ -1,43 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2015 Akretion (<http://www.akretion.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'SQL Export',
'version': '9.0.1.0.0',
'author': 'Akretion,Odoo Community Association (OCA)',
'website': 'http://www.akretion.com',
'license': 'AGPL-3',
'category': 'Generic Modules/Others',
'summary': 'Export data in csv file with SQL requests',
'depends': [
'sql_request_abstract',
],
'data': [
'views/sql_export_view.xml',
'wizard/wizard_file_view.xml',
'security/sql_export_security.xml',
'security/ir.model.access.csv',
],
'demo': [
'demo/sql_export.xml',
],
'installable': True,
}

4
sql_export/demo/sql_export.xml

@ -5,7 +5,7 @@ Copyright (C) 2017 - Today: GRAP (http://www.grap.coop)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
--> -->
<openerp><data>
<odoo>
<record id="sql_export_partner" model="sql.export"> <record id="sql_export_partner" model="sql.export">
<field name="name">Export Partners (Demo Data)</field> <field name="name">Export Partners (Demo Data)</field>
@ -14,4 +14,4 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<function model="sql.export" name="button_validate_sql_expression" eval="([ref('sql_export.sql_export_partner')])"/> <function model="sql.export" name="button_validate_sql_expression" eval="([ref('sql_export.sql_export_partner')])"/>
</data></openerp>
</odoo>

2
sql_export/models/__init__.py

@ -1 +1,3 @@
# -*- coding: utf-8 -*-
from . import sql_export from . import sql_export

25
sql_export/models/sql_export.py

@ -1,25 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2015 Akretion (<http://www.akretion.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields, api
# Copyright (C) 2015 Akretion (<http://www.akretion.com>)
# @author: Florian da Costa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, fields, api
class SqlExport(models.Model): class SqlExport(models.Model):

6
sql_export/security/sql_export_security.xml

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<odoo noupdate="1">
<record model="ir.rule" id="sql_export_restric_access_user_or_group"> <record model="ir.rule" id="sql_export_restric_access_user_or_group">
<field name="name" >SQL Export users and groups rules</field> <field name="name" >SQL Export users and groups rules</field>
@ -12,5 +11,4 @@
<field name="domain_force">['|', ('user_ids','=',user.id), ('group_ids','in', [x.id for x in user.groups_id])]</field> <field name="domain_force">['|', ('user_ids','=',user.id), ('group_ids','in', [x.id for x in user.groups_id])]</field>
</record> </record>
</data>
</openerp>
</odoo>

1
sql_export/tests/__init__.py

@ -1,2 +1,3 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from . import test_sql_query from . import test_sql_query

4
sql_export/tests/test_sql_query.py

@ -4,8 +4,8 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import base64 import base64
from openerp.tests.common import TransactionCase
from openerp.exceptions import Warning as UserError
from odoo.tests.common import TransactionCase
from odoo.exceptions import Warning as UserError
class TestExportSqlQuery(TransactionCase): class TestExportSqlQuery(TransactionCase):

23
sql_export/views/sql_export_view.xml

@ -1,23 +1,20 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>
<record id="sql_export_view_form" model="ir.ui.view"> <record id="sql_export_view_form" model="ir.ui.view">
<field name="name">Sql_export_form_view</field> <field name="name">Sql_export_form_view</field>
<field name="model">sql.export</field> <field name="model">sql.export</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="SQL export"> <form string="SQL export">
<sheet>
<header> <header>
<button name="button_validate_sql_expression" type="object" states="draft" <button name="button_validate_sql_expression" type="object" states="draft"
string="Validate SQL Expression" class="oe_highlight"/> string="Validate SQL Expression" class="oe_highlight"/>
<button name="button_set_draft" type="object" states="sql_valid" <button name="button_set_draft" type="object" states="sql_valid"
string="Set to Draft" groups="sql_request_abstract.group_sql_request_manager"/> string="Set to Draft" groups="sql_request_abstract.group_sql_request_manager"/>
<button name="export_sql_query" string="Execute Query" states="sql_valid" type="object" class="oe_highlight" <button name="export_sql_query" string="Execute Query" states="sql_valid" type="object" class="oe_highlight"
icon="gtk-execute"/>
<field name="state" widget="statusbar" />
icon="fa-arrow-right text-success"/>
<field name="state" widget="statusbar"/>
</header> </header>
<sheet>
<group> <group>
<h1> <h1>
<field name="name" nolabel="1" placeholder="Request Name"/> <field name="name" nolabel="1" placeholder="Request Name"/>
@ -30,14 +27,14 @@
<group name="request" string="SQL Request" groups="sql_request_abstract.group_sql_request_user"> <group name="request" string="SQL Request" groups="sql_request_abstract.group_sql_request_user">
<field name="query" nolabel="1" placeholder="select * from res_partner"/> <field name="query" nolabel="1" placeholder="select * from res_partner"/>
</group> </group>
<group string="Parameters" groups="sql_request_abstract.group_sql_request_user">
<group name="parameters" string="Parameters" groups="sql_request_abstract.group_sql_request_user">
<field name="field_ids" nolabel="1"/> <field name="field_ids" nolabel="1"/>
</group> </group>
<group groups="sql_request_abstract.group_sql_request_manager"> <group groups="sql_request_abstract.group_sql_request_manager">
<group string="Allowed Users">
<group string="Allowed Users" name="users_allowed">
<field name="user_ids" nolabel="1"/> <field name="user_ids" nolabel="1"/>
</group> </group>
<group string="Allowed Groups">
<group string="Allowed Groups" name="groups_allowed">
<field name="group_ids" nolabel="1"/> <field name="group_ids" nolabel="1"/>
</group> </group>
@ -55,7 +52,7 @@
<field name="name"/> <field name="name"/>
<field name="state"/> <field name="state"/>
<button name="export_sql_query" string="Execute Query" states="sql_valid" type="object" <button name="export_sql_query" string="Execute Query" states="sql_valid" type="object"
icon="gtk-execute"/>
icon="fa-arrow-right text-success"/>
</tree> </tree>
</field> </field>
</record> </record>
@ -103,6 +100,4 @@
<menuitem id="sql_parameter_menu_view" name="Sql Export Variables" parent="sql_export_menu" action="sql_parameter_tree_action" sequence="5" groups="sql_request_abstract.group_sql_request_manager"/> <menuitem id="sql_parameter_menu_view" name="Sql Export Variables" parent="sql_export_menu" action="sql_parameter_tree_action" sequence="5" groups="sql_request_abstract.group_sql_request_manager"/>
</data>
</openerp>
</odoo>

2
sql_export/wizard/__init__.py

@ -1 +1,3 @@
# -*- coding: utf-8 -*-
from . import wizard_file from . import wizard_file

26
sql_export/wizard/wizard_file.py

@ -1,29 +1,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2015 Akretion (<http://www.akretion.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright (C) 2015 Akretion (<http://www.akretion.com>)
# @author: Florian da Costa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import datetime import datetime
from lxml import etree from lxml import etree
from openerp import models, fields, api, osv
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
from odoo import models, fields, api, osv
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
class SqlFileWizard(models.TransientModel): class SqlFileWizard(models.TransientModel):

8
sql_export/wizard/wizard_file_view.xml

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<openerp>
<odoo>
<data> <data>
<record id="sql_file_wizard_view_form" model="ir.ui.view"> <record id="sql_file_wizard_view_form" model="ir.ui.view">
@ -14,14 +14,14 @@
<field name="file_name" invisible="1"/> <field name="file_name" invisible="1"/>
<footer> <footer>
<button name="export_sql" string="Export" type="object" <button name="export_sql" string="Export" type="object"
icon="gtk-apply" />
icon="fa-download"/>
or or
<button special="cancel" string="Cancel" type="object" <button special="cancel" string="Cancel" type="object"
icon="gtk-cancel" />
icon="fa-times" />
</footer> </footer>
</form> </form>
</field> </field>
</record> </record>
</data> </data>
</openerp>
</odoo>
Loading…
Cancel
Save