-
-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
300 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,13 @@ Authors | |
|
||
* Akretion | ||
|
||
Contributors | ||
------------ | ||
|
||
- Akretion | ||
|
||
- David BEAL [email protected] | ||
|
||
Maintainers | ||
----------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
<odoo /> | ||
<odoo noupdate="1"> | ||
<record id="sqlite_chinook" model="db.config"> | ||
<field name="name">Chinook</field> | ||
<field | ||
name="string_connexion" | ||
>sqlite://.../polars_db_schema/tests/files/chinook.sqlite</field> | ||
</record> | ||
|
||
<record id="contact_chinook" model="dataframe"> | ||
<field name="model_id" ref="base.model_res_partner" /> | ||
<field name="code">Chinook Customers</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--{"model": "res.partner"} | ||
SELECT LastName AS name, State AS state, PostalCode AS zip, Email AS mail | ||
-- , Company, Address, City, Country, Phone, Fax, SupportRepId | ||
FROM customers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
from . import dataframe | ||
from . import df_field | ||
from . import df_source | ||
from . import db_config |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import connectorx as cx | ||
|
||
from odoo import _, exceptions, fields, models | ||
|
||
HELP = """ | ||
String connexion samples: | ||
postgres://user:PASSWORD@server:port/database | ||
mssql://user:PASSWORD@server:port/db.encrypt=true&trusted_connection=false | ||
sqlite:///home/user/path/test.db | ||
mysql://user:PASSWORD@server:port/database | ||
oracle://user:PASSWORD@server:port/database | ||
""" | ||
|
||
|
||
class DbConfig(models.Model): | ||
_name = "db.config" | ||
_description = "External db.configuration" | ||
_rec_name = "name" | ||
_order = "name" | ||
_rec_names_search = ["name"] | ||
|
||
name = fields.Char(required=True) | ||
string_connexion = fields.Char(required=True, help=HELP) | ||
password = fields.Char(help="Not required for Sqlite") | ||
|
||
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") | ||
if len(res): | ||
# Not invalid in reality | ||
raise exceptions.ValidationError(_("Connexion OK !")) | ||
|
||
def _read_sql(self, connexion, query): | ||
try: | ||
return cx.read_sql(connexion, query, return_type="polars") | ||
except RuntimeError as err: | ||
raise exceptions.ValidationError(err) from err | ||
except TimeoutError as err: | ||
raise exceptions.ValidationError(err) from err | ||
except Exception as err: | ||
raise exceptions.ValidationError(err) from err |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,84 @@ | ||
from odoo import models | ||
from pathlib import Path | ||
|
||
from odoo import fields, models | ||
from odoo.modules.module import get_module_path | ||
from odoo.tools.safe_eval import safe_eval | ||
|
||
MODULE = __name__[12 : __name__.index(".", 13)] | ||
|
||
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} | ||
""" | ||
|
||
|
||
class DfSource(models.Model): | ||
_inherit = "df.source" | ||
|
||
name = fields.Char(help=HELP) | ||
query = fields.Char() | ||
# TODO : -> db_config_id | ||
db_id = fields.Many2one(comodel_name="db.config", help="Database") | ||
|
||
def _file_hook(self, file): | ||
"Map sql file with the right Odoo model via dataframe and the right db.config" | ||
vals = super()._file_hook(file) | ||
if ".sql" in file: | ||
# TODO: improve | ||
content = self._get_file(file).decode("utf-8") | ||
contents = content.split("\n") | ||
if contents: | ||
# we only detect first line | ||
metadata = safe_eval(contents[0].replace("--", "")) | ||
model_name = metadata.get("model") | ||
model = self.env["ir.model"].search([("model", "=", model_name)]) | ||
if model_name: | ||
# we don't want to use these dataframes | ||
dataframes = ( | ||
self.env["df.source"] | ||
.search([]) | ||
.filtered(lambda s: not s.db_id) | ||
.mapped("dataframe_id") | ||
) | ||
dataframe = self.env["dataframe"].search( | ||
[ | ||
("id", "not in", dataframes.ids), | ||
("model_id", "=", model_name), | ||
] | ||
) | ||
if dataframe: | ||
# TODO use first | ||
vals["dataframe_id"] = dataframe[0].id | ||
db_config = self.env["db.config"].search( | ||
[("name", "ilike", metadata.get("db_id"))] | ||
) | ||
vals["db_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} | ||
) | ||
vals["dataframe_id"] = df.id | ||
vals["query"] = content | ||
return vals | ||
|
||
def _populate(self): | ||
chinook = self.env.ref(f"{MODULE}.sqlite_chinook") | ||
if chinook: | ||
# Demo behavior only | ||
path = Path(get_module_path(MODULE)) / "data/chinook.sqlite" | ||
chinook.string_connexion = f"sqlite://{str(path)}" | ||
return super()._populate() | ||
|
||
def _get_test_file_paths(self): | ||
res = super()._get_test_file_paths() | ||
res.update( | ||
{ | ||
"polars_db_process": { | ||
"relative_path": "data/files", | ||
"xmlid": "polars_db_process.contact_chinook", | ||
} | ||
} | ||
) | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- Akretion | ||
|
||
- David BEAL <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<odoo> | ||
<record id="db_config_all" model="ir.model.access"> | ||
<field name="name">Database Config</field> | ||
<field name="model_id" ref="model_db_config" /> | ||
<field name="group_id" ref="base.group_user" /> | ||
<field name="perm_read" eval="1" /> | ||
<field name="perm_create" eval="1" /> | ||
<field name="perm_write" eval="1" /> | ||
<field name="perm_unlink" eval="1" /> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<odoo> | ||
<record id="db_config_form" model="ir.ui.view"> | ||
<field name="model">db.config</field> | ||
<field name="arch" type="xml"> | ||
<form> | ||
<header> | ||
<button | ||
type="object" | ||
name="test_connexion" | ||
string="Test Connexion" | ||
/> | ||
</header> | ||
<sheet> | ||
<group> | ||
<group> | ||
<field name="name" /> | ||
</group> | ||
<group> | ||
<field name="password" password="1" /> | ||
</group> | ||
</group> | ||
<group name="connexion"> | ||
<field | ||
name="string_connexion" | ||
placeholder="postgres://username:PASSWORD@server:port/database" | ||
/> | ||
<div> | ||
<b | ||
>PASSWORD in string connexion'll be replaced by password field</b> | ||
</div> | ||
</group> | ||
</sheet> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="dataframe_list" model="ir.ui.view"> | ||
<field name="model">db.config</field> | ||
<field name="arch" type="xml"> | ||
<list> | ||
<field name="name" /> | ||
</list> | ||
</field> | ||
</record> | ||
|
||
<record id="db_config_action" model="ir.actions.act_window"> | ||
<field name="name">Database Config</field> | ||
<field name="res_model">db.config</field> | ||
<field name="view_mode">list,form</field> | ||
<field name="path">db-config</field> | ||
</record> | ||
|
||
<menuitem | ||
id="db_config_menu" | ||
action="db_config_action" | ||
parent="polars_process.polars_menu" | ||
sequence="7" | ||
/> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,48 @@ | ||
<odoo /> | ||
<odoo> | ||
<record id="df_source_form" model="ir.ui.view"> | ||
<field name="model">df.source</field> | ||
<field name="inherit_id" ref="polars_process.df_source_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//group[1]" position="after"> | ||
<separator /> | ||
<group> | ||
<field name="db_id" invisible="template" /> | ||
<field name="query" widget="code" invisible="template" /> | ||
</group> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="df_source_list" model="ir.ui.view"> | ||
<field name="model">df.source</field> | ||
<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" /> | ||
</xpath> | ||
<xpath expr="//list/field[@name='template']" position="attributes"> | ||
<attribute | ||
name="options" | ||
>{'accepted_file_extensions': '.xlsx,.sql'}</attribute> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="df_source_search" model="ir.ui.view"> | ||
<field name="model">df.source</field> | ||
<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" /> | ||
</xpath> | ||
<xpath expr="//group" position="inside"> | ||
<filter | ||
string="Database" | ||
name="db_id" | ||
domain="[]" | ||
context="{'group_by': 'db_id'}" | ||
/> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
from odoo import models | ||
from odoo import _, exceptions, models | ||
|
||
MODULE = __name__[12 : __name__.index(".", 13)] | ||
|
||
|
||
class DfProcessWiz(models.TransientModel): | ||
_inherit = "df.process.wiz" | ||
|
||
def _pre_process(self): | ||
res = super()._pre_process() | ||
if not self.file: | ||
self._pre_process_sql() | ||
return res | ||
|
||
def _pre_process_sql(self): | ||
raise exceptions.ValidationError(_("to be continued")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
odoo-addon-polars_process @ git+https://github.com/OCA/reporting-engine.git@refs/pull/943/head#subdirectory=polars_process | ||
odoo-addon-polars_process @ git+https://github.com/OCA/reporting-engine.git@refs/pull/943/head#subdirectory=polars_process |