Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] add default_value for import and export #114

Open
wants to merge 2 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pattern_import_export/models/pattern_chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ def run_import(self):
pattern_config={
"model": model,
"record_ids": [],
"purge_one2many": (
self.pattern_file_id.pattern_config_id.purge_one2many
),
"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_csv/models/pattern_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PatternFile(models.Model):
_inherit = "pattern.file"

def _parse_data_csv(self, datafile):
in_file = io.StringIO(datafile.decode("utf-8"))
in_file = io.StringIO(datafile.decode("utf-8-sig"))
config = self.pattern_config_id
if config.header_format == "description_and_tech":
# read the first line to skip it
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
Loading