From 0e725f33d784cbdea6dcf1dcfe7ac46e494255a7 Mon Sep 17 00:00:00 2001 From: Chill Date: Thu, 17 Aug 2023 19:10:29 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#I7TD3E=20=E3=80=90app=5Fai=5Fseo?= =?UTF-8?q?=E3=80=91=E7=BD=91=E7=AB=99=E5=BF=AB=E9=80=9Fseo=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_common/models/app_import.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/app_common/models/app_import.py b/app_common/models/app_import.py index 47cea556..c608bc4b 100644 --- a/app_common/models/app_import.py +++ b/app_common/models/app_import.py @@ -7,7 +7,8 @@ import os.path from odoo import api, fields, models, modules, tools, SUPERUSER_ID, _ from odoo.tools import pycompat - +from odoo.tests import common +ADMIN_USER_ID = common.ADMIN_USER_ID def app_quick_import(cr, content_path, sep=None): if not sep: @@ -19,7 +20,11 @@ def app_quick_import(cr, content_path, sep=None): model_name = file_name.replace(file_type, '') file_path = modules.get_module_resource(module_name, dir_split[1], file_name) content = open(file_path, 'rb').read() - env = api.Environment(cr, SUPERUSER_ID, {}) + uid = SUPERUSER_ID + if model_name == 'mail.channel': + # todo: 创建mail.channel时,如果用root用户会报错 + uid = 2 + env = api.Environment(cr, uid, {}) if file_type == '.csv': file_type = 'text/csv' elif file_type in ['.xls', '.xlsx']: @@ -30,11 +35,16 @@ def app_quick_import(cr, content_path, sep=None): 'file_type': file_type, 'file': content, }) - preview = import_wizard.parse_preview({ - # 'separator': ',', - 'has_headers': True, - # 'quoting': '"', - }) + if file_type == 'text/csv': + preview = import_wizard.parse_preview({ + 'separator': ',', + 'has_headers': True, + 'quoting': '"', + }) + elif file_type == 'application/vnd.ms-excel': + preview = import_wizard.parse_preview({ + 'has_headers': True, + }) result = import_wizard.execute_import( preview["headers"], preview["headers"],