Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Oct 31, 2024
1 parent ef401f3 commit 3fd0732
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 22 deletions.
File renamed without changes.
1 change: 0 additions & 1 deletion polars_db_process/models/df_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def _get_test_file_paths(self):
res.update(

Check warning on line 110 in polars_db_process/models/df_source.py

View check run for this annotation

Codecov / codecov/patch

polars_db_process/models/df_source.py#L109-L110

Added lines #L109 - L110 were not covered by tests
{
"polars_db_process": {
"relative_path": "data/files",
"xmlid": "polars_db_process.contact_chinook",
}
}
Expand Down
1 change: 0 additions & 1 deletion polars_db_schema/models/db_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class DfSource(models.Model):
# res.update(
# {
# "polars_db_schema": {
# "relative_path": "tests/files",
# "xmlid": "migr.contact",
# }
# }
Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 9 additions & 13 deletions polars_process/models/df_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from odoo import fields, models
from odoo.modules.module import get_module_path

DF_SOURCE_DIR = "data/df"


class DfSource(models.Model):
_name = "df.source"
Expand Down Expand Up @@ -48,7 +50,7 @@ def _reset_process(self):
self.state = "draft"

Check warning on line 50 in polars_process/models/df_source.py

View check run for this annotation

Codecov / codecov/patch

polars_process/models/df_source.py#L50

Added line #L50 was not covered by tests

def _populate(self):
def create_attach(myfile, addon, idstring, relative_path):
def create_attach(myfile, addon, idstring):
with open(myfile, "rb") as f:
name = f.name[f.name.find(addon) :]
vals = {
Expand All @@ -63,12 +65,11 @@ def create_attach(myfile, addon, idstring, relative_path):
self.env[self._name].search([("template", "=", False)]).unlink()
paths = self._get_test_file_paths()
for addon, data in paths.items():
relative_path = data["relative_path"]
idstring = data["xmlid"]
if self.env.ref(idstring):
mpath = Path(get_module_path(addon)) / relative_path
mpath = Path(get_module_path(addon)) / DF_SOURCE_DIR
for mfile in tuple(mpath.iterdir()):
create_attach(mfile, addon, idstring, relative_path)
create_attach(mfile, addon, idstring)
action = self.env.ref("polars_process.df_source_action")._get_action_dict()
return action

Expand All @@ -78,27 +79,22 @@ def _get_file(self, name=None):
return self.template

Check warning on line 79 in polars_process/models/df_source.py

View check run for this annotation

Codecov / codecov/patch

polars_process/models/df_source.py#L79

Added line #L79 was not covered by tests
name = self.name or name
module = name[: name.find("/")]
relative = self._get_test_file_paths().get(module)
relative = relative and relative.get("relative_path")
if relative:
path = Path(get_module_path(module))
path = path / relative / name[name.rfind("/") + 1 :]
with open(path, "rb") as f:
return f.read()
path = Path(get_module_path(module))
path = path / DF_SOURCE_DIR / name[name.rfind("/") + 1 :]
with open(path, "rb") as f:
return f.read()

def _get_test_file_paths(self):
"""
You may override if you want populate files in your module
returns:
{"module_name": {
"relative_path": "tests/files",
"xmlid": "model_map_xml_id"}
}
}
"""
return {
"polars_process": {
"relative_path": "tests/files",
"xmlid": "polars_process.model_map_contact",
}
}
Expand Down
13 changes: 6 additions & 7 deletions polars_process/views/df_source.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@
type="object"
title="Start process"
/>
<field
name="template"
filename="name"
widget="binary"
options="{'accepted_file_extensions': '.xlsx'}"
/>
<field name="name" />
<field name="state" />
<button
Expand All @@ -50,7 +44,12 @@
invisible="state!='done'"
title="Not yet implemented in this module"
/>
<!-- <field name="id" optional="hide" /> -->
<field
name="template"
filename="name"
widget="binary"
options="{'accepted_file_extensions': '.xlsx'}"
/>
<field name="rename" optional="hide" />
</list>
</field>
Expand Down

0 comments on commit 3fd0732

Please sign in to comment.