Skip to content

Commit

Permalink
[14.0][IMP] add default_value for import and export
Browse files Browse the repository at this point in the history
  • Loading branch information
chafique-delli committed Feb 17, 2023
1 parent e896fd6 commit ae76975
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions pattern_import_export/models/pattern_chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def run_import(self):
"model": model,
"record_ids": [],
"purge_one2many": self.pattern_file_id.pattern_config_id.purge_one2many,
"pattern_file": self.pattern_file_id,
}
)
.env[model]
Expand Down
2 changes: 1 addition & 1 deletion pattern_import_export_custom_header/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Pattern export custom header",
"summary": "Allow to use custom headers names in export files",
"summary": "Allow to use custom headers names in export or import files",
"version": "14.0.1.0.1",
"category": "Extra Tools",
"website": "https://github.com/shopinvader/pattern-import-export",
Expand Down
1 change: 1 addition & 0 deletions pattern_import_export_custom_header/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import pattern_config
from . import base
20 changes: 20 additions & 0 deletions pattern_import_export_custom_header/models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (C) 2023 Akretion (<http://www.akretion.com>).
# @author Chafique Delli <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class Base(models.AbstractModel):
_inherit = "base"

def _pattern_format2json(self, row):
config = self._context["pattern_config"]["pattern_file"].pattern_config_id
new_row = {
header.initial_header_name: row.get(header.name)
or header.import_default_value
for header in config.custom_header_ids
}
if new_row:
row = new_row
return super()._pattern_format2json(row=row)
4 changes: 3 additions & 1 deletion pattern_import_export_custom_header/models/pattern_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PatternConfig(models.Model):

def _map_with_custom_header(self, data):
return {
item.name: data.get(item.initial_header_name)
item.name: data.get(item.initial_header_name) or item.export_default_value
for item in self.custom_header_ids
}

Expand Down Expand Up @@ -72,6 +72,8 @@ class PatternCustomHeader(models.Model):
custom_name = fields.Char(string="Custom Header Name")
initial_header_name = fields.Char(string="Initial Header Name")
pattern_id = fields.Many2one("pattern.config", required=True)
import_default_value = fields.Char(string="Import default Value")
export_default_value = fields.Char(string="Export default Value")

def _compute_name(self):
for record in self:
Expand Down
2 changes: 2 additions & 0 deletions pattern_import_export_custom_header/views/pattern_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
name="custom_name"
attrs="{'required': [('initial_header_name', '=', False)]}"
/>
<field name="import_default_value" />
<field name="export_default_value" />
</tree>
</field>
</page>
Expand Down

0 comments on commit ae76975

Please sign in to comment.