File tree 6 files changed +38
-2
lines changed
pattern_import_export/models
6 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ def run_import(self):
40
40
"model" : model ,
41
41
"record_ids" : [],
42
42
"purge_one2many" : self .pattern_file_id .pattern_config_id .purge_one2many ,
43
+ "pattern_file" : self .pattern_file_id ,
43
44
}
44
45
)
45
46
.env [model ]
Original file line number Diff line number Diff line change 4
4
5
5
{
6
6
"name" : "Pattern export custom header" ,
7
- "summary" : "Allow to use custom headers names in export files" ,
7
+ "summary" : "Allow to use custom headers names in export or import files" ,
8
8
"version" : "14.0.1.0.1" ,
9
9
"category" : "Extra Tools" ,
10
10
"website" : "https://github.com/shopinvader/pattern-import-export" ,
Original file line number Diff line number Diff line change 1
1
from . import pattern_config
2
+ from . import base
Original file line number Diff line number Diff line change
1
+ # Copyright (C) 2023 Akretion (<http://www.akretion.com>).
2
+ # @author Chafique Delli <[email protected] >
3
+ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4
+
5
+ from odoo import models
6
+
7
+
8
+ class Base (models .AbstractModel ):
9
+ _inherit = "base"
10
+
11
+ def _pattern_format2json (self , row ):
12
+ pattern_config_ctx = self ._context .get ("pattern_config" )
13
+ if pattern_config_ctx :
14
+ pattern_file = pattern_config_ctx .get ("pattern_file" )
15
+ pattern_config = pattern_file .pattern_config_id
16
+ new_row = {}
17
+ for custom_header in pattern_config .custom_header_ids :
18
+ value = ""
19
+ if custom_header .custom_name and custom_header .custom_name in row :
20
+ value = row [custom_header .custom_name ]
21
+ elif (
22
+ custom_header .initial_header_name
23
+ and custom_header .initial_header_name in row
24
+ ):
25
+ value = row [custom_header .initial_header_name ]
26
+ if not value and custom_header .import_default_value :
27
+ value = custom_header .import_default_value
28
+ new_row [custom_header .initial_header_name ] = value
29
+ row = new_row
30
+ return super ()._pattern_format2json (row = row )
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class PatternConfig(models.Model):
19
19
20
20
def _map_with_custom_header (self , data ):
21
21
return {
22
- item .name : data .get (item .initial_header_name )
22
+ item .name : data .get (item .initial_header_name ) or item . export_default_value
23
23
for item in self .custom_header_ids
24
24
}
25
25
@@ -72,6 +72,8 @@ class PatternCustomHeader(models.Model):
72
72
custom_name = fields .Char (string = "Custom Header Name" )
73
73
initial_header_name = fields .Char (string = "Initial Header Name" )
74
74
pattern_id = fields .Many2one ("pattern.config" , required = True )
75
+ import_default_value = fields .Char (string = "Import default Value" )
76
+ export_default_value = fields .Char (string = "Export default Value" )
75
77
76
78
def _compute_name (self ):
77
79
for record in self :
Original file line number Diff line number Diff line change 30
30
name =" custom_name"
31
31
attrs =" {'required': [('initial_header_name', '=', False)]}"
32
32
/>
33
+ <field name =" import_default_value" />
34
+ <field name =" export_default_value" />
33
35
</tree >
34
36
</field >
35
37
</page >
You can’t perform that action at this time.
0 commit comments