3232class BaseImportImport (models .TransientModel ):
3333 _inherit = "base_import.import"
3434
35- def do (self , fields , columns , options , dryrun = False ):
35+ def execute_import (self , fields , columns , options , dryrun = False ):
3636 if dryrun or not options .get (OPT_USE_QUEUE ):
3737 # normal import
38- return super ().do (fields , columns , options , dryrun = dryrun )
38+ return super ().execute_import (fields , columns , options , dryrun = dryrun )
3939
4040 # asynchronous import
4141 try :
@@ -56,15 +56,18 @@ def do(self, fields, columns, options, dryrun=False):
5656 translated_model_name ,
5757 self .file_name ,
5858 )
59+ file_name = self .file_name
60+ if not file_name .endswith (".csv" ):
61+ file_name += ".csv"
5962 attachment = self ._create_csv_attachment (
60- import_fields , data , options , self . file_name
63+ import_fields , data , options , file_name
6164 )
6265 delayed_job = self .with_delay (description = description )._split_file (
6366 model_name = self .res_model ,
6467 translated_model_name = translated_model_name ,
6568 attachment = attachment ,
6669 options = options ,
67- file_name = self . file_name ,
70+ file_name = file_name ,
6871 )
6972 self ._link_attachment_to_job (delayed_job , attachment )
7073 return []
@@ -91,7 +94,12 @@ def _create_csv_attachment(self, fields, data, options, file_name):
9194 # create attachment
9295 datas = base64 .encodebytes (f .getvalue ().encode (encoding ))
9396 attachment = self .env ["ir.attachment" ].create (
94- {"name" : file_name , "datas" : datas }
97+ {
98+ "name" : file_name ,
99+ "datas" : datas ,
100+ "type" : "binary" ,
101+ "mimetype" : "text/csv" ,
102+ }
95103 )
96104 return attachment
97105
@@ -130,7 +138,7 @@ def _split_file(
130138 options ,
131139 file_name = "file.csv" ,
132140 ):
133- """ Split a CSV attachment in smaller import jobs """
141+ """Split a CSV attachment in smaller import jobs"""
134142 model_obj = self .env [model_name ]
135143 fields , data = self ._read_csv_attachment (attachment , options )
136144 padding = len (str (len (data )))
0 commit comments