Merge branch 'feature/从ftp获取cnc程序文件' into develop
# Conflicts: # sf_manufacturing/models/mrp_workorder.py
This commit is contained in:
@@ -27,7 +27,7 @@ class Http(models.AbstractModel):
|
|||||||
raise AuthenticationError('无效的token')
|
raise AuthenticationError('无效的token')
|
||||||
timestamp_str = int(time.time())
|
timestamp_str = int(time.time())
|
||||||
# 设置API接口请求时间,不能超过5秒
|
# 设置API接口请求时间,不能超过5秒
|
||||||
deltime = datetime.timedelta(seconds=60)
|
deltime = datetime.timedelta(seconds=5)
|
||||||
if abs(int(datas['HTTP_TIMESTAMP'])-timestamp_str) > deltime.seconds:
|
if abs(int(datas['HTTP_TIMESTAMP'])-timestamp_str) > deltime.seconds:
|
||||||
raise AuthenticationError('请求已过期')
|
raise AuthenticationError('请求已过期')
|
||||||
# 获得sha1_str加密字符串
|
# 获得sha1_str加密字符串
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
|
import os
|
||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import logging
|
import logging
|
||||||
|
import base64
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from odoo import api, fields, models, SUPERUSER_ID, _
|
from odoo import api, fields, models, SUPERUSER_ID, _
|
||||||
<<<<<<< HEAD
|
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
from odoo.addons.sf_base.commons.common import Common
|
from odoo.addons.sf_base.commons.common import Common
|
||||||
=======
|
|
||||||
from odoo.addons.sf_base.commons.common import Common
|
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
>>>>>>> b2d1e9ce8c5d8965ed09c3fbd6de543708223487
|
from odoo.addons.sf_mrs_connect.models.ftp_operate import FtpController
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ResMrpWorkOrder(models.Model):
|
class ResMrpWorkOrder(models.Model):
|
||||||
@@ -347,7 +346,7 @@ class CNCprocessing(models.Model):
|
|||||||
workorder = self.env['mrp.workorder'].search([('production_id.name', '=', obj['manufacturing_order_no']),
|
workorder = self.env['mrp.workorder'].search([('production_id.name', '=', obj['manufacturing_order_no']),
|
||||||
('processing_panel', '=', obj['processing_panel']),
|
('processing_panel', '=', obj['processing_panel']),
|
||||||
('routing_type', '=', 'CNC加工')])
|
('routing_type', '=', 'CNC加工')])
|
||||||
self.env['sf.cnc.processing'].create({
|
vals = {
|
||||||
'workorder_id': workorder.id,
|
'workorder_id': workorder.id,
|
||||||
'sequence_number': obj['sequence_number'],
|
'sequence_number': obj['sequence_number'],
|
||||||
'program_name': obj['program_name'],
|
'program_name': obj['program_name'],
|
||||||
@@ -359,9 +358,37 @@ class CNCprocessing(models.Model):
|
|||||||
'depth_of_processing_z': obj['depth_of_processing_z'],
|
'depth_of_processing_z': obj['depth_of_processing_z'],
|
||||||
'cutting_tool_extension_length': obj['cutting_tool_extension_length'],
|
'cutting_tool_extension_length': obj['cutting_tool_extension_length'],
|
||||||
'cutting_tool_handle_type': obj['cutting_tool_handle_type'],
|
'cutting_tool_handle_type': obj['cutting_tool_handle_type'],
|
||||||
|
'estimated_processing_time': obj['estimated_processing_time'],
|
||||||
'remark': obj['remark']
|
'remark': obj['remark']
|
||||||
# 'FJGDate': obj['']
|
}
|
||||||
|
return self.env['sf.cnc.processing'].create(vals)
|
||||||
|
|
||||||
|
def attachment_create(self, name, data):
|
||||||
|
attachment = self.env['ir.attachment'].create({
|
||||||
|
'datas': base64.b64encode(data),
|
||||||
|
'type': 'binary',
|
||||||
|
'description': '程序文件',
|
||||||
|
'name': name
|
||||||
})
|
})
|
||||||
|
return attachment
|
||||||
|
|
||||||
|
def download_file_tmp(self, model_code, processing_panel):
|
||||||
|
remotepath = os.path.join('/', model_code, 'return', processing_panel)
|
||||||
|
serverdir = os.path.join('/tmp', model_code, 'return', processing_panel)
|
||||||
|
ftp = FtpController()
|
||||||
|
ftp.download_file_tree(remotepath, serverdir)
|
||||||
|
return serverdir
|
||||||
|
|
||||||
|
def write_file(self, nc_file_path, cnc):
|
||||||
|
if os.path.exists(nc_file_path):
|
||||||
|
with open(nc_file_path, 'rb') as file:
|
||||||
|
data_bytes = file.read()
|
||||||
|
attachment = self.attachment_create(cnc.program_name + '.NC', data_bytes)
|
||||||
|
cnc.write({'cnc_id': attachment.id})
|
||||||
|
file.close()
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class SfWorkOrderBarcodes(models.Model):
|
class SfWorkOrderBarcodes(models.Model):
|
||||||
"""
|
"""
|
||||||
@@ -371,9 +398,8 @@ class SfWorkOrderBarcodes(models.Model):
|
|||||||
_inherit = ["mrp.workorder", "barcodes.barcode_events_mixin"]
|
_inherit = ["mrp.workorder", "barcodes.barcode_events_mixin"]
|
||||||
|
|
||||||
def on_barcode_scanned(self, barcode):
|
def on_barcode_scanned(self, barcode):
|
||||||
|
|
||||||
tray_code = self.env['sf.tray'].search([('code', '=', barcode)])
|
tray_code = self.env['sf.tray'].search([('code', '=', barcode)])
|
||||||
self.tray_code = tray_code.code
|
self.tray_code = tray_code.code
|
||||||
|
|
||||||
workorder = self.env['mrp.workorder'].browse(self.ids)
|
workorder = self.env['mrp.workorder'].browse(self.ids)
|
||||||
workorder.gettray_auto(barcode)
|
workorder.gettray_auto(barcode)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
from odoo import http
|
from odoo import http
|
||||||
from odoo.http import request
|
from odoo.http import request
|
||||||
@@ -22,6 +23,12 @@ class Sf_Mrs_Connect(http.Controller):
|
|||||||
ret = json.loads(datas)
|
ret = json.loads(datas)
|
||||||
ret = json.loads(ret['result'])
|
ret = json.loads(ret['result'])
|
||||||
for obj in ret:
|
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:
|
except Exception as e:
|
||||||
logging.info('get_cnc_processing_create error:%s' % 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 res_config_setting
|
||||||
from . import sync_common
|
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