-
-
Notifications
You must be signed in to change notification settings - Fork 274
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
10 changed files
with
81 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
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,10 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<record id="remove_related_uidstring_record" model="ir.actions.server"> | ||
<field name="name">Remove ir_model_data created from there</field> | ||
<field name="model_id" ref="polars_db_process.model_model_map" /> | ||
<field name="binding_model_id" ref="polars_db_process.model_model_map" /> | ||
<field name="state">code</field> | ||
<field name="code">env['model.map']._remove_related_uidstring_record()</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
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,2 +1,3 @@ | ||
from . import df_source | ||
from . import db_config | ||
from . import model_map |
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
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,20 @@ | ||
from odoo import models | ||
|
||
|
||
class ModelMap(models.Model): | ||
_inherit = "model.map" | ||
|
||
def _remove_related_uidstring_record(self): | ||
self = self.browse(self.env.context.get("active_ids")) | ||
self = self and self[0] or False | ||
res = self.env["ir.model.data"].search( | ||
[ | ||
("model", "=", self.model_id.model), | ||
("module", "=", self._get_uidstring_module_name()), | ||
] | ||
) | ||
res.reference.unlink() | ||
return True | ||
|
||
def _get_uidstring_module_name(self): | ||
return "polars" |
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
File renamed without changes.
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,25 +1,50 @@ | ||
import logging | ||
|
||
from odoo import _, exceptions, models | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class DfProcessWiz(models.TransientModel): | ||
_inherit = "df.process.wiz" | ||
|
||
def _pre_process(self): | ||
res = super()._pre_process() | ||
if not self.file: | ||
self._pre_process_sql() | ||
self._pre_process_query() | ||
return res | ||
|
||
def _pre_process_sql(self): | ||
def _pre_process_query(self): | ||
"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() | ||
self._process_query() | ||
|
||
def _process_sql(self): | ||
def _process_query(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()) | ||
if self.model_map_id: | ||
model = self.model_map_id.model_id.model | ||
vals_list = df.to_dicts() | ||
mapper = {} | ||
for vals in vals_list: | ||
uidstring = vals.pop("id") | ||
if "parent_id" in vals: | ||
vals["parent_id"] = mapper.get(vals["parent_id"]) | ||
rec = self.env[model].create(vals) | ||
mapper[uidstring] = rec.id | ||
logger.info(" >>> ", vals) | ||
self._set_uidstring(uidstring, rec, model) | ||
|
||
def _set_uidstring(self, uidstring, record, model): | ||
self.env["ir.model.data"].create( | ||
{ | ||
"res_id": record.id, | ||
"model": model, | ||
"module": self.model_map_id._get_uidstring_module_name(), | ||
"name": uidstring, | ||
"noupdate": False, | ||
} | ||
) |