前置三次元检测数据读取
This commit is contained in:
@@ -8,6 +8,7 @@ from datetime import datetime, timedelta
|
|||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
import math
|
import math
|
||||||
|
from lxml import etree
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
# import subprocess
|
# import subprocess
|
||||||
from odoo import api, fields, models, SUPERUSER_ID, _
|
from odoo import api, fields, models, SUPERUSER_ID, _
|
||||||
@@ -115,6 +116,17 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
processing_user_id = fields.Many2one('res.users', string='加工人')
|
processing_user_id = fields.Many2one('res.users', string='加工人')
|
||||||
# 检测人
|
# 检测人
|
||||||
inspection_user_id = fields.Many2one('res.users', string='检测人')
|
inspection_user_id = fields.Many2one('res.users', string='检测人')
|
||||||
|
# 保存名称
|
||||||
|
save_name = fields.Char(string='检测文件保存名称', compute='_compute_save_name')
|
||||||
|
|
||||||
|
@api.depends('production_id')
|
||||||
|
def _compute_save_name(self):
|
||||||
|
"""
|
||||||
|
保存名称
|
||||||
|
"""
|
||||||
|
for record in self:
|
||||||
|
record.save_name = record.production_id.name.replace('/', '_')
|
||||||
|
|
||||||
schedule_state = fields.Selection(related='production_id.schedule_state', store=True)
|
schedule_state = fields.Selection(related='production_id.schedule_state', store=True)
|
||||||
# 工件装夹信息
|
# 工件装夹信息
|
||||||
functional_fixture_code = fields.Char(string="功能夹具编码", readonly=True)
|
functional_fixture_code = fields.Char(string="功能夹具编码", readonly=True)
|
||||||
@@ -187,6 +199,143 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', production_id)])
|
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', production_id)])
|
||||||
return process_parameter_workorder
|
return process_parameter_workorder
|
||||||
|
|
||||||
|
# 获取三次元检测点数据
|
||||||
|
def get_three_check_datas(self):
|
||||||
|
factory_nick_name = 'XT'
|
||||||
|
ftp_resconfig = self.env['res.config.settings'].get_values()
|
||||||
|
ftp = FtpController(str(ftp_resconfig['ftp_host']), int(ftp_resconfig['ftp_port']),
|
||||||
|
ftp_resconfig['ftp_user'],
|
||||||
|
ftp_resconfig['ftp_password'])
|
||||||
|
# ftp.connect()
|
||||||
|
|
||||||
|
local_dir_path = '/ftp/before'
|
||||||
|
os.makedirs(local_dir_path, exist_ok=True)
|
||||||
|
local_filename = 'WH_MO_00099.xls'
|
||||||
|
local_file_path = os.path.join(local_dir_path, local_filename)
|
||||||
|
logging.info('local_file_path:%s' % local_file_path)
|
||||||
|
remote_path = '/home/ftp/ftp_root/ThreeTest/XT/Before/WH_MO_00099.xls'
|
||||||
|
|
||||||
|
with open(local_file_path, 'wb') as local_file:
|
||||||
|
ftp.ftp.retrbinary('RETR ' + remote_path, local_file.write)
|
||||||
|
logging.info('下载文件成功')
|
||||||
|
# 解析本地文件
|
||||||
|
# file_path = 'WH_MO_00099.xls' # 使用下载的实际文件路径
|
||||||
|
parser = etree.XMLParser(recover=True) # Using recover to handle errors
|
||||||
|
tree = etree.parse(local_file_path, parser)
|
||||||
|
logging.info('tree:%s' % tree)
|
||||||
|
root = tree.getroot()
|
||||||
|
logging.info('root:%s' % root)
|
||||||
|
|
||||||
|
# 准备一个外部字典来存储以PT为键的坐标字典
|
||||||
|
pt_coordinates = {}
|
||||||
|
# 遍历每个工作表和行
|
||||||
|
for worksheet in root.iterfind('.//{urn:schemas-microsoft-com:office:spreadsheet}Worksheet'):
|
||||||
|
sheet_name = worksheet.attrib.get('{urn:schemas-microsoft-com:office:spreadsheet}Name')
|
||||||
|
logging.info('sheet_name:%s' % sheet_name)
|
||||||
|
if sheet_name == "Sheet1": # 确保我们只查看包含数据的工作表
|
||||||
|
current_pt = None
|
||||||
|
for row in worksheet.iterfind('.//{urn:schemas-microsoft-com:office:spreadsheet}Row'):
|
||||||
|
cells = list(row.iterfind('.//{urn:schemas-microsoft-com:office:spreadsheet}Cell'))
|
||||||
|
for i, cell in enumerate(cells):
|
||||||
|
data_cell = cell.find('.//{urn:schemas-microsoft-com:office:spreadsheet}Data')
|
||||||
|
if data_cell is not None and data_cell.text is not None: # 添加检查以确保data_cell.text不为空
|
||||||
|
# 检查是否是PT标识
|
||||||
|
logging.info(f"Data in cell: {data_cell.text}") # 输出单元格数据
|
||||||
|
if "PT" in data_cell.text:
|
||||||
|
current_pt = data_cell.text
|
||||||
|
pt_coordinates[current_pt] = []
|
||||||
|
elif data_cell.text in ["X", "Y", "Z"] and current_pt is not None:
|
||||||
|
# 确保当前单元格后面还有单元格存在,以获取理论值
|
||||||
|
if i + 1 < len(cells):
|
||||||
|
next_cell = cells[i + 1]
|
||||||
|
theory_value = next_cell.find(
|
||||||
|
'.//{urn:schemas-microsoft-com:office:spreadsheet}Data')
|
||||||
|
if theory_value is not None:
|
||||||
|
# 为当前PT键添加坐标数据
|
||||||
|
pt_coordinates[current_pt].append({
|
||||||
|
data_cell.text: float(theory_value.text)
|
||||||
|
})
|
||||||
|
logging.info(f"PT: {current_pt} - {data_cell.text}: {theory_value.text}")
|
||||||
|
logging.info('pt_coordinates=====%s' % pt_coordinates)
|
||||||
|
# pt_coordinates:{'PT1': [{'X': 38.9221}, {'Y': -18.7304}, {'Z': 128.0783}],
|
||||||
|
# 'PT2': [{'X': 39.2456}, {'Y': -76.9169}, {'Z': 123.7541}]}
|
||||||
|
|
||||||
|
# 检查是否存在PT1等键
|
||||||
|
if 'PT1' in pt_coordinates and pt_coordinates['PT1']:
|
||||||
|
self.X1_axis = pt_coordinates['PT1'][0]['X']
|
||||||
|
self.Y1_axis = pt_coordinates['PT1'][1]['Y']
|
||||||
|
self.Z1_axis = pt_coordinates['PT1'][2]['Z']
|
||||||
|
else:
|
||||||
|
raise UserError('PT1点未测或数据错误')
|
||||||
|
if 'PT2' in pt_coordinates and pt_coordinates['PT2']:
|
||||||
|
self.X2_axis = pt_coordinates['PT2'][0]['X']
|
||||||
|
self.Y2_axis = pt_coordinates['PT2'][1]['Y']
|
||||||
|
self.Z2_axis = pt_coordinates['PT2'][2]['Z']
|
||||||
|
else:
|
||||||
|
raise UserError('PT2点未测或数据错误')
|
||||||
|
if 'PT3' in pt_coordinates and pt_coordinates['PT3']:
|
||||||
|
self.X3_axis = pt_coordinates['PT3'][0]['X']
|
||||||
|
self.Y3_axis = pt_coordinates['PT3'][1]['Y']
|
||||||
|
self.Z3_axis = pt_coordinates['PT3'][2]['Z']
|
||||||
|
else:
|
||||||
|
raise UserError('PT3点未测或数据错误')
|
||||||
|
if 'PT4' in pt_coordinates and pt_coordinates['PT4']:
|
||||||
|
self.X4_axis = pt_coordinates['PT4'][0]['X']
|
||||||
|
self.Y4_axis = pt_coordinates['PT4'][1]['Y']
|
||||||
|
self.Z4_axis = pt_coordinates['PT4'][2]['Z']
|
||||||
|
else:
|
||||||
|
raise UserError('PT4点未测或数据错误')
|
||||||
|
if 'PT5' in pt_coordinates and pt_coordinates['PT5']:
|
||||||
|
self.X5_axis = pt_coordinates['PT5'][0]['X']
|
||||||
|
self.Y5_axis = pt_coordinates['PT5'][1]['Y']
|
||||||
|
self.Z5_axis = pt_coordinates['PT5'][2]['Z']
|
||||||
|
else:
|
||||||
|
raise UserError('PT5点未测或数据错误')
|
||||||
|
if 'PT6' in pt_coordinates and pt_coordinates['PT6']:
|
||||||
|
self.X6_axis = pt_coordinates['PT6'][0]['X']
|
||||||
|
self.Y6_axis = pt_coordinates['PT6'][1]['Y']
|
||||||
|
self.Z6_axis = pt_coordinates['PT6'][2]['Z']
|
||||||
|
else:
|
||||||
|
raise UserError('PT6点未测或数据错误')
|
||||||
|
if 'PT7' in pt_coordinates and pt_coordinates['PT7']:
|
||||||
|
self.X7_axis = pt_coordinates['PT7'][0]['X']
|
||||||
|
self.Y7_axis = pt_coordinates['PT7'][1]['Y']
|
||||||
|
self.Z7_axis = pt_coordinates['PT7'][2]['Z']
|
||||||
|
else:
|
||||||
|
raise UserError('PT7点未测或数据错误')
|
||||||
|
if 'PT8' in pt_coordinates and pt_coordinates['PT8']:
|
||||||
|
self.X8_axis = pt_coordinates['PT8'][0]['X']
|
||||||
|
self.Y8_axis = pt_coordinates['PT8'][1]['Y']
|
||||||
|
self.Z8_axis = pt_coordinates['PT8'][2]['Z']
|
||||||
|
else:
|
||||||
|
raise UserError('PT8点未测或数据错误')
|
||||||
|
if 'PT9' in pt_coordinates and pt_coordinates['PT9']:
|
||||||
|
self.X9_axis = pt_coordinates['PT9'][0]['X']
|
||||||
|
self.Y9_axis = pt_coordinates['PT9'][1]['Y']
|
||||||
|
self.Z9_axis = pt_coordinates['PT9'][2]['Z']
|
||||||
|
else:
|
||||||
|
raise UserError('PT9点未测或数据错误')
|
||||||
|
if 'PT10' in pt_coordinates and pt_coordinates['PT10']:
|
||||||
|
self.X10_axis = pt_coordinates['PT10'][0]['X']
|
||||||
|
self.Y10_axis = pt_coordinates['PT10'][1]['Y']
|
||||||
|
self.Z10_axis = pt_coordinates['PT10'][2]['Z']
|
||||||
|
else:
|
||||||
|
raise UserError('PT10点未测或数据错误')
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
# ftp.download_file('three_check_datas.xls', '/home/ftpuser/three_check_datas.xls')
|
||||||
|
# ftp.close()
|
||||||
|
# data = xlrd.open_workbook('/home/ftpuser/three_check_datas.xls')
|
||||||
|
# table = data.sheets()[0]
|
||||||
|
# nrows = table.nrows
|
||||||
|
# # 点坐标列表
|
||||||
|
# point_list = []
|
||||||
|
# datas = []
|
||||||
|
# for i in range(1, nrows):
|
||||||
|
# datas.append(table.row_values(i))
|
||||||
|
# return datas
|
||||||
|
|
||||||
# 计算配料中心点和与x轴倾斜度方法
|
# 计算配料中心点和与x轴倾斜度方法
|
||||||
def getcenter(self):
|
def getcenter(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -403,6 +403,10 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-12 col-lg-6 o_setting_box">
|
<div class="col-12 col-lg-6 o_setting_box">
|
||||||
|
<button type="object" class="oe_highlight" name="get_three_check_datas" string="获取数据"
|
||||||
|
attrs='{"invisible": ["|","|",("material_center_point","!=",False),("state","!=","progress"),("user_permissions","=",False)]}'/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
<button type="object" class="oe_highlight" name="getcenter" string="计算定位"
|
<button type="object" class="oe_highlight" name="getcenter" string="计算定位"
|
||||||
attrs='{"invisible": ["|","|",("material_center_point","!=",False),("state","!=","progress"),("user_permissions","=",False)]}'/>
|
attrs='{"invisible": ["|","|",("material_center_point","!=",False),("state","!=","progress"),("user_permissions","=",False)]}'/>
|
||||||
</div>
|
</div>
|
||||||
@@ -517,6 +521,7 @@
|
|||||||
<field name="is_ok"/>
|
<field name="is_ok"/>
|
||||||
<field name="processing_user_id"/>
|
<field name="processing_user_id"/>
|
||||||
<field name="inspection_user_id"/>
|
<field name="inspection_user_id"/>
|
||||||
|
<field name="save_name" widget="CopyClipboardChar"/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
Reference in New Issue
Block a user