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 3fd0fb4 commit 14090a7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion polars_process/data/action.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="refresh_df_source_action" model="ir.actions.server">
<field name="name">Populate Polars data source</field>
<field name="name">⚙ Populate data source</field>
<field name="model_id" ref="model_df_source" />
<field name="binding_model_id" ref="model_df_source" />
<field name="state">code</field>
Expand Down
49 changes: 24 additions & 25 deletions polars_process/models/df_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,34 @@ class DfSource(models.Model):
)
name = fields.Char(help="Supported files: .xlsx")
sequence = fields.Integer()
state = fields.Selection(selection=[('draft', "Draft"), ("ready", "Ready"), ("done", "Done")], default="draft")
rename = fields.Boolean(help="Display renamed Dataframe in wizard")
template = fields.Binary(string="File", attachment=False)
readonly = fields.Boolean(help="Imported records from module are readonly created")

def start(self):
self.ensure_one()
vals = {
"filename": self.name,
"df_source_id": self.id,
"model_map_id": self.model_map_id.id,
}
if ".xlsx" in self.name:
vals["file"] = base64.b64encode(self._get_file())
transient = self.env["df.process.wiz"].create(vals)
action = self.env.ref("polars_process.df_process_wiz_action")._get_action_dict()
action["res_id"] = transient.id
self.state = "done"
return action

def reset_process(self):
self.ensure_one()
self._reset_process()

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

View check run for this annotation

Codecov / codecov/patch

polars_process/models/df_source.py#L40-L41

Added lines #L40 - L41 were not covered by tests

def _reset_process(self):
"Inherit me"
self.state = "draft"

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

View check run for this annotation

Codecov / codecov/patch

polars_process/models/df_source.py#L45

Added line #L45 was not covered by tests

def _populate(self):
def create_attach(myfile, addon, idstring, relative_path):
with open(myfile, "rb") as f:
Expand All @@ -45,20 +69,6 @@ def create_attach(myfile, addon, idstring, relative_path):
action = self.env.ref("polars_process.df_source_action")._get_action_dict()
return action

def start(self):
self.ensure_one()
vals = {
"filename": self.name,
"df_source_id": self.id,
"model_map_id": self.model_map_id.id,
}
if ".xlsx" in self.name:
vals["file"] = base64.b64encode(self._get_file())
transient = self.env["df.process.wiz"].create(vals)
action = self.env.ref("polars_process.df_process_wiz_action")._get_action_dict()
action["res_id"] = transient.id
return action

def _get_file(self, name=None):
# TODO Clean
if self.template:
Expand Down Expand Up @@ -90,17 +100,6 @@ def _get_test_file_paths(self):
}
}

def ui_form(self):
self.ensure_one()
return {
"name": _("Dataframe source"),
"res_model": self._name,
"view_mode": "form",
"res_id": self.id,
"type": "ir.actions.act_window",
"target": "current",
}

def _file_hook(self, file):
"Overide me in your own module"
return {}
16 changes: 12 additions & 4 deletions polars_process/views/df_source.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<list editable="bottom">
<field name="sequence" widget="handle" />
<field name="model_map_id" />
<button name="ui_form" type="object" string="Form" />
<button
name="start"
class="fa fa-play"
Expand All @@ -43,11 +42,20 @@
options="{'accepted_file_extensions': '.xlsx'}"
/>
<field name="name" />
<field name="rename" />
<field name="state" />
<button
type="object"
name="reset_process"
class="fa fa-refresh"
invisible="state!='done'"
title="Not yet implemented in this module"
/>
<!-- <field name="id" optional="hide" /> -->
<field name="rename" optional="hide" />
</list>
</field>
</record>

<record id="df_source_search" model="ir.ui.view">
<field name="model">df.source</field>
<field name="arch" type="xml">
Expand All @@ -67,7 +75,7 @@
</record>

<record id="df_source_action" model="ir.actions.act_window">
<field name="name">Polars data source</field>
<field name="name">Data sources for Polars</field>
<field name="res_model">df.source</field>
<field name="view_mode">list,form</field>
<field name="path">df-source</field>
Expand Down
6 changes: 3 additions & 3 deletions polars_process/views/menu.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<odoo>
<menuitem id="polars_menu" name="🐻‍❄️" parent="contacts.menu_contacts" sequence="3" />
<menuitem id="polars_menu" name="🐻‍❄️ Polars" parent="contacts.menu_contacts" sequence="3" />
<menuitem
id="model_map_menu"
action="action_model_map"
Expand All @@ -8,6 +8,7 @@
/>
<menuitem
id="df_source_menu"
name="Data source"
action="df_source_action"
parent="polars_menu"
sequence="4"
Expand All @@ -18,11 +19,10 @@
sequence="5"
parent="polars_menu"
/>

<menuitem
id="df_process_wiz_menu"
action="df_process_wiz_action"
parent="polars_menu"
sequence="6"
sequence="9"
/>
</odoo>

0 comments on commit 14090a7

Please sign in to comment.