Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
H
hh_ccs
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
贺阳
hh_ccs
Commits
fe4152be
提交
fe4152be
authored
3月 30, 2026
作者:
刘擎阳
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.新增ocr配置
上级
390b718b
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
119 行增加
和
3 行删除
+119
-3
order_state_change_rule.py
ccs_base/models/order_state_change_rule.py
+28
-0
res_config_setting.py
ccs_base/models/res_config_setting.py
+9
-0
baidu_ocr_config.py
ccs_base/pdf_tools/baidu_ocr_config.py
+15
-3
config_setting.xml
ccs_base/views/config_setting.xml
+67
-0
没有找到文件。
ccs_base/models/order_state_change_rule.py
浏览文件 @
fe4152be
...
@@ -258,6 +258,34 @@ class OrderStateChangeRule(models.Model):
...
@@ -258,6 +258,34 @@ class OrderStateChangeRule(models.Model):
logging
.
info
(
'邮件正文提取单号:
%
s'
%
text_arr
)
logging
.
info
(
'邮件正文提取单号:
%
s'
%
text_arr
)
attachment_arr
=
kwargs
[
'attachment_arr'
]
attachment_arr
=
kwargs
[
'attachment_arr'
]
attachment_tuple_arr
=
attachment_arr
if
attachment_arr
else
[]
attachment_tuple_arr
=
attachment_arr
if
attachment_arr
else
[]
try
:
from
..pdf_tools.baidu_ocr_config
import
get_baidu_ocr_config
from
..pdf_tools
import
awb_page_merger
ICP
=
self
.
env
[
'ir.config_parameter'
]
.
sudo
()
# 1. 组装 Odoo 系统参数
odoo_ocr_config
=
{
"baidu_ocr_app_id"
:
ICP
.
get_param
(
'ocr.baidu_app_id'
,
''
),
"baidu_ocr_api_key"
:
ICP
.
get_param
(
'ocr.baidu_api_key'
,
''
),
"baidu_ocr_secret_key"
:
ICP
.
get_param
(
'ocr.baidu_secret_key'
,
''
),
# Odoo的系统参数存的都是字符串,所以需要做类型转换
"ocr_enabled"
:
ICP
.
get_param
(
'ocr.enabled'
)
==
'True'
,
"ocr_timeout"
:
int
(
ICP
.
get_param
(
'ocr.timeout'
,
30
)),
"max_retries"
:
int
(
ICP
.
get_param
(
'ocr.max_retries'
,
3
)),
}
print
(
odoo_ocr_config
)
# 2. 注入配置:传 save_to_file=False 保证只在当前运行内存生效,不修改底层 json
ocr_config_manager
=
get_baidu_ocr_config
()
ocr_config_manager
.
update_config
(
odoo_ocr_config
,
save_to_file
=
False
)
# 3. 核心!清理 awb_page_merger 中的全局懒加载缓存
# 因为 awb_page_merger 缓存了 _OCR_EXTRACTOR 实例
# 必须重置为 None,否则如果在 Odoo 界面修改了秘钥,系统还会继续使用旧秘钥
awb_page_merger
.
_OCR_EXTRACTOR
=
None
logging
.
info
(
"Odoo OCR 配置注入成功"
)
except
ImportError
as
e
:
logging
.
error
(
f
"导入 OCR 模块失败,请检查路径: {e}"
)
except
Exception
as
e
:
logging
.
error
(
f
"注入 OCR 配置时发生错误: {e}"
)
try
:
try
:
# 清洗邮件正文提取的单号
# 清洗邮件正文提取的单号
text_arr
=
[
i
.
replace
(
'-'
,
''
)
.
replace
(
' '
,
''
)
.
replace
(
'
\xa0
'
,
''
)
for
i
in
text_arr
]
text_arr
=
[
i
.
replace
(
'-'
,
''
)
.
replace
(
' '
,
''
)
.
replace
(
'
\xa0
'
,
''
)
for
i
in
text_arr
]
...
...
ccs_base/models/res_config_setting.py
浏览文件 @
fe4152be
...
@@ -17,6 +17,15 @@ class ResConfigSettings(models.TransientModel):
...
@@ -17,6 +17,15 @@ class ResConfigSettings(models.TransientModel):
is_package_scan
=
fields
.
Boolean
(
is_package_scan
=
fields
.
Boolean
(
'一键全扫开关'
,
default
=
False
,
config_parameter
=
'is_package_scan'
)
'一键全扫开关'
,
default
=
False
,
config_parameter
=
'is_package_scan'
)
# OCR 相关配置
baidu_ocr_app_id
=
fields
.
Char
(
string
=
"Baidu OCR App ID"
,
config_parameter
=
'ocr.baidu_app_id'
)
baidu_ocr_api_key
=
fields
.
Char
(
string
=
"Baidu OCR API Key"
,
config_parameter
=
'ocr.baidu_api_key'
)
baidu_ocr_secret_key
=
fields
.
Char
(
string
=
"Baidu OCR Secret Key"
,
config_parameter
=
'ocr.baidu_secret_key'
)
ocr_enabled
=
fields
.
Boolean
(
string
=
"是否启用 OCR"
,
config_parameter
=
'ocr.enabled'
,
default
=
True
)
ocr_timeout
=
fields
.
Integer
(
string
=
"OCR 超时时间(秒)"
,
config_parameter
=
'ocr.timeout'
,
default
=
30
)
ocr_max_retries
=
fields
.
Integer
(
string
=
"最大重试次数"
,
config_parameter
=
'ocr.max_retries'
,
default
=
3
)
@api.model
@api.model
def
get_values
(
self
):
def
get_values
(
self
):
"""
"""
...
...
ccs_base/pdf_tools/baidu_ocr_config.py
浏览文件 @
fe4152be
...
@@ -140,15 +140,27 @@ class BaiduOCRConfig:
...
@@ -140,15 +140,27 @@ class BaiduOCRConfig:
"""获取所有配置"""
"""获取所有配置"""
return
self
.
_config
.
copy
()
return
self
.
_config
.
copy
()
def
update_config
(
self
,
config_dict
:
Dict
)
->
None
:
# def update_config(self, config_dict: Dict) -> None:
# """
# 批量更新配置
#
# Args:
# config_dict: 配置字典
# """
# self._config.update(config_dict)
# self._save_config(self._config)
def
update_config
(
self
,
config_dict
:
Dict
,
save_to_file
:
bool
=
True
)
->
None
:
"""
"""
批量更新配置
批量更新配置
Args:
Args:
config_dict: 配置字典
config_dict: 配置字典
save_to_file: 是否将配置持久化写入本地 JSON 文件
"""
"""
self
.
_config
.
update
(
config_dict
)
self
.
_config
.
update
(
config_dict
)
self
.
_save_config
(
self
.
_config
)
if
save_to_file
:
self
.
_save_config
(
self
.
_config
)
# 全局配置实例
# 全局配置实例
...
...
ccs_base/views/config_setting.xml
0 → 100644
浏览文件 @
fe4152be
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record
id=
"res_config_settings_view_form_ocr_inherit"
model=
"ir.ui.view"
>
<field
name=
"name"
>
res.config.settings.view.form.inherit.ocr
</field>
<field
name=
"model"
>
res.config.settings
</field>
<field
name=
"inherit_id"
ref=
"base_setup.res_config_settings_view_form"
/>
<field
name=
"arch"
type=
"xml"
>
<xpath
expr=
"//div[hasclass('app_settings_block')]/div"
position=
"before"
>
<!-- OCR 配置板块 -->
<div
id=
"ocr_baidu_config"
>
<h2>
百度 OCR 接口配置
</h2>
<div
class=
"row mt16 o_settings_container"
>
<!-- 开启/关闭开关 -->
<div
class=
"col-12 col-lg-6 o_setting_box"
>
<div
class=
"o_setting_left_pane"
>
<field
name=
"ocr_enabled"
/>
</div>
<div
class=
"o_setting_right_pane"
>
<label
for=
"ocr_enabled"
/>
<div
class=
"text-muted"
>
开启后,系统将自动识别附件 PDF 中的提单号
</div>
</div>
</div>
<!-- 百度参数设置 -->
<div
class=
"col-12 col-lg-6 o_setting_box"
attrs=
"{'invisible': [('ocr_enabled', '=', False)]}"
>
<div
class=
"o_setting_right_pane"
>
<div
class=
"content-group"
>
<div
class=
"row mt16"
>
<label
for=
"baidu_ocr_app_id"
string=
"App ID"
class=
"col-lg-3 o_light_label"
/>
<field
name=
"baidu_ocr_app_id"
/>
</div>
<div
class=
"row"
>
<label
for=
"baidu_ocr_api_key"
string=
"API Key"
class=
"col-lg-3 o_light_label"
/>
<field
name=
"baidu_ocr_api_key"
/>
</div>
<div
class=
"row"
>
<label
for=
"baidu_ocr_secret_key"
string=
"Secret Key"
class=
"col-lg-3 o_light_label"
/>
<field
name=
"baidu_ocr_secret_key"
password=
"True"
/>
</div>
</div>
</div>
</div>
<!-- 超时与重试设置 -->
<div
class=
"col-12 col-lg-6 o_setting_box"
attrs=
"{'invisible': [('ocr_enabled', '=', False)]}"
>
<div
class=
"o_setting_right_pane"
>
<div
class=
"text-muted"
>
<label
for=
"ocr_timeout"
string=
"超时时间(秒)"
/>
<field
name=
"ocr_timeout"
style=
"width: 50px;"
/>
</div>
<div
class=
"text-muted"
>
<label
for=
"ocr_max_retries"
string=
"最大重试次数"
/>
<field
name=
"ocr_max_retries"
style=
"width: 50px;"
/>
</div>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
</data>
</odoo>
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论