Merge branch 'feature/从ftp获取cnc程序文件' into develop
# Conflicts: # sf_manufacturing/models/mrp_workorder.py
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from datetime import date, timedelta
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
@@ -22,6 +23,12 @@ class Sf_Mrs_Connect(http.Controller):
|
||||
ret = json.loads(datas)
|
||||
ret = json.loads(ret['result'])
|
||||
for obj in ret:
|
||||
request.env['sf.cnc.processing'].with_user(request.env.ref("base.user_admin")).CNCprocessing_create(obj)
|
||||
cnc = request.env['sf.cnc.processing'].with_user(request.env.ref("base.user_admin")).CNCprocessing_create(obj)
|
||||
# 从ftp拉取对应的文件
|
||||
model_code = cnc.workorder_id.product_id.barcode
|
||||
processing_panel = cnc.workorder_id.processing_panel
|
||||
server_dir = cnc.with_user(request.env.ref("base.user_admin")).download_file_tmp(model_code, processing_panel)
|
||||
cnc_file_path = os.path.join(server_dir, cnc.program_name + '.NC')
|
||||
cnc.with_user(request.env.ref("base.user_admin")).write_file(cnc_file_path, cnc)
|
||||
except Exception as e:
|
||||
logging.info('get_cnc_processing_create error:%s' % e)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from . import ftp_operate
|
||||
from . import res_config_setting
|
||||
from . import sync_common
|
||||
|
||||
|
||||
43
sf_mrs_connect/models/ftp_operate.py
Normal file
43
sf_mrs_connect/models/ftp_operate.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import posixpath
|
||||
from odoo.modules import get_resource_path
|
||||
from ftplib import FTP
|
||||
import logging
|
||||
|
||||
|
||||
# FTP接口类
|
||||
class FtpController():
|
||||
'''
|
||||
这是ftp接口类,在类初始化的时候就连接了ftp服务器,能否成功连接有反馈。
|
||||
类中定义了两个接口:上传接口和删除接口
|
||||
'''
|
||||
|
||||
ftp = FTP()
|
||||
|
||||
def __init__(self, host="192.168.50.202", port=21, username="ftpuser", password="123456"):
|
||||
try:
|
||||
self.ftp.connect(host, port)
|
||||
self.ftp.login(username, password)
|
||||
except:
|
||||
logging.info("连接失败: ")
|
||||
|
||||
# 下载目录下的文件
|
||||
def download_file_tree(self, remotepath, serverdir):
|
||||
if not os.path.exists(serverdir):
|
||||
os.makedirs(serverdir)
|
||||
self.ftp.cwd(remotepath)
|
||||
remotenames = self.ftp.nlst()
|
||||
for file in remotenames:
|
||||
server = os.path.join(serverdir, file)
|
||||
if file.find(".") != -1:
|
||||
self.download_file(server, file)
|
||||
else:
|
||||
return False
|
||||
|
||||
# 下载指定目录下的指定文件
|
||||
def download_file(self, serverfile, remotefile):
|
||||
file_handler = open(serverfile, 'wb')
|
||||
self.ftp.retrbinary('RETR ' + remotefile, file_handler.write)
|
||||
file_handler.close()
|
||||
|
||||
Reference in New Issue
Block a user