diff --git a/app_common/models/app_import.py b/app_common/models/app_import.py index 68f66a69..0a0f2356 100644 --- a/app_common/models/app_import.py +++ b/app_common/models/app_import.py @@ -10,7 +10,7 @@ from odoo.tools import pycompat from odoo.tests import common ADMIN_USER_ID = common.ADMIN_USER_ID -def app_quick_import(env, content_path, sep=None): +def app_quick_import(env, content_path, sep=None, context={}): if not sep: sep = '/' dir_split = content_path.split(sep) @@ -28,7 +28,8 @@ def app_quick_import(env, content_path, sep=None): file_type = 'text/csv' elif file_type in ['.xls', '.xlsx']: file_type = 'application/vnd.ms-excel' - import_wizard = env['base_import.import'].create({ + import_wizard = env['base_import.import'].with_context(context) + import_wizard = import_wizard.create({ 'res_model': model_name, 'file_name': file_name, 'file_type': file_type, @@ -44,10 +45,12 @@ def app_quick_import(env, content_path, sep=None): preview = import_wizard.parse_preview({ 'has_headers': True, }) - result = import_wizard.execute_import( - preview["headers"], - preview["headers"], - preview["options"] - ) - - + else: + preview = False + + if preview: + import_wizard.execute_import( + preview["headers"], + preview["headers"], + preview["options"] + )