# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. import base64 import psycopg2 import os import logging from zeep.exceptions import ValidationError from odoo import http from ftplib import FTP from odoo.http import request from odoo import api, fields, models from odoo.addons.sf_machine_connect.models import py2opcua, ftp_operate # from .ftp_operate import FtpController # from .py2opcua import Py2opcua _logger = logging.getLogger(__name__) # ---------------------------------------------------------- # Models for client # ---------------------------------------------------------- class FtpButton(models.Model): _inherit = 'sf.cnc.processing' def pri(self): print('11111111111111111') s = self.cnc_id s1 = self.cnc_id._filestore() print(s1) v = self.cnc_id.display_name a = self.cnc_id.datas print(v) print(a) ftp_operate.FtpController.prin(self) def up(self): # self.env['mrp.workorder'].check_compensation_before_up() ftp = ftp_operate.FtpController() # ftp.delAllfile('C://Users//马广威//Desktop//ftp') a = self.cnc_id print(a.display_name) _logger.info(a.display_name) datas = base64.standard_b64decode(a.datas) # file_path = '{}\{}\{}'.format(a._filestore(), a.store_fname.split('/'[0]), a.display_name) # 此方法不走ftp,直接文件写入,暂不确定能否写入ftp服务器,但可以转成ftp方法,只是要把文件暂存到本地,再上传 # file_path_local = '{}\{}'.format('C://Users//马广威//Desktop//ftp', a.display_name) file_path_local = '{}/{}'.format('/nc2machine', a.display_name) file_path_remote = '{}\{}'.format('//(192,168,2,141)//DS', a.display_name) with open(file_path_local, mode='wb+') as file: file.write(datas) # file = open(file_path_local, 'wb+') # file.write(datas) # file.close() # 存在本地的文件下发到机床 ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local) class FtpClient(models.Model): _name = "ftp.client" _description = 'Ftp Client' name = fields.Char('Name', size=50, readonly=True) description = fields.Char(size=50) mobile = fields.Char(size=50) def up(self): ftp = ftp_operate.FtpController() # FtpController.__init__(self, host="127.0.0.1", port=2121, username="admin", password="123456") ftp.upload_file(remotepath='/(192,168,199,2)/DS/02-222.NC', localpath='D:/ftp/up/02-222.NC') # def delete(self): # ftp = FtpController() # ftp.del_file() # # def _compute_ip_url(self): # for box in self: # if not box.ip: # box.ip_url = False # else: # url = 'https://%s' if box.get_base_url()[:5] == 'https' else 'http://%s:8069' # box.ip_url = url % box.ip # # def _compute_device_count(self): # for box in self: # box.device_count = len(box.device_ids) class Machine_ftp(models.Model): # _name = 'data.collection' _inherit = 'sf.machine_tool' timestamp = fields.Datetime('时间戳', readonly=True) signed = fields.Integer('刷新间隔', readonly=True) status = fields.Boolean('在线状态', readonly=True) tool_num = fields.Integer('当前刀具', readonly=True) program = fields.Char('当前程序', readonly=True) class WorkCenterBarcode(models.Model): """ 扫码托盘码可查到制造订单,由制造订单查工单 """ _inherit = "mrp.workorder" compensation_value_x = fields.Float(string='X轴补偿值') compensation_value_y = fields.Float(string='Y轴补偿值') def compensation(self): ''' 将节点与其值放入字典,字典作为参数传入 :return: ''' temp_dict = {} temp_dict['ns=1;s=Project_Default.Group1.Mitsubishi_NC.hongbianliang520'] = self.compensation_value_x temp_dict['ns=1;s=Project_Default.Group1.Mitsubishi_NC.hongbianliang521'] = self.compensation_value_y print("测试补偿能够执行") temp = py2opcua.Py2opcua() _logger.info(temp) temp.connect() temp.write(temp_dict) temp.disconnect() def check_compensation_before_up(self): temp_value = self.env['mrp.workorder'].getcenter() _logger.info("====================================================================================") _logger.info(temp_value) if temp_value[0] == 0 or temp_value[1] != 0: temp_dict = {} # temp_dict['ns=1;s=Project_Default.Group1.Mitsubishi_NC.hongbianliang520'] = temp_value[0] temp_dict['ns=1;s=Project_Default.Group1.Mitsubishi_NC.hongbianliang520'] = 111 temp_dict['ns=1;s=Project_Default.Group1.Mitsubishi_NC.hongbianliang521'] = 111 # temp_dict['ns=1;s=Project_Default.Group1.Mitsubishi_NC.hongbianliang521'] = temp_value[1] print("测试补偿能够执行") temp = py2opcua.Py2opcua() _logger.info(temp) temp.connect() temp.write(temp_dict) temp.disconnect() def test(self, barcode): # 托盘对象 tray = self.env('sf.tray').search("code", "=", barcode) product = tray.product_id