From f442585265933ca9089925b2ca416600f285c21c Mon Sep 17 00:00:00 2001 From: Chill Date: Fri, 21 Feb 2025 18:21:21 +0800 Subject: [PATCH] =?UTF-8?q?prepare=20#IBMBTT=20app=5Fcommon=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=9B=B4=E5=A4=9A=E7=9A=84import=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_common/__manifest__.py | 2 +- app_common/i18n/zh_CN.po | 36 +++++++-------- app_common/models/app_import.py | 56 ++++++++++++++++++++++-- app_common/static/description/index.html | 2 +- 4 files changed, 70 insertions(+), 26 deletions(-) diff --git a/app_common/__manifest__.py b/app_common/__manifest__.py index c6a1c8c4..2ca19dc5 100644 --- a/app_common/__manifest__.py +++ b/app_common/__manifest__.py @@ -39,7 +39,7 @@ { 'name': "odooAi Common Util and Tools,欧度智能基础功能及面板", - 'version': '16.0.25.01.06', + 'version': '16.0.25.02.21', 'author': 'odooai.cn', 'category': 'Extra tools', 'website': 'https://www.odooai.cn', diff --git a/app_common/i18n/zh_CN.po b/app_common/i18n/zh_CN.po index 8f697414..080efb22 100644 --- a/app_common/i18n/zh_CN.po +++ b/app_common/i18n/zh_CN.po @@ -4,10 +4,10 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 16.0+e-20231112\n" +"Project-Id-Version: Odoo Server 16.0+e-20241226\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-01-03 09:20+0000\n" -"PO-Revision-Date: 2025-01-03 09:20+0000\n" +"POT-Creation-Date: 2025-02-21 08:15+0000\n" +"PO-Revision-Date: 2025-02-21 08:15+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -66,10 +66,16 @@ msgstr "忽略的邮箱: %s" #. module: app_common #: model:ir.model.fields,field_description:app_common.field_res_config_settings__app_saas_ok -#: model_terms:ir.ui.view,arch_db:app_common.app_res_config_settings_view_form msgid "Enable CN SaaS" msgstr "启用Odoo中文云服务" +#. module: app_common +#. odoo-python +#: code:addons/app_common/models/app_import.py:0 +#, python-format +msgid "File %s not found" +msgstr "文件 %s 未找到" + #. module: app_common #: model_terms:ir.ui.view,arch_db:app_common.app_res_config_settings_view_form msgid "" @@ -99,16 +105,6 @@ msgstr "邮件服务器" msgid "Outgoing Mails" msgstr "发出邮件" -#. module: app_common -#: model:ir.model.fields,field_description:app_common.field_res_config_settings__app_saas_db_token -msgid "SaaS Common Token" -msgstr "云通讯Token" - -#. module: app_common -#: model_terms:ir.ui.view,arch_db:app_common.app_res_config_settings_view_form -msgid "SaaS Settings" -msgstr "云通讯设置" - #. module: app_common #: model:ir.model,name:app_common.model_ir_cron msgid "Scheduled Actions" @@ -129,7 +125,7 @@ msgstr "本操作只对销售订单和采购订单生效" #. module: app_common #: model:ir.model,name:app_common.model_ir_ui_view msgid "View" -msgstr "查看" +msgstr "视图" #. module: app_common #: model_terms:ir.ui.view,arch_db:app_common.app_res_config_settings_view_form @@ -140,11 +136,6 @@ msgstr "" "欢迎访问欧度智能官方网站,获取Odoo企业级运营支持。\n" "\t\t\t\t\t\t\t\t\t\t\t\t\t https://www.odooai.cn" -#. module: app_common -#: model_terms:ir.ui.view,arch_db:app_common.app_res_config_settings_view_form -msgid "https://www.odooapp.cn/apps/modules/app_saas" -msgstr "https://www.odooapp.cn/apps/modules/app_saas" - #. module: app_common #. odoo-python #: code:addons/app_common/models/ir_ui_view.py:0 @@ -154,6 +145,11 @@ msgid "" " file: %s" msgstr "此警告可忽略:载入文件失败 RelaxNG XML schema for views validation, 文件名: %s" +#. module: app_common +#: model_terms:ir.ui.view,arch_db:app_common.app_res_config_settings_view_form +msgid "https://www.odooapp.cn/apps/modules/app_saas" +msgstr "" + #. module: app_common #: model:ir.actions.act_window,name:app_common.action_odooai_cloud_config #: model_terms:ir.ui.view,arch_db:app_common.app_res_config_settings_view_form diff --git a/app_common/models/app_import.py b/app_common/models/app_import.py index 2615f952..930fc3b1 100644 --- a/app_common/models/app_import.py +++ b/app_common/models/app_import.py @@ -1,18 +1,21 @@ # -*- coding: utf-8 -*- import os.path - +import json +from os.path import basename, splitext from odoo import api, fields, models, modules, tools, SUPERUSER_ID, _ +import logging +_logger = logging.getLogger(__name__) def app_quick_import(env, content_path, sep=None, context={}): if not sep: sep = '/' dir_split = content_path.split(sep) module_name = dir_split[0] - file_name = dir_split[2] + file_name = dir_split[-1] file_path, file_type = os.path.splitext(content_path) model_name = file_name.replace(file_type, '') - file_path = modules.get_module_resource(module_name, dir_split[1], file_name) + file_path = modules.get_module_resource(*dir_split) content = open(file_path, 'rb').read() uid = SUPERUSER_ID if model_name == 'mail.channel': @@ -41,7 +44,7 @@ def app_quick_import(env, content_path, sep=None, context={}): }) else: preview = False - + if preview: import_wizard.execute_import( preview["headers"], @@ -50,3 +53,48 @@ def app_quick_import(env, content_path, sep=None, context={}): ) +def app_quick_import_json(env, content_path, sep=None, context={}): + try: + if not sep: + sep = '/' + dir_split = content_path.split(sep) + module_name = dir_split[0] + filename = dir_split[-1] + model_name, file_extension = splitext(filename) + file_path = modules.get_module_resource(*dir_split) + if not file_path: + _logger.error(_('File %s not found' % content_path)) + return + if file_extension.lower() != '.json': + _logger.error(_(f"File {filename} is not a JSON file")) + return + + with open(file_path, 'r') as file: + content = file.read() + if not content.strip(): + _logger.error(_(f"File {filename} is empty")) + return + try: + data = json.loads(content) + except json.JSONDecodeError as e: + _logger.error(_(f"Invalid JSON format in file {filename}: {e}")) + return + + model = env[model_name] + if not model._fields: + _logger.error(_(f"Model {model_name} not found")) + return + if not data: + _logger.error(_(f"No records found in file {filename}")) + return + + import_fields = list(data[0].keys()) + merged_data = [] + for record in data: + record_data = [record[field] for field in import_fields] + merged_data.append(record_data) + import_result = model.load(import_fields, merged_data) + except FileNotFoundError: + _logger.error(_(f"File not found: {content_path}")) + except Exception as e: + _logger.error(_(f"Unexpected error during import: {e}")) diff --git a/app_common/static/description/index.html b/app_common/static/description/index.html index 41f95cbe..2f6c166c 100644 --- a/app_common/static/description/index.html +++ b/app_common/static/description/index.html @@ -4,7 +4,7 @@

odooAi Common Util and Tools

Network and media and base tools

-

Lastest update: v16.25.01.06

+

Lastest update: v16.25.02.21