diff --git a/polars_db_process/README.rst b/polars_db_process/README.rst index 51ffe4338..8c4cabd6f 100644 --- a/polars_db_process/README.rst +++ b/polars_db_process/README.rst @@ -16,14 +16,14 @@ Polars Database Process .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 -.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github - :target: https://github.com/OCA/reporting-engine/tree/18.0/polars_db_process - :alt: OCA/reporting-engine +.. |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/polars_db_process + :alt: OCA/server-backend .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/reporting-engine-18-0/reporting-engine-18-0-polars_db_process + :target: https://translation.odoo-community.org/projects/server-backend-18-0/server-backend-18-0-polars_db_process :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/reporting-engine&target_branch=18.0 + :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| @@ -52,10 +52,10 @@ For that you need to transform/arrange data to the same way Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. +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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -95,6 +95,6 @@ Current `maintainer `__: |maintainer-bealdav| -This module is part of the `OCA/reporting-engine `_ project on GitHub. +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/polars_db_process/__manifest__.py b/polars_db_process/__manifest__.py index ba7c441d0..46a15cdf2 100644 --- a/polars_db_process/__manifest__.py +++ b/polars_db_process/__manifest__.py @@ -9,7 +9,7 @@ "license": "AGPL-3", "author": "Akretion, Odoo Community Association (OCA)", "development_status": "Alpha", - "website": "https://github.com/OCA/reporting-engine", + "website": "https://github.com/OCA/server-backend", "maintainers": ["bealdav"], "depends": [ "polars_process", diff --git a/polars_db_process/models/db_config.py b/polars_db_process/models/db_config.py index dc2ff46d7..975bddc13 100644 --- a/polars_db_process/models/db_config.py +++ b/polars_db_process/models/db_config.py @@ -28,14 +28,14 @@ def _get_connexion(self): return self.string_connexion.replace("PASSWORD", self.password or "") def test_connexion(self): - res = self._read_sql(self._get_connexion(), "SELECT 1") + res = self._read_sql("SELECT 1") if len(res): # Not invalid in reality raise exceptions.ValidationError(_("Connexion OK !")) - def _read_sql(self, connexion, query): + def _read_sql(self, query): try: - return cx.read_sql(connexion, query, return_type="polars") + return cx.read_sql(self._get_connexion(), query, return_type="polars") except RuntimeError as err: raise exceptions.ValidationError(err) from err except TimeoutError as err: diff --git a/polars_db_process/models/df_source.py b/polars_db_process/models/df_source.py index ea2fe51bd..20644d54a 100644 --- a/polars_db_process/models/df_source.py +++ b/polars_db_process/models/df_source.py @@ -9,8 +9,8 @@ HELP = """Supported files: .xlsx and .sql Sql files may contains a comment on first line to be mapped automatically with dataframe, i.e:\n --- {'model_id': 'product.product', 'db_id': mydb} --- {'code': 'my_delivery_address', 'db_id': mydb} +-- {'model_id': 'product.product', 'db_conf_id': mydb} +-- {'code': 'my_delivery_address', 'db_conf_id': mydb} """ @@ -19,8 +19,9 @@ class DfSource(models.Model): name = fields.Char(help=HELP) query = fields.Char() - # TODO : -> db_config_id - db_id = fields.Many2one(comodel_name="db.config", help="Database") + db_conf_id = fields.Many2one( + comodel_name="db.config", help="Database Configuration" + ) def _file_hook(self, file): "Map sql file with the right Odoo model via dataframe and the right db.config" @@ -39,7 +40,7 @@ def _file_hook(self, file): dataframes = ( self.env["df.source"] .search([]) - .filtered(lambda s: not s.db_id) + .filtered(lambda s: not s.db_conf_id) .mapped("dataframe_id") ) dataframe = self.env["dataframe"].search( @@ -52,9 +53,9 @@ def _file_hook(self, file): # TODO use first vals["dataframe_id"] = dataframe[0].id db_config = self.env["db.config"].search( - [("name", "ilike", metadata.get("db_id"))] + [("name", "ilike", metadata.get("db_conf_id"))] ) - vals["db_id"] = db_config and db_config[0].id or False + vals["db_conf_id"] = db_config and db_config[0].id or False else: df = self.env["dataframe"].create( {"code": model.name, "model_id": model and model[0].id} diff --git a/polars_db_process/static/description/index.html b/polars_db_process/static/description/index.html index bd157bb92..469438868 100644 --- a/polars_db_process/static/description/index.html +++ b/polars_db_process/static/description/index.html @@ -369,7 +369,7 @@

Polars Database Process

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:3fb8a401fe8c3d73e23b477915bbd9ff0b2bcb331711726a4fd5be280ad53d5d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Alpha License: AGPL-3 OCA/reporting-engine Translate me on Weblate Try me on Runboat

+

Alpha License: AGPL-3 OCA/server-backend Translate me on Weblate Try me on Runboat

From a db query, this module allows to transform data in Polars dataframe and process them according to rules in order to:

    @@ -399,10 +399,10 @@

    Polars Database Process

    Bug Tracker

    -

    Bugs are tracked on GitHub Issues. +

    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.

    +feedback.

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

    @@ -433,7 +433,7 @@

    Maintainers

    promote its widespread use.

    Current maintainer:

    bealdav

    -

    This module is part of the OCA/reporting-engine project on GitHub.

    +

    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/polars_db_process/views/df_source.xml b/polars_db_process/views/df_source.xml index 623a48864..c1184fc38 100644 --- a/polars_db_process/views/df_source.xml +++ b/polars_db_process/views/df_source.xml @@ -6,7 +6,7 @@ - + @@ -18,13 +18,16 @@ - + {'accepted_file_extensions': '.xlsx,.sql'} + + query and not db_conf_id + @@ -33,14 +36,14 @@ - + diff --git a/polars_db_process/wizards/df_process.py b/polars_db_process/wizards/df_process.py index 611b4a78e..4483d4f14 100644 --- a/polars_db_process/wizards/df_process.py +++ b/polars_db_process/wizards/df_process.py @@ -1,7 +1,5 @@ from odoo import _, exceptions, models -MODULE = __name__[12 : __name__.index(".", 13)] - class DfProcessWiz(models.TransientModel): _inherit = "df.process.wiz" @@ -13,4 +11,15 @@ def _pre_process(self): return res def _pre_process_sql(self): - raise exceptions.ValidationError(_("to be continued")) + "You may inherit to set your own behavior" + if not self.df_source_id.db_conf_id: + raise exceptions.ValidationError( + _("Missing database configuration in your df source ") + ) + self._process_sql() + + def _process_sql(self): + self.ensure_one() + df = self.df_source_id.db_conf_id._read_sql(self.df_source_id.query) + if self.dataframe_id: + self.env[self.dataframe_id.model_id.model].create(df.to_dicts()) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..278dea77f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +# generated from manifests external_dependencies +connectorx