Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Oct 29, 2024
1 parent 25f4f20 commit bd39a80
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 31 deletions.
16 changes: 8 additions & 8 deletions polars_db_process/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -52,10 +52,10 @@ For that you need to transform/arrange data to the same way
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-backend/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 <https://github.com/OCA/reporting-engine/issues/new?body=module:%20polars_db_process%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/server-backend/issues/new?body=module:%20polars_db_process%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand Down Expand Up @@ -95,6 +95,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-bealdav|

This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/18.0/polars_db_process>`_ project on GitHub.
This module is part of the `OCA/server-backend <https://github.com/OCA/server-backend/tree/18.0/polars_db_process>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion polars_db_process/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions polars_db_process/models/db_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 8 additions & 7 deletions polars_db_process/models/df_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
"""


Expand All @@ -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"
Expand All @@ -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(
Expand All @@ -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}
Expand Down
8 changes: 4 additions & 4 deletions polars_db_process/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Polars Database Process</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:3fb8a401fe8c3d73e23b477915bbd9ff0b2bcb331711726a4fd5be280ad53d5d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/reporting-engine/tree/18.0/polars_db_process"><img alt="OCA/reporting-engine" src="https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/reporting-engine-18-0/reporting-engine-18-0-polars_db_process"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-backend/tree/18.0/polars_db_process"><img alt="OCA/server-backend" src="https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-backend-18-0/server-backend-18-0-polars_db_process"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-backend&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>From a db query, this module allows to transform data in Polars
dataframe and process them according to rules in order to:</p>
<ul class="simple">
Expand Down Expand Up @@ -399,10 +399,10 @@ <h1 class="title">Polars Database Process</h1>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/reporting-engine/issues">GitHub Issues</a>.
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-backend/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/reporting-engine/issues/new?body=module:%20polars_db_process%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/server-backend/issues/new?body=module:%20polars_db_process%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -433,7 +433,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/bealdav"><img alt="bealdav" src="https://github.com/bealdav.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/18.0/polars_db_process">OCA/reporting-engine</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-backend/tree/18.0/polars_db_process">OCA/server-backend</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
13 changes: 8 additions & 5 deletions polars_db_process/views/df_source.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<xpath expr="//group[1]" position="after">
<separator />
<group>
<field name="db_id" invisible="template" />
<field name="db_conf_id" invisible="template" />
<field name="query" widget="code" invisible="template" />
</group>
</xpath>
Expand All @@ -18,13 +18,16 @@
<field name="inherit_id" ref="polars_process.df_source_list" />
<field name="arch" type="xml">
<xpath expr="//list/field[last()]" position="after">
<field name="db_id" />
<field name="db_conf_id" />
</xpath>
<xpath expr="//list/field[@name='template']" position="attributes">
<attribute
name="options"
>{'accepted_file_extensions': '.xlsx,.sql'}</attribute>
</xpath>
<xpath expr="//list/button[@name='start']" position="attributes">
<attribute name="invisible">query and not db_conf_id</attribute>
</xpath>
</field>
</record>

Expand All @@ -33,14 +36,14 @@
<field name="inherit_id" ref="polars_process.df_source_search" />
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="db_id" />
<field name="db_conf_id" />
</xpath>
<xpath expr="//group" position="inside">
<filter
string="Database"
name="db_id"
name="db_conf_id"
domain="[]"
context="{'group_by': 'db_id'}"
context="{'group_by': 'db_conf_id'}"
/>
</xpath>
</field>
Expand Down
15 changes: 12 additions & 3 deletions polars_db_process/wizards/df_process.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from odoo import _, exceptions, models

MODULE = __name__[12 : __name__.index(".", 13)]


class DfProcessWiz(models.TransientModel):
_inherit = "df.process.wiz"
Expand All @@ -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())
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# generated from manifests external_dependencies
connectorx

0 comments on commit bd39a80

Please sign in to comment.