diff --git a/base_external_dbsource_sap_hana/README.rst b/base_external_dbsource_sap_hana/README.rst new file mode 100644 index 000000000..3f50213e3 --- /dev/null +++ b/base_external_dbsource_sap_hana/README.rst @@ -0,0 +1,107 @@ +===================================== +External Database Source - SAP - Hana +===================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b85a80a6fdb648c130cc6fdce284d503c8bc94a3878ddc2c51dc24f1d0764481 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github + :target: https://github.com/OCA/server-backend/tree/18.0/base_external_dbsource_sap_hana + :alt: OCA/server-backend +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-backend-18-0/server-backend-18-0-base_external_dbsource_sap_hana + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/server-backend&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends ``base_external_dbsource``, allowing you to connect +to foreign SAP HANA databases using SQLAlchemy. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +To install this module, you need to: + +- Install ``sqlalchemy_hana`` and ``hdbcli`` python libraries + +Configuration +============= + +To configure this module, you need to: + +1. Database sources can be configured in Settings > Technical > Database + Structure > Database sources. + +Usage +===== + +To use this module: + +- Go to Settings > Technical > Database Structure > Database Sources +- Click on Create to enter the following information: +- Datasource name?? +- Pasword +- Connector: Choose the database to which you want to connect +- Connection string: Specify how to connect to database + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__: + + - Carlos Dauden + - Sergio Teruel + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/server-backend `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_external_dbsource_sap_hana/__init__.py b/base_external_dbsource_sap_hana/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/base_external_dbsource_sap_hana/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_external_dbsource_sap_hana/__manifest__.py b/base_external_dbsource_sap_hana/__manifest__.py new file mode 100644 index 000000000..9f25035db --- /dev/null +++ b/base_external_dbsource_sap_hana/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2022 Tecnativa - Sergio Teruel +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +{ + "name": "External Database Source - SAP - Hana", + "version": "18.0.1.0.0", + "category": "Tools", + "author": "Tecnativa, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/server-backend", + "license": "LGPL-3", + "depends": ["base_external_dbsource"], + "external_dependencies": {"python": ["sqlalchemy", "sqlalchemy-hana", "hdbcli"]}, + "demo": ["demo/base_external_dbsource.xml"], + "installable": True, +} diff --git a/base_external_dbsource_sap_hana/demo/base_external_dbsource.xml b/base_external_dbsource_sap_hana/demo/base_external_dbsource.xml new file mode 100644 index 000000000..23fc1c5a8 --- /dev/null +++ b/base_external_dbsource_sap_hana/demo/base_external_dbsource.xml @@ -0,0 +1,9 @@ + + + + SAP Hana Demo + hana://username:password@example.de:30015 + password + sap_hana + + diff --git a/base_external_dbsource_sap_hana/i18n/base_external_dbsource_sap_hana.pot b/base_external_dbsource_sap_hana/i18n/base_external_dbsource_sap_hana.pot new file mode 100644 index 000000000..1b9695847 --- /dev/null +++ b/base_external_dbsource_sap_hana/i18n/base_external_dbsource_sap_hana.pot @@ -0,0 +1,19 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_external_dbsource_sap_hana +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_external_dbsource_sap_hana +#: model:ir.model,name:base_external_dbsource_sap_hana.model_base_external_dbsource +msgid "External Database Sources" +msgstr "" diff --git a/base_external_dbsource_sap_hana/i18n/es.po b/base_external_dbsource_sap_hana/i18n/es.po new file mode 100644 index 000000000..6b771afd1 --- /dev/null +++ b/base_external_dbsource_sap_hana/i18n/es.po @@ -0,0 +1,22 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_external_dbsource_sap_hana +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-10-09 07:49+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: base_external_dbsource_sap_hana +#: model:ir.model,name:base_external_dbsource_sap_hana.model_base_external_dbsource +msgid "External Database Sources" +msgstr "Fuentes de bases de datos externas" diff --git a/base_external_dbsource_sap_hana/i18n/gl.po b/base_external_dbsource_sap_hana/i18n/gl.po new file mode 100644 index 000000000..1077cbb91 --- /dev/null +++ b/base_external_dbsource_sap_hana/i18n/gl.po @@ -0,0 +1,22 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_external_dbsource_sap_hana +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2026-05-23 07:54+0000\n" +"Last-Translator: Pablo Castelo \n" +"Language-Team: none\n" +"Language: gl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.15.2\n" + +#. module: base_external_dbsource_sap_hana +#: model:ir.model,name:base_external_dbsource_sap_hana.model_base_external_dbsource +msgid "External Database Sources" +msgstr "Fuentes de bases de datos externas" diff --git a/base_external_dbsource_sap_hana/models/__init__.py b/base_external_dbsource_sap_hana/models/__init__.py new file mode 100644 index 000000000..91032fcb6 --- /dev/null +++ b/base_external_dbsource_sap_hana/models/__init__.py @@ -0,0 +1 @@ +from . import base_external_dbsource diff --git a/base_external_dbsource_sap_hana/models/base_external_dbsource.py b/base_external_dbsource_sap_hana/models/base_external_dbsource.py new file mode 100644 index 000000000..5e6f32697 --- /dev/null +++ b/base_external_dbsource_sap_hana/models/base_external_dbsource.py @@ -0,0 +1,38 @@ +# Copyright 2022 Tecnativa - Sergio Teruel +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + + +import sqlalchemy + +from odoo import fields, models + + +class BaseExternalDbsource(models.Model): + """It provides logic for connection to a SAP Hana data source.""" + + _inherit = "base.external.dbsource" + + connector = fields.Selection( + selection_add=[("sap_hana", "SAP-Hana")], + ondelete={"sap_hana": "cascade"}, + ) + + def connection_close_sap_hana(self, connection): + return connection.close() + + def connection_open_sap_hana(self): + return sqlalchemy.create_engine(self.conn_string_full).connect() + + def execute_sap_hana(self, sqlquery, sqlparams, metadata): + # FIXME: Duplicated method in modules to be consolidated in base + rows, cols = list(), list() + for record in self: + with record.connection_open() as connection: + if sqlparams is None: + cur = connection.execute(sqlquery) + else: + cur = connection.execute(sqlquery, sqlparams) + if metadata: + cols = list(cur.keys()) + rows = [r for r in cur] + return rows, cols diff --git a/base_external_dbsource_sap_hana/pyproject.toml b/base_external_dbsource_sap_hana/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/base_external_dbsource_sap_hana/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/base_external_dbsource_sap_hana/readme/CONFIGURE.md b/base_external_dbsource_sap_hana/readme/CONFIGURE.md new file mode 100644 index 000000000..9a93e6daf --- /dev/null +++ b/base_external_dbsource_sap_hana/readme/CONFIGURE.md @@ -0,0 +1,4 @@ +To configure this module, you need to: + +1. Database sources can be configured in Settings \> Technical \> + Database Structure \> Database sources. diff --git a/base_external_dbsource_sap_hana/readme/CONTRIBUTORS.md b/base_external_dbsource_sap_hana/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..565414939 --- /dev/null +++ b/base_external_dbsource_sap_hana/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Tecnativa](https://www.tecnativa.com/): + - Carlos Dauden + - Sergio Teruel diff --git a/base_external_dbsource_sap_hana/readme/DESCRIPTION.md b/base_external_dbsource_sap_hana/readme/DESCRIPTION.md new file mode 100644 index 000000000..9f33df837 --- /dev/null +++ b/base_external_dbsource_sap_hana/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module extends `base_external_dbsource`, allowing you to connect to +foreign SAP HANA databases using SQLAlchemy. diff --git a/base_external_dbsource_sap_hana/readme/INSTALL.md b/base_external_dbsource_sap_hana/readme/INSTALL.md new file mode 100644 index 000000000..8163d85a8 --- /dev/null +++ b/base_external_dbsource_sap_hana/readme/INSTALL.md @@ -0,0 +1,3 @@ +To install this module, you need to: + +- Install `sqlalchemy_hana` and `hdbcli` python libraries diff --git a/base_external_dbsource_sap_hana/readme/USAGE.md b/base_external_dbsource_sap_hana/readme/USAGE.md new file mode 100644 index 000000000..3d2d712bf --- /dev/null +++ b/base_external_dbsource_sap_hana/readme/USAGE.md @@ -0,0 +1,8 @@ +To use this module: + +- Go to Settings \> Technical \> Database Structure \> Database Sources +- Click on Create to enter the following information: +- Datasource name?? +- Pasword +- Connector: Choose the database to which you want to connect +- Connection string: Specify how to connect to database diff --git a/base_external_dbsource_sap_hana/static/description/icon.png b/base_external_dbsource_sap_hana/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/base_external_dbsource_sap_hana/static/description/icon.png differ diff --git a/base_external_dbsource_sap_hana/static/description/index.html b/base_external_dbsource_sap_hana/static/description/index.html new file mode 100644 index 000000000..2830e831c --- /dev/null +++ b/base_external_dbsource_sap_hana/static/description/index.html @@ -0,0 +1,458 @@ + + + + + +External Database Source - SAP - Hana + + + +
+

External Database Source - SAP - Hana

+ + +

Beta License: LGPL-3 OCA/server-backend Translate me on Weblate Try me on Runboat

+

This module extends base_external_dbsource, allowing you to connect +to foreign SAP HANA databases using SQLAlchemy.

+

Table of contents

+ +
+

Installation

+

To install this module, you need to:

+
    +
  • Install sqlalchemy_hana and hdbcli python libraries
  • +
+
+
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Database sources can be configured in Settings > Technical > Database +Structure > Database sources.
  2. +
+
+
+

Usage

+

To use this module:

+
    +
  • Go to Settings > Technical > Database Structure > Database Sources
  • +
  • Click on Create to enter the following information:
  • +
  • Datasource name??
  • +
  • Pasword
  • +
  • Connector: Choose the database to which you want to connect
  • +
  • Connection string: Specify how to connect to database
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Carlos Dauden
    • +
    • Sergio Teruel
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/server-backend project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/base_external_dbsource_sap_hana/tests/__init__.py b/base_external_dbsource_sap_hana/tests/__init__.py new file mode 100644 index 000000000..c48ef497a --- /dev/null +++ b/base_external_dbsource_sap_hana/tests/__init__.py @@ -0,0 +1 @@ +from . import test_base_external_dbsource_sap_hana diff --git a/base_external_dbsource_sap_hana/tests/test_base_external_dbsource_sap_hana.py b/base_external_dbsource_sap_hana/tests/test_base_external_dbsource_sap_hana.py new file mode 100644 index 000000000..0b1a407c3 --- /dev/null +++ b/base_external_dbsource_sap_hana/tests/test_base_external_dbsource_sap_hana.py @@ -0,0 +1,57 @@ +# Copyright 2022 Tecnativa - Sergio Teruel +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from unittest import mock + +from odoo.addons.base.tests.common import BaseCommon + +ADAPTER = "odoo.addons.base_external_dbsource_sap_hana.models.base_external_dbsource.SAPhanaDB" # noqa: E501 + + +class TestBaseExternalDbsource(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.dbsource = cls.env.ref("base_external_dbsource_sap_hana.demo_sap_hana") + + def _test_adapter_method( + self, + method_name, + side_effect=None, + return_value=None, + create=False, + args=None, + kwargs=None, + ): + if args is None: + args = [] + if kwargs is None: + kwargs = {} + adapter = f"{method_name}_sap_hana" + with mock.patch.object(type(self.dbsource), adapter, create=create) as adapter: + if side_effect is not None: + adapter.side_effect = side_effect + elif return_value is not None: + adapter.return_value = return_value + res = getattr(self.dbsource, method_name)(*args, **kwargs) + return res, adapter + + def test_connection_close_sap_hana(self): + """It should close the connection""" + args = [mock.MagicMock()] + res, adapter = self._test_adapter_method("connection_close", args=args) + adapter.assert_called_once_with(args[0]) + + def test_connection_open_sap_hana(self): + """It should call SQLAlchemy open""" + with mock.patch.object(type(self.dbsource), "connection_open") as connection: + res = self.dbsource.conn_open() + self.assertEqual(res, connection().__enter__()) + + def test_excecute_sap_hana(self): + """It should pass args to SQLAlchemy execute""" + expect = "sqlquery", "sqlparams", "metadata" + with mock.patch.object(type(self.dbsource), "execute_sap_hana") as execute: + execute.return_value = "rows", "cols" + self.dbsource.execute(*expect) + execute.assert_called_once_with(*expect) diff --git a/requirements.txt b/requirements.txt index b9eb3d222..cee5f2251 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,9 @@ # generated from manifests external_dependencies +hdbcli mysqlclient pymssql<=2.2.5 ; python_version <= '3.10' pymssql<=2.2.8 ; python_version < '3.12' pymssql<=2.3.7 ; python_version >= '3.12' sqlalchemy +sqlalchemy-hana vobject