mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
prepare #IBMBTT app_common处理更多的import导入
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}"))
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<h2 class="oe_slogan">odooAi Common Util and Tools</h2>
|
||||
<h3 class="oe_slogan"> Network and media and base tools </h3>
|
||||
<div class="oe_row">
|
||||
<h3>Lastest update: v16.25.01.06</h3>
|
||||
<h3>Lastest update: v16.25.02.21</h3>
|
||||
<div class="row">
|
||||
<img class="oe_demo oe_screenshot img img-fluid" style="max-height: 100%;" src="banner.png">
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user