Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dwsproject
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dws
dwsproject
Commits
9b18504f
Commit
9b18504f
authored
Mar 14, 2025
by
夏超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[fix] 同步功能优化
parent
77a9ae74
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
1 deletions
+83
-1
sdddl_project/__manifest__.py
+2
-1
sdddl_project/models/__init__.py
+1
-0
sdddl_project/models/inherit_roke_pub_interate_model.py
+80
-0
No files found.
sdddl_project/__manifest__.py
View file @
9b18504f
...
@@ -4,7 +4,8 @@
...
@@ -4,7 +4,8 @@
'version'
:
'14.0'
,
'version'
:
'14.0'
,
'category'
:
'mes'
,
'category'
:
'mes'
,
'depends'
:
[
'roke_mes_purchase'
,
'roke_mes_sale'
,
'roke_mes_documents'
,
'roke_mes_stock'
,
'roke_workstation_api'
,
'depends'
:
[
'roke_mes_purchase'
,
'roke_mes_sale'
,
'roke_mes_documents'
,
'roke_mes_stock'
,
'roke_workstation_api'
,
'roke_mes_workshop_inspect'
,
'roke_mes_quality'
,
'roke_mes_entrust_order'
,
"roke_workstation_sync_ps"
],
'roke_mes_workshop_inspect'
,
'roke_mes_quality'
,
'roke_mes_entrust_order'
,
"roke_workstation_sync_ps"
,
'roke_pub_integrate'
],
'author'
:
'www.rokedata.com'
,
'author'
:
'www.rokedata.com'
,
'website'
:
'http://www.rokedata.com'
,
'website'
:
'http://www.rokedata.com'
,
'description'
:
"""
'description'
:
"""
...
...
sdddl_project/models/__init__.py
View file @
9b18504f
...
@@ -3,3 +3,4 @@ from . import inherit_production_task
...
@@ -3,3 +3,4 @@ from . import inherit_production_task
from
.
import
inherit_roke_routing
from
.
import
inherit_roke_routing
from
.
import
inherit_roke_product
from
.
import
inherit_roke_product
from
.
import
inherit_roke_process
from
.
import
inherit_roke_process
from
.
import
inherit_roke_pub_interate_model
sdddl_project/models/inherit_roke_pub_interate_model.py
0 → 100644
View file @
9b18504f
import
requests
from
odoo
import
models
,
fields
,
api
,
_
from
odoo.exceptions
import
UserError
import
psycopg2
,
pymssql
,
cx_Oracle
import
json
import
logging
import
datetime
_logger
=
logging
.
getLogger
(
__name__
)
class
RokePubIntegrateModel
(
models
.
Model
):
_inherit
=
"roke.pub.integrate.model"
time_type
=
fields
.
Selection
(
selection_add
=
[(
"YMD"
,
"YMD"
)],
string
=
"时间类型"
)
def
sync_pull_database
(
self
,
**
kwargs
):
_logger
.
info
(
"----------------------******数据库直连下拉数据******----------------------"
)
sync_address
=
self
.
system_id
.
sync_address
sync_port
=
self
.
system_id
.
sync_port
sync_uname
=
self
.
system_id
.
sync_uname
sync_passwd
=
self
.
system_id
.
sync_passwd
db_name
=
self
.
system_id
.
db_name
if
self
.
db_type
==
'PostgreSQL'
:
conn
=
psycopg2
.
connect
(
host
=
sync_address
,
port
=
int
(
sync_port
),
user
=
sync_uname
,
password
=
sync_passwd
,
database
=
db_name
)
cur
=
conn
.
cursor
()
elif
self
.
db_type
==
'Microsoft SQL Server'
:
# conn = pymssql.connect(host="%s:%s" % (sync_address, sync_port), user=sync_uname, password=sync_passwd, database=db_name)
conn
=
pymssql
.
connect
(
host
=
sync_address
,
user
=
sync_uname
,
password
=
sync_passwd
,
database
=
db_name
)
cur
=
conn
.
cursor
()
elif
self
.
db_type
==
'oracle'
:
conn
=
cx_Oracle
.
connect
(
sync_uname
,
sync_passwd
,
'
%
s:
%
s/ORCL'
%
(
sync_address
,
sync_port
))
cur
=
conn
.
cursor
()
else
:
raise
UserError
(
'非预制类型'
)
wheresql
=
""
# 时间轴字段where条件拼接
if
self
.
sync_mode
==
"时间轴"
and
self
.
time_axis_field
and
self
.
last_execute_time
:
if
self
.
time_type
==
"Y-M-D H:M:S"
:
wheresql
+=
" and
%
s >= '
%
s'"
%
(
self
.
time_axis_field
,
self
.
last_execute_time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
))
elif
self
.
time_type
==
"YMD HMS"
:
wheresql
+=
" and
%
s >= '
%
s'"
%
(
self
.
time_axis_field
,
self
.
last_execute_time
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
))
else
:
wheresql
+=
" and
%
s >=
%
s"
%
(
self
.
time_axis_field
,
self
.
last_execute_time
.
strftime
(
"
%
Y
%
m
%
d"
))
# 填写的where条件拼接
if
self
.
where_sql
:
wheresql
+=
self
.
where_sql
# 入参where条件拼接
for
integrate_input
in
self
.
integrate_input_ids
:
if
integrate_input
.
is_required
and
not
integrate_input
.
fixed
:
if
not
kwargs
.
get
(
integrate_input
.
enter_name
):
raise
UserError
(
"入参[
%
s]必填!"
%
integrate_input
.
enter_name
)
wheresql
+=
" and
%
s='
%
s'"
%
(
integrate_input
.
enter_name
,
kwargs
.
get
(
integrate_input
.
enter_name
))
else
:
if
integrate_input
.
fixed
:
wheresql
+=
" and
%
s='
%
s'"
%
(
integrate_input
.
enter_name
,
integrate_input
.
enter_data
)
# 拼接查询字段
select_field
=
""
for
integrate_field
in
self
.
integrate_field_ids
:
if
not
integrate_field
.
fixed
:
select_field
+=
"
%
s, "
%
integrate_field
.
opposite_field_name
select_field
=
select_field
[:
-
2
]
cur
.
execute
(
"select {} from {} where 1=1 {}"
.
format
(
select_field
,
self
.
opposite_model
,
wheresql
))
rows
=
cur
.
fetchall
()
rowdesc
=
cur
.
description
data_dicts
=
[
dict
(
zip
([
col
[
0
]
for
col
in
rowdesc
],
row
))
for
row
in
rows
]
cur
.
close
()
conn
.
close
()
self
.
sync_analysis_database
(
data_dicts
)
if
self
.
logging_enable
:
self
.
env
[
"roke.pub.integrate.log"
]
.
create
({
"requst_parameter"
:
wheresql
,
"response_result"
:
str
(
data_dicts
),
"integrate_model_id"
:
self
.
id
,
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment