From 24afa53028ee25948314c79dfbf2aba9cc886086 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Wed, 2 Aug 2023 17:35:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD=E5=A4=B9?= =?UTF-8?q?=E5=85=B7=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/models/fixture.py | 171 +--------------------- sf_base/models/functional_fixture.py | 18 ++- sf_base/views/fixture_view.xml | 8 +- sf_base/views/functional_fixture_view.xml | 5 + 4 files changed, 18 insertions(+), 184 deletions(-) diff --git a/sf_base/models/fixture.py b/sf_base/models/fixture.py index 78b1eb9e..d929cad9 100644 --- a/sf_base/models/fixture.py +++ b/sf_base/models/fixture.py @@ -1,14 +1,8 @@ from odoo import models, fields, api -from odoo.modules import get_resource_path -# from OCC.Extend.DataExchange import read_step_file -# from OCC.Extend.DataExchange import write_stl_file from odoo.addons.sf_base.commons.common import Common from odoo.exceptions import ValidationError import requests import json -import logging -import base64 -import hashlib class FixtureMaterial(models.Model): @@ -36,6 +30,7 @@ class FixtureModel(models.Model): _name = 'sf.fixture.model' _description = "夹具型号" + code = fields.Char(string='编码') name = fields.Char(string="名称", size=15) fixture_material_id = fields.Many2one('sf.fixture.material', string="夹具物料", ) fixture_material_type = fields.Char(string="夹具物料类型", related='fixture_material_id.name', store=True) @@ -61,169 +56,5 @@ class FixtureModel(models.Model): string="适用机床型号") through_hole_size = fields.Integer(string="过孔大小[mm]", size=6) screw_size = fields.Integer(string="螺牙大小[mm]", size=6) - upload_model_file = fields.Many2many('ir.attachment', 'upload_fixture_model_file_attachment_ref', string='上传模型文件') - - def _get_code(self, fixture_model_type_code): - fixture_model = self.env['sf.fixture.model'].sudo().search( - [('code', 'ilike', fixture_model_type_code)], - limit=1, - order="id desc") - if not fixture_model: - num = "%03d" % 1 - else: - m = int(fixture_model.code[-3:]) + 1 - num = "%03d" % m - return "%s%s" % (fixture_model_type_code, num) - - code = fields.Char(string='编码', readonly=True) - - @api.model - def create(self, vals): - if vals.get('upload_model_file'): - logging.info('create-attachment:%s' % vals['upload_model_file'][0]) - for item in vals['upload_model_file']: - print(len(item[2])) - if len(item[2]) > 0: - logging.info('create-attachment:%s' % int(item[2][0])) - attachment = self.env['ir.attachment'].sudo().search([('id', '=', int(item[2][0]))]) - base64_data = base64.b64encode(attachment.datas) - base64_datas = base64_data.decode('utf-8') - model_code = hashlib.sha1(base64_datas.encode('utf-8')).hexdigest() - report_path = attachment._full_path(attachment.store_fname) - vals['model_file'] = self.transition_glb_file(report_path, model_code) - logging.info('create-model_file:%s' % len(vals['model_file'])) - obj = super(FixtureModel, self).create(vals) - return obj - - # 将attach的datas内容转为glb文件 - def transition_glb_file(self, report_path, model_code): - shapes = read_step_file(report_path) - # output_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.stl') - # output_file = os.path.join('/tmp', str(model_code) + '.stl') - # write_stl_file(shapes, output_file, 'binary', 0.03, 0.5) - # # 转化为glb - # # output_glb_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.glb') - # output_glb_file = os.path.join('/tmp', str(model_code) + '.glb') - # util_path = get_resource_path('mrs_base', 'static/util') - # cmd = 'python3 %s/stl2gltf.py %s %s -b' % (util_path, output_file, output_glb_file) - # os.system(cmd) - # # 转base64 - # with open(output_glb_file, 'rb') as fileObj: - # image_data = fileObj.read() - # base64_data = base64.b64encode(image_data) - # return base64_data - return False - - @api.onchange('brand_id') - def _onchange_brand_id(self): - if self.brand_id: - self.manufacturer_model_number = self.brand_id.manufacturer_model_number - - def name_get(self): - result = [] - for parameter in self: - if parameter.fixture_material_type in ['虎钳托盘', '零点卡盘']: - if parameter.driving_way: - name = parameter.multi_mounting_type_id.name + '-' + parameter.driving_way + '-' + parameter.name - else: - name = parameter.multi_mounting_type_id.name + '-' + parameter.name - else: - name = parameter.multi_mounting_type_id.name + '-' + parameter.name - result.append((parameter.id, name)) - return result - - @api.onchange('fixture_material_id') - def _onchange_fixture_material_id(self): - if self.fixture_material_id: - if self.fixture_material_id.name == "气动托盘": - self.code = self._get_code("JKM-C-JJWL-QDTP-") - elif self.fixture_material_id.name == "转接板(锁板)托盘": - self.code = self._get_code("JKM-C-JJWL-ZJBTP-") - elif self.fixture_material_id.name == "磁吸托盘": - self.code = self._get_code("JKM-C-JJWL-CXTP-") - elif self.fixture_material_id.name == "虎钳托盘": - self.code = self._get_code("JKM-C-JJWL-HQTP-") - else: - self.code = self._get_code("JKM-C-JJWL-LDKP-") - - @api.onchange('upload_model_file') - def onchange_model_file(self): - for item in self: - if len(item.upload_model_file) > 1: - raise ValidationError('只允许上传一个文件') - if item.upload_model_file: - file_attachment_id = item.upload_model_file[0] - # 附件路径 - report_path = file_attachment_id._full_path(file_attachment_id.store_fname) - logging.info("模型路径: %s" % report_path) - base64_data = base64.b64encode(file_attachment_id.datas) - base64_datas = base64_data.decode('utf-8') - model_code = hashlib.sha1(base64_datas.encode('utf-8')).hexdigest() - logging.info("模型编码: %s" % model_code) - item.model_file = self.transition_glb_file(report_path, model_code) - else: - item.model_file = False - - def _json_apply_machine_tool_type_item_code(self, item): - code_arr = [] - for i in item.apply_machine_tool_type_ids: - code_arr.append(i.code) - return code_arr - # 注册到cloud的夹具型号中 - def register_fixture_model(self): - sf_sync_config = self.env['res.config.settings'].get_values() - token = sf_sync_config['token'] - sf_secret_key = sf_sync_config['sf_secret_key'] - headers = Common.get_headers(self, token, sf_secret_key) - strurl = sf_sync_config['sf_url'] + self.crea_url - objs_all = self.search([('code', '=', self.code)]) - fixture_model_list = [] - if objs_all: - for item in objs_all: - val = { - 'code': item.code, - 'factory_token': token, - 'name': item.name, - 'code': item.code, - 'fixture_material_code': self.env['sf.fixture.material'].search( - [('id', '=', item.fixture_material_id.id)]).code, - 'multi_mounting_type_code': self.env['sf.multi_mounting.type'].search( - [('id', '=', item.multi_mounting_type_id.id)]).code, - 'brand_code': self.env['sf.machine.brand'].search( - [('id', '=', item.brand_id.id)]).code, - 'manufacturer_model_number': item.manufacturer_model_number, - 'clamping_way': item.clamping_way, - 'materials_model_code': self.env['sf.materials.model'].search( - [('id', '=', item.materials_model_id.id)]).code, - 'apply_machine_tool_type_code': self.env['sf.machine_tool.type'].search( - [('id', '=', item.type_id.id)]).code, - 'port_type': item.port_type, - 'model_file': item.model_file, - 'length': item.length, - 'width': item.width, - 'height': item.height, - 'weight': item.weight, - 'clamp_workpiece_length_max': item.state, - 'clamp_workpiece_width_max': item.clamp_workpiece_width_max, - 'clamp_workpiece_height_max': item.clamp_workpiece_height_max, - 'clamp_workpiece_diameter_max': item.clamp_workpiece_diameter_max, - 'maximum_carrying_weight': item.maximum_carrying_weight, - 'maximum_clamping_force': item.maximum_clamping_force, - 'driving_way': item.driving_way, - 'through_hole_size': item.through_hole_size, - 'screw_size': item.screw_size, - - } - fixture_model_list.append(val) - # kw = machine_tool_list - kw = json.dumps(fixture_model_list, ensure_ascii=False) - r = requests.post(strurl, json={}, data={'kw': kw, 'token': token}, headers=headers) - ret = r.json() - self.code = ret['message'] - self.state_zc = "已注册" - if r == 200: - return "注册成功" - else: - raise ValidationError("没有夹具型号注册信息") diff --git a/sf_base/models/functional_fixture.py b/sf_base/models/functional_fixture.py index a0b2b73b..86cc015f 100644 --- a/sf_base/models/functional_fixture.py +++ b/sf_base/models/functional_fixture.py @@ -36,6 +36,8 @@ class FunctionalFixture(models.Model): domain=[('fixture_material_type', '=', '磁吸托盘')]) vice_tray_model_ids = fields.Many2many('sf.fixture.model', 'rel_fixture_model_vice_tray', string="虎钳托盘型号", domain=[('fixture_material_type', '=', '虎钳托盘')]) + registration_status = fields.Selection([("已注册", "已注册"), ("未注册", "未注册")], string="注册状态", default='未注册', tracking=True) + @api.onchange('type_id') def _onchange_type_id(self): @@ -113,20 +115,19 @@ class FunctionalFixture(models.Model): code_arr.append(i.code) return code_arr - # 注册到cloud的夹具型号中 - + # 注册到cloud的功能夹具中 def register_functional_fixture(self): + registration_url = 'api/functional_fixture/create' sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strurl = sf_sync_config['sf_url'] + self.crea_url - objs_all = self.search([('code', '=', self.code)]) + strurl = sf_sync_config['sf_url'] + self.registration_url + objs_self = self.search([('code', '=', self.code)]) functional_fixture_list = [] - if objs_all: - for item in objs_all: + if objs_self: + for item in objs_self: val = { - 'code': item.code, 'factory_token': token, 'name': item.name, 'code': item.code, @@ -150,8 +151,9 @@ class FunctionalFixture(models.Model): r = requests.post(strurl, json={}, data={'kw': kw, 'token': token}, headers=headers) ret = r.json() self.code = ret['message'] - self.state_zc = "已注册" + if r == 200: + self.registration_status = "已注册" return "功能夹具注册成功" else: raise ValidationError("没有功能夹具注册信息") diff --git a/sf_base/views/fixture_view.xml b/sf_base/views/fixture_view.xml index 19934548..75a55392 100644 --- a/sf_base/views/fixture_view.xml +++ b/sf_base/views/fixture_view.xml @@ -161,7 +161,7 @@ 夹具型号 sf.fixture.model - + @@ -175,11 +175,7 @@ 夹具型号 sf.fixture.model -
-
-
+ diff --git a/sf_base/views/functional_fixture_view.xml b/sf_base/views/functional_fixture_view.xml index 93783c2b..a790c1d6 100644 --- a/sf_base/views/functional_fixture_view.xml +++ b/sf_base/views/functional_fixture_view.xml @@ -94,6 +94,11 @@ sf.functional.fixture +
+ +