Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Oct 28, 2024
1 parent 147e229 commit 882f7fa
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 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 file polars example</field>
<field name="name">Populate Polars 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
1 change: 1 addition & 0 deletions polars_process/models/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Dataframe(models.Model):
_inherit = "mail.thread"
_description = "File Configuration"
_rec_name = "code"
_rec_names_search = ["model_id", "code"]

model_id = fields.Many2one(
comodel_name="ir.model",
Expand Down
2 changes: 2 additions & 0 deletions polars_process/models/df_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class FileField(models.Model):
_inherit = ["mail.thread"]
_description = "Configuration de l'import de champ"
_order = "field_id ASC"
_rec_name = "field_id"
_rec_names_search = ["field_id"]

dataframe_id = fields.Many2one(
comodel_name="dataframe", required=True, ondelete="cascade"
Expand Down
14 changes: 10 additions & 4 deletions polars_process/models/df_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
class DfSource(models.Model):
_name = "df.source"
_description = "Dataframe data source"
_rec_name = "name"
_rec_names_search = ["name"]

dataframe_id = fields.Many2one(
comodel_name="dataframe", required=True, ondelete="cascade"
)
name = fields.Char()
name = fields.Char(help="Supported files: .xlsx")
sequence = fields.Integer()
rename = fields.Boolean(help="Display renamed Dataframe in wizard")
template = fields.Binary(string="File", attachment=False)
Expand All @@ -28,8 +30,7 @@ def create_attach(myfile, addon, idstring, relative_path):
"readonly": True,
"rename": True,
}
if ".sql" in name:
vals["query"] = self._get_file(name)
vals.update(self._file_hook(name))
self.env[self._name].sudo().create(vals)

self.env[self._name].search([("template", "=", False)]).unlink()
Expand All @@ -50,8 +51,9 @@ def start(self):
"filename": self.name,
"df_source_id": self.id,
"dataframe_id": self.dataframe_id.id,
"file": base64.b64encode(self._get_file()),
}
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
Expand Down Expand Up @@ -98,3 +100,7 @@ def ui_form(self):
"type": "ir.actions.act_window",
"target": "current",
}

def _file_hook(self, file):
"Overide me in your own module"
return {}
15 changes: 5 additions & 10 deletions polars_process/views/menu.xml
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
<odoo>
<menuitem
id="polars_menu"
name="Polars"
parent="contacts.menu_contacts"
sequence="3"
/>
<menuitem id="polars_menu" name="🐻‍❄️" parent="contacts.menu_contacts" sequence="3" />
<menuitem
id="dataframe_menu"
action="action_dataframe"
sequence="2"
sequence="1"
parent="polars_menu"
/>
<menuitem
id="df_source_menu"
action="df_source_action"
parent="polars_menu"
sequence="5"
sequence="4"
/>
<menuitem
id="refresh_df_source_menu"
action="refresh_df_source_action"
sequence="9"
sequence="5"
parent="polars_menu"
/>

<menuitem
id="df_process_wiz_menu"
action="df_process_wiz_action"
parent="polars_menu"
sequence="7"
sequence="6"
/>
</odoo>
11 changes: 7 additions & 4 deletions polars_process/wizards/df_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ class DfProcessWiz(models.TransientModel):

def create(self, vals):
res = super().create(vals)
if res.dataframe_id and res.file:
res._pre_process()
res._pre_process()
return res

def _pre_process(self):
if self.dataframe_id and self.file:
self._pre_process_file()

def _pre_process_file(self):
self.ensure_one()
attribs = {}
df = self._get_dataframe()
Expand All @@ -42,7 +45,7 @@ def _pre_process(self):
renamed_df, rdf = self._rename_df_columns(df)
if renamed_df:
attribs["Renamed Columns"] = rdf
self._pre_process_hook(df, attribs)
self._pre_process_file_hook(df, attribs)
comment = "\n".join(
[
f'<div id="{self._slug_me(key)}"><div>{key}:</div>'
Expand All @@ -56,7 +59,7 @@ def _pre_process(self):
)
self._reload()

def _pre_process_hook(self, df, attribs):
def _pre_process_file_hook(self, df, attribs):
"Inherit for your own behavior"
self.ensure_one()

Expand Down
2 changes: 1 addition & 1 deletion polars_process/wizards/df_process.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</record>

<record id="df_process_wiz_action" model="ir.actions.act_window">
<field name="name">Process Dataframe</field>
<field name="name">Process Dataframe Wizard</field>
<field name="res_model">df.process.wiz</field>
<field name="view_mode">form</field>
<field name="target">inline</field>
Expand Down

0 comments on commit 882f7fa

Please sign in to comment.