You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2011 Daniel Reis
  3. # Copyright 2016 LasLabs Inc.
  4. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  5. import logging
  6. from odoo import api, models
  7. _logger = logging.getLogger(__name__)
  8. try:
  9. from odoo.addons.base_external_dbsource.models import (
  10. base_external_dbsource,
  11. )
  12. CONNECTORS = base_external_dbsource.BaseExternalDbsource.CONNECTORS
  13. try:
  14. import pyodbc
  15. CONNECTORS.append(('pyodbc', 'ODBC'))
  16. except ImportError:
  17. _logger.info('ODBC libraries not available. Please install '
  18. '"unixodbc" and "python-pyodbc" packages.')
  19. except ImportError:
  20. _logger.info('base_external_dbsource Odoo module not found.')
  21. class BaseExternalDbsource(models.Model):
  22. """ It provides logic for connection to a ODBC data source. """
  23. _inherit = "base.external.dbsource"
  24. @api.multi
  25. def connection_close_pyodbc(self, connection):
  26. return connection.close()
  27. @api.multi
  28. def connection_open_pyodbc(self):
  29. return pyodbc.connect(self.conn_string_full)
  30. @api.multi
  31. def execute_pyodbc(self, sqlquery, sqlparams, metadata):
  32. return self._execute_generic(sqlquery, sqlparams, metadata)