Browse Source

FIX sql_export: test and misc

pull/1554/head
David Beal 6 years ago
parent
commit
903662e07a
  1. 6
      sql_export/models/sql_export.py
  2. 2
      sql_export/readme/ROADMAP.rst
  3. 6
      sql_export/tests/test_sql_query.py
  4. 2
      sql_export/wizard/__init__.py
  5. 20
      sql_export/wizard/wizard_file.py

6
sql_export/models/sql_export.py

@ -1,7 +1,7 @@
# Copyright (C) 2015 Akretion (<http://www.akretion.com>) # Copyright (C) 2015 Akretion (<http://www.akretion.com>)
# @author: Florian da Costa # @author: Florian da Costa
# 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).
from odoo import models, fields, api
from odoo import models, fields
class SqlExport(models.Model): class SqlExport(models.Model):
@ -35,18 +35,16 @@ class SqlExport(models.Model):
('koir8_r', 'koir8_r')], string='Encoding', required=True, ('koir8_r', 'koir8_r')], string='Encoding', required=True,
default='utf-8') default='utf-8')
@api.multi
def export_sql_query(self): def export_sql_query(self):
self.ensure_one() self.ensure_one()
wiz = self.env['sql.file.wizard'].create({ wiz = self.env['sql.file.wizard'].create({
'sql_export_id': self.id}) 'sql_export_id': self.id})
return { return {
'view_type': 'form',
'view_mode': 'form', 'view_mode': 'form',
'res_model': 'sql.file.wizard', 'res_model': 'sql.file.wizard',
'res_id': wiz.id, 'res_id': wiz.id,
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
'target': 'new', 'target': 'new',
'context': self._context,
'context': self.env.context,
'nodestroy': True, 'nodestroy': True,
} }

2
sql_export/readme/ROADMAP.rst

@ -14,3 +14,5 @@ See sql_request_abstract module to fix this issue.
* checking SQL request by execution and rollback is disabled in this module * checking SQL request by execution and rollback is disabled in this module
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.
* Move modules sql_request_abstract and sql_export to oca/reporting-engine

6
sql_export/tests/test_sql_query.py

@ -1,13 +1,13 @@
# Copyright (C) 2015 Akretion (<http://www.akretion.com>) # Copyright (C) 2015 Akretion (<http://www.akretion.com>)
# @author: Florian da Costa # @author: Florian da Costa
# 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 odoo.tests.common import TransactionCase
from odoo.tests.common import TransactionCase, post_install
from odoo.exceptions import Warning as UserError from odoo.exceptions import Warning as UserError
@post_install(True)
class TestExportSqlQuery(TransactionCase): class TestExportSqlQuery(TransactionCase):
def setUp(self): def setUp(self):
@ -21,7 +21,7 @@ class TestExportSqlQuery(TransactionCase):
'sql_export_id': self.sql_report_demo.id, 'sql_export_id': self.sql_report_demo.id,
}) })
wizard.export_sql() wizard.export_sql()
export = base64.b64decode(wizard.binary_file)
export = base64.b64decode(wizard.binary_file).decode('utf-8')
self.assertEqual(export.split(';')[0], 'name') self.assertEqual(export.split(';')[0], 'name')
self.assertTrue(len(export.split(';')) > 6) self.assertTrue(len(export.split(';')) > 6)

2
sql_export/wizard/__init__.py

@ -1,3 +1 @@
from . import wizard_file from . import wizard_file

20
sql_export/wizard/wizard_file.py

@ -1,9 +1,8 @@
# Copyright (C) 2015 Akretion (<http://www.akretion.com>) # Copyright (C) 2015 Akretion (<http://www.akretion.com>)
# @author: Florian da Costa # @author: Florian da Costa
# 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 datetime
from datetime import datetime
from lxml import etree from lxml import etree
from odoo import models, fields, api, osv from odoo import models, fields, api, osv
@ -22,23 +21,23 @@ class SqlFileWizard(models.TransientModel):
def fields_view_get(self, view_id=None, view_type='form', def fields_view_get(self, view_id=None, view_type='form',
toolbar=False, submenu=False): toolbar=False, submenu=False):
""" """
Display dinamicaly parameter fields depending on the sql_export.
Display dynamically parameter fields depending on the sql_export.
""" """
res = super(SqlFileWizard, self).fields_view_get( res = super(SqlFileWizard, self).fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar, view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu=submenu) submenu=submenu)
export_obj = self.env['sql.export'] export_obj = self.env['sql.export']
if view_type == 'form': if view_type == 'form':
sql_export = export_obj.browse(self._context.get('active_id'))
sql_export = export_obj.browse(self.env.context.get('active_id'))
if sql_export.field_ids: if sql_export.field_ids:
eview = etree.fromstring(res['arch']) eview = etree.fromstring(res['arch'])
group = etree.Element( group = etree.Element(
'group', name="variables_group", colspan="4") 'group', name="variables_group", colspan="4")
toupdate_fields = [] toupdate_fields = []
for field in sql_export.field_ids: for field in sql_export.field_ids:
kwargs = {'name': "%s" % field.name}
toupdate_fields.append(field.name) toupdate_fields.append(field.name)
view_field = etree.SubElement(group, 'field', **kwargs)
view_field = etree.SubElement(
group, 'field', name=field.name)
osv.orm.setup_modifiers( osv.orm.setup_modifiers(
view_field, self.fields_get(field.name)) view_field, self.fields_get(field.name))
@ -50,24 +49,21 @@ class SqlFileWizard(models.TransientModel):
res['arch'] = etree.tostring(eview, pretty_print=True) res['arch'] = etree.tostring(eview, pretty_print=True)
return res return res
@api.multi
def export_sql(self): def export_sql(self):
self.ensure_one() self.ensure_one()
sql_export = self.sql_export_id sql_export = self.sql_export_id
# Manage Params # Manage Params
variable_dict = {} variable_dict = {}
today = datetime.datetime.now()
today_tz = fields.Datetime.context_timestamp(
sql_export, today)
date = today_tz.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
now_tz = fields.Datetime.context_timestamp(sql_export, datetime.now())
date = now_tz.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
if sql_export.field_ids: if sql_export.field_ids:
for field in sql_export.field_ids: for field in sql_export.field_ids:
variable_dict[field.name] = self[field.name] variable_dict[field.name] = self[field.name]
if "%(company_id)s" in sql_export.query: if "%(company_id)s" in sql_export.query:
variable_dict['company_id'] = self.env.user.company_id.id variable_dict['company_id'] = self.env.user.company_id.id
if "%(user_id)s" in sql_export.query: if "%(user_id)s" in sql_export.query:
variable_dict['user_id'] = self._uid
variable_dict['user_id'] = self.env.uid
# Execute Request # Execute Request
res = sql_export._execute_sql_request( res = sql_export._execute_sql_request(

Loading…
Cancel
Save