From 5c2e7c80da3945ebeaafd582f8938c15a2440ec6 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Tue, 1 Aug 2023 17:39:40 +0800 Subject: [PATCH 1/3] =?UTF-8?q?1.=E4=BA=A7=E5=93=81=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E5=A2=9E=E5=8A=A0=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E7=B1=BB=E5=88=AB=E7=9A=84=E6=90=9C=E7=B4=A2=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=202.=E5=A4=B9=E5=85=B7=E5=9E=8B=E5=8F=B7=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E5=88=B0cloud=EF=BC=9A=E5=A4=B9=E5=85=B7=E5=9E=8B=E5=8F=B7?= =?UTF-8?q?=E7=9A=84Tree=E5=92=8Cform=E8=A7=86=E5=9B=BE=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=E4=B8=8D=E5=8F=AF=E5=A2=9E=E5=88=A0=E6=94=B9=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=EF=BC=8C=E9=A1=B5=E9=9D=A2=E6=96=B0=E5=A2=9E=E6=97=B6=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E6=A0=B9=E6=8D=AE=E5=A4=B9=E5=85=B7=E7=89=A9=E6=96=99?= =?UTF-8?q?=E5=9B=9E=E6=98=BE=E4=B8=8D=E5=90=8C=E7=9A=84=E7=BC=96=E7=A0=81?= =?UTF-8?q?=EF=BC=9B=E6=96=B0=E5=A2=9E=E6=B3=A8=E5=86=8C=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E5=8F=8A=E5=AF=B9=E5=BA=94=E7=9A=84=E6=B3=A8=E5=86=8C=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=203.=E5=8A=9F=E8=83=BD=E5=A4=B9=E5=85=B7=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E5=88=B0cloud=EF=BC=9A.=E5=8A=9F=E8=83=BD=E5=A4=B9?= =?UTF-8?q?=E5=85=B7=E7=9A=84Tree=E5=92=8Cform=E8=A7=86=E5=9B=BE=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E4=B8=8D=E5=8F=AF=E5=A2=9E=E5=88=A0=E6=94=B9=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=EF=BC=8C=E9=A1=B5=E9=9D=A2=E6=96=B0=E5=A2=9E=E6=97=B6?= =?UTF-8?q?=E7=BC=96=E7=A0=81=E5=92=8C=E5=90=8D=E7=A7=B0=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=A4=B9=E5=85=B7=E7=B1=BB=E5=9E=8B=E5=92=8C?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E7=9A=84=E6=89=98=E7=9B=98=E5=9E=8B=E5=8F=B7?= =?UTF-8?q?=E6=89=80=E8=BF=9B=E8=A1=8C=E5=9B=9E=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/models/fixture.py | 194 +++++++++++++++++++- sf_base/models/functional_fixture.py | 130 ++++++++++++- sf_base/views/base_view.xml | 6 +- sf_base/views/fixture_view.xml | 18 +- sf_base/views/functional_fixture_view.xml | 18 +- sf_dlm/views/product_template_view.xml | 2 +- sf_manufacturing/models/product_template.py | 5 +- 7 files changed, 336 insertions(+), 37 deletions(-) diff --git a/sf_base/models/fixture.py b/sf_base/models/fixture.py index d5ad7fe6..78b1eb9e 100644 --- a/sf_base/models/fixture.py +++ b/sf_base/models/fixture.py @@ -1,4 +1,14 @@ 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): @@ -26,7 +36,6 @@ 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) @@ -40,14 +49,181 @@ class FixtureModel(models.Model): width = fields.Char(string="宽度[mm]", size=6) height = fields.Char(string="高度[mm]", size=6) weight = fields.Char(string="重量[kg]", size=4) - clamp_workpiece_length_max = fields.Char(string="夹持工件长度MAX[mm]", size=6) - clamp_workpiece_width_max = fields.Char(string="夹持工件宽度MAX[mm]", size=6) - clamp_workpiece_height_max = fields.Char(string="夹持工件高度MAX[mm]", size=6) - clamp_workpiece_diameter_max = fields.Char(string="夹持工件直径MAX[mm]", size=6) - maximum_carrying_weight = fields.Char(string="最大承载重量[kg]", size=4) - maximum_clamping_force = fields.Char(string="最大夹持力[n]", size=8) + clamp_workpiece_length_max = fields.Integer(string="夹持工件长度MAX[mm]", size=6) + clamp_workpiece_width_max = fields.Integer(string="夹持工件宽度MAX[mm]", size=6) + clamp_workpiece_height_max = fields.Integer(string="夹持工件高度MAX[mm]", size=6) + clamp_workpiece_diameter_max = fields.Float(string="夹持工件直径MAX[mm]", size=6) + maximum_carrying_weight = fields.Float(string="最大承载重量[kg]", size=4) + maximum_clamping_force = fields.Integer(string="最大夹持力[n]", size=8) materials_model_id = fields.Many2one('sf.materials.model', string="材料型号") - driving_way = fields.Char(string="驱动方式") - apply_machine_tool_type_id = fields.Many2one('sf.machine_tool.type', string="适用机床型号") + driving_way = fields.Selection([('气动', '气动'), ('液压', '液压'), ('机械', '机械')], string="驱动方式") + apply_machine_tool_type_ids = fields.Many2many('sf.machine_tool.type', 'rel_fixture_model_machine_tool_type', + 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 4ef466f7..a0b2b73b 100644 --- a/sf_base/models/functional_fixture.py +++ b/sf_base/models/functional_fixture.py @@ -1,4 +1,8 @@ from odoo import models, fields, api +from odoo.addons.sf_base.commons.common import Common +from odoo.exceptions import ValidationError +import requests +import json class FunctionalFixtureType(models.Model): @@ -16,7 +20,6 @@ class FunctionalFixture(models.Model): _description = "功能夹具" code = fields.Char(string='编码', readonly=True) - name = fields.Char(string="名称", size=15, required=True) type_id = fields.Many2one('sf.functional.fixture.type', string="功能夹具类型", required=True) type = fields.Char(related='type_id.name', string="功能夹具类别", store=True) zero_chuck_model_ids = fields.Many2many('sf.fixture.model', 'rel_fixture_model_zero_chuck', string="零点卡盘型号", @@ -34,10 +37,121 @@ class FunctionalFixture(models.Model): vice_tray_model_ids = fields.Many2many('sf.fixture.model', 'rel_fixture_model_vice_tray', string="虎钳托盘型号", domain=[('fixture_material_type', '=', '虎钳托盘')]) - def _get_fixture_model_ids(self, fixture_model_code): - fixture_model_ids = [] - for item in fixture_model_code: - fixture_model = self.env['sf.fixture.model'].search([('code', '=', item)]) - if fixture_model: - fixture_model_ids.append(fixture_model.id) - return [(6, 0, fixture_model_ids)] + @api.onchange('type_id') + def _onchange_type_id(self): + if self.type_id: + functional_fixture_type = self.search( + [('type', '=', self.type)], limit=1, order='id desc') + if not functional_fixture_type: + num = "%04d" % 1 + else: + m = int(functional_fixture_type.code[-3:]) + 1 + num = "%04d" % m + self.code = "%s%s-%s" % ('JKM-C-GNJJ-', self.type_id.code, num) + + _sql_constraints = [ + ('code_uniq', 'unique (code)', + '编码不能重复') + + ] + + @api.depends('transfer_tray_model_ids', 'pneumatic_tray_model_ids', 'magnetic_tray_model_ids', + 'vice_tray_model_ids', 'type') + def _get_name(self): + for record in self: + if record.type: + if not record.transfer_tray_model_ids and not record.pneumatic_tray_model_ids and not record.magnetic_tray_model_ids and not record.vice_tray_model_ids: + record.name = '' + if record.transfer_tray_model_ids: + for i in record.transfer_tray_model_ids: + record.name = '%s%s%s' % ( + i.display_name.split('-')[0], record.type, '功能夹具') + if record.pneumatic_tray_model_ids: + for i in record.pneumatic_tray_model_ids: + record.name = '%s%s%s' % ( + i.display_name.split('-')[0], record.type, '功能夹具') + if record.magnetic_tray_model_ids: + for i in record.magnetic_tray_model_ids: + record.name = '%s%s%s' % ( + i.display_name.split('-')[0], record.type, '功能夹具') + if record.vice_tray_model_ids: + for i in record.vice_tray_model_ids: + record.name = '%s%s%s' % ( + i.display_name.split('-')[0], record.type, '功能夹具') + else: + record.name = '' + + name = fields.Char(string="名称", compute=_get_name, readonly=True) + + def _json_zero_chuck_model_item_code(self, item): + code_arr = [] + for i in item.zero_chuck_model_ids: + code_arr.append(i.code) + return code_arr + + def _json_transfer_tray_model_item_code(self, item): + code_arr = [] + for i in item.transfer_tray_model_ids: + code_arr.append(i.code) + return code_arr + + def _json_vice_tray_item_code(self, item): + code_arr = [] + for i in item.vice_tray_model_ids: + code_arr.append(i.code) + return code_arr + + def _json_magnetic_tray_model_item_code(self, item): + code_arr = [] + for i in item.magnetic_tray_model_ids: + code_arr.append(i.code) + return code_arr + + def _json_pneumatic_tray_model_item_code(self, item): + code_arr = [] + for i in item.pneumatic_tray_model_ids: + code_arr.append(i.code) + return code_arr + + # 注册到cloud的夹具型号中 + + def register_functional_fixture(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)]) + functional_fixture_list = [] + if objs_all: + for item in objs_all: + val = { + 'code': item.code, + 'factory_token': token, + 'name': item.name, + 'code': item.code, + 'type_code': self.env['sf.functional.fixture.type'].search( + [('id', '=', item.type_id.id)]).code, + 'zero_chuck_model_codes': self.env['sf.functional.fixture']._json_zero_chuck_model_item_code( + item), + 'transfer_tray_model_codes': self.env['sf.functional.fixture']._json_transfer_tray_model_item_code( + item), + 'pneumatic_tray_model_codes': self.env[ + 'sf.functional.fixture']._json_pneumatic_tray_model_item_code( + item), + 'magnetic_tray_model_codes': self.env['sf.functional.fixture']._json_magnetic_tray_model_item_code( + item), + 'vice_tray_model_codes': self.env['sf.functional.fixture']._json_vice_tray_item_code( + item), + } + functional_fixture_list.append(val) + # kw = machine_tool_list + kw = json.dumps(functional_fixture_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/views/base_view.xml b/sf_base/views/base_view.xml index 274d9d64..be7e220c 100644 --- a/sf_base/views/base_view.xml +++ b/sf_base/views/base_view.xml @@ -21,7 +21,7 @@ tree.sf.machine.brand sf.machine.brand - + @@ -61,7 +61,7 @@ 品牌 ir.actions.act_window sf.machine.brand - tree + tree,form #------------------机床型号------------------ @@ -81,7 +81,7 @@ tree.sf.machine_tool.type sf.machine_tool.type - + diff --git a/sf_base/views/fixture_view.xml b/sf_base/views/fixture_view.xml index cef36ff2..19934548 100644 --- a/sf_base/views/fixture_view.xml +++ b/sf_base/views/fixture_view.xml @@ -161,7 +161,7 @@ 夹具型号 sf.fixture.model - + @@ -175,17 +175,21 @@ 夹具型号 sf.fixture.model -
+ +
+
- + - + - + @@ -232,7 +236,7 @@ - + - diff --git a/sf_base/views/functional_fixture_view.xml b/sf_base/views/functional_fixture_view.xml index 0a763393..93783c2b 100644 --- a/sf_base/views/functional_fixture_view.xml +++ b/sf_base/views/functional_fixture_view.xml @@ -81,7 +81,7 @@ 功能夹具 sf.functional.fixture - + @@ -93,7 +93,7 @@ 功能夹具 sf.functional.fixture - + @@ -101,15 +101,19 @@ - + + options="{'no_create': True}" + attrs='{"invisible": [("type","!=","转接板(锁板)式")],"required": [("type", "=", "转接板(锁板)式")]}'/> + options="{'no_create': True}" + attrs='{"invisible": [("type","!=","气动式")],"required": [("type", "=", "气动式")]}'/> + options="{'no_create': True}" + attrs='{"invisible": [("type","!=","磁吸式")],"required": [("type", "=", "磁吸式")]}'/> + options="{'no_create': True}" + attrs='{"invisible": [("type","!=","虎钳式")],"required": [("type", "=", "虎钳式")]}'/> diff --git a/sf_dlm/views/product_template_view.xml b/sf_dlm/views/product_template_view.xml index e7bd62a9..3fcdcf1b 100644 --- a/sf_dlm/views/product_template_view.xml +++ b/sf_dlm/views/product_template_view.xml @@ -278,7 +278,7 @@ attrs='{"invisible": [("fixture_material_type","!=",("转接板(锁板)托盘"))]}'/> - diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py index 710fdb63..85f8313f 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -147,7 +147,8 @@ class ResProductMo(models.Model): fixture_maximum_carrying_weight = fields.Float(string="最大承载重量[kg]", digits=(16, 4)) fixture_maximum_clamping_force = fields.Integer(string="最大夹持力[n]", size=8) fixture_driving_way = fields.Char(string="驱动方式") - fixture_apply_machine_tool_type_id = fields.Many2one('sf.machine_tool.type', string="适用机床型号") + fixture_apply_machine_tool_type_ids = fields.Many2many('sf.machine_tool.type', 'rel_product_machine_tool_type', + string="适用机床型号") fixture_through_hole_size = fields.Integer(string="过孔大小[mm]", size=6) fixture_screw_size = fields.Integer(string="螺牙大小[mm]", size=6) @@ -205,7 +206,7 @@ class ResProductMo(models.Model): item.fixture_clamp_workpiece_width_max = item.fixture_model_id.clamp_workpiece_width_max item.fixture_clamp_workpiece_height_max = item.fixture_model_id.clamp_workpiece_height_max item.fixture_clamp_workpiece_diameter_max = item.fixture_model_id.clamp_workpiece_diameter_max - item.fixture_apply_machine_tool_type_id = item.fixture_model_id.apply_machine_tool_type_id.id + item.fixture_apply_machine_tool_type_id = self._get_ids(item.fixture_model_id.apply_machine_tool_type_ids) @api.onchange('cutting_tool_model_id') def _onchange_cutting_tool_model_id(self): From 24afa53028ee25948314c79dfbf2aba9cc886086 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Wed, 2 Aug 2023 17:35:09 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=A4=B9=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 +
+ +
From 5df00e14da851564824387b4ad31b0e2f46aaaba Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Thu, 3 Aug 2023 16:57:18 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=88=B6=E9=80=A0=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E9=87=8C=E7=9A=84=E9=85=8D=E7=BD=AE=E5=86=85=E7=9A=84=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/models/base.py | 4 +- sf_base/views/base_view.xml | 296 ++++---- sf_base/views/common_view.xml | 159 +++-- sf_base/views/fixture_view.xml | 118 ++-- sf_base/views/functional_fixture_view.xml | 10 +- sf_base/views/menu_view.xml | 2 +- sf_base/views/tool_menu.xml | 6 +- sf_base/views/tool_views.xml | 806 ++++++++++++---------- 8 files changed, 773 insertions(+), 628 deletions(-) diff --git a/sf_base/models/base.py b/sf_base/models/base.py index 0a1face8..f6a945aa 100644 --- a/sf_base/models/base.py +++ b/sf_base/models/base.py @@ -31,13 +31,13 @@ class MachineBrand(models.Model): _name = 'sf.machine.brand' _description = '品牌' + code = fields.Char('编码') name = fields.Char('名称') tag_ids = fields.Many2many('sf.machine.brand.tags', 'rel_machine_brand_tags', string='类别') image_brand = fields.Image("品牌图片") manufacturer_model_number = fields.Char('厂家型号', size=10) + remark = fields.Text('备注') active = fields.Boolean('有效', default=True) - code = fields.Char('编码') - # 机床 class MachineTool(models.Model): diff --git a/sf_base/views/base_view.xml b/sf_base/views/base_view.xml index be7e220c..eadd81f2 100644 --- a/sf_base/views/base_view.xml +++ b/sf_base/views/base_view.xml @@ -21,41 +21,47 @@ tree.sf.machine.brand sf.machine.brand - + - + - - - - - - - - - - - - - - - - - - - - - - - - - + + form.sf.machine.brand + sf.machine.brand + + + + + + + + + + + + + + + + + + + + + + + + 品牌 @@ -81,7 +87,7 @@ tree.sf.machine_tool.type sf.machine_tool.type - + @@ -96,81 +102,110 @@ sf.machine_tool.type
- + - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -207,7 +242,7 @@ tree.sf.machine_tool.category sf.machine_tool.category - + @@ -216,42 +251,35 @@ - - form.sf.machine_tool.category - sf.machine_tool.category - -
- - - - - - - - - + + + + + + + + + + + + + + - - - + + + -
-
-
+ + + 机床类型 ir.actions.act_window sf.machine_tool.category - tree,form - -

- [机床类型] 还没有哦!点左上角的[创建]按钮,沙发归你了! -

-

-

-
+ tree
#------------------机床注册------------------ @@ -378,13 +406,13 @@
- #------------------控制系统------------------ + #------------------数控系统------------------ search.sf.machine.control_system sf.machine.control_system - + @@ -395,7 +423,7 @@ tree.sf.machine.control_system sf.machine.control_system - + @@ -424,7 +452,7 @@ - 控制系统 + 数控系统 ir.actions.act_window sf.machine.control_system tree diff --git a/sf_base/views/common_view.xml b/sf_base/views/common_view.xml index f73e4dcf..e15d644c 100644 --- a/sf_base/views/common_view.xml +++ b/sf_base/views/common_view.xml @@ -2,24 +2,24 @@ - - sf.processing.technology - -
- - - - - - - - - - - -
-
-
+ + + + + + + + + + + + + + + + + + sf.processing.technology @@ -75,7 +75,7 @@ sf.production.process.category - + @@ -131,7 +131,7 @@ - + @@ -186,44 +186,50 @@ sf.materials.model -
- + + - - - + + + + + + + + + + + + + + + + + + + + + + + - - - + - - - - - - - - - - - - - - - +
sf.materials.model - - - - - + + + + + + @@ -247,28 +253,33 @@ sf.production.materials
- + - + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - +
@@ -372,14 +383,16 @@
- - - + + + + + + + + - - - - +
diff --git a/sf_base/views/fixture_view.xml b/sf_base/views/fixture_view.xml index 75a55392..65cf2ce1 100644 --- a/sf_base/views/fixture_view.xml +++ b/sf_base/views/fixture_view.xml @@ -177,7 +177,7 @@
- + @@ -193,60 +193,68 @@ attrs="{'invisible': [('model_file', '=', False)]}"/> - - - - - - - - - - - - - + + + + + + + + + +
diff --git a/sf_base/views/functional_fixture_view.xml b/sf_base/views/functional_fixture_view.xml index a790c1d6..4239ceba 100644 --- a/sf_base/views/functional_fixture_view.xml +++ b/sf_base/views/functional_fixture_view.xml @@ -94,11 +94,11 @@ sf.functional.fixture
-
- -
+ + + + + diff --git a/sf_base/views/menu_view.xml b/sf_base/views/menu_view.xml index 1806e42a..9525bbd3 100644 --- a/sf_base/views/menu_view.xml +++ b/sf_base/views/menu_view.xml @@ -139,7 +139,7 @@ diff --git a/sf_base/views/tool_menu.xml b/sf_base/views/tool_menu.xml index a1c976d5..91d95b37 100644 --- a/sf_base/views/tool_menu.xml +++ b/sf_base/views/tool_menu.xml @@ -7,14 +7,14 @@ 刀具物料 ir.actions.act_window sf.cutting.tool.material - tree,form + tree 刀具类型 ir.actions.act_window sf.cutting.tool.type - tree,form + tree @@ -35,7 +35,7 @@ 功能刀具类型 ir.actions.act_window sf.functional.cutting.tool.model - tree,form + tree diff --git a/sf_base/views/tool_views.xml b/sf_base/views/tool_views.xml index 4b02fefb..ccb98a7d 100644 --- a/sf_base/views/tool_views.xml +++ b/sf_base/views/tool_views.xml @@ -1,99 +1,114 @@ - - - sf.cutting.tool.material.tree - sf.cutting.tool.material - - - - - - - - + + + sf.cutting.tool.material.tree + sf.cutting.tool.material + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sf.cutting.tool.material.search + sf.cutting.tool.material + + + + + + + + + + + + sf.functional.cutting.tool.tree + sf.functional.cutting.tool + + + + + + + + + + + + + + + + + + sf.functional.cutting.tool.form + sf.functional.cutting.tool + + + + + + + + + + + + + + + + + + + + - - sf.cutting.tool.material.form - sf.cutting.tool.material - - - - - - - - - - - - - - - - - - - - - sf.cutting.tool.material.search - sf.cutting.tool.material - - - - - - - - - - - - sf.functional.cutting.tool.tree - sf.functional.cutting.tool - - - - - - - - - - - - - - - - - - sf.functional.cutting.tool.form - sf.functional.cutting.tool - -
- - - - - - - - - - - - - - - - - - - - @@ -114,284 +129,365 @@ - - -
-
-
+
+
+ +
+
- - sf.functional.cutting.tool.search - sf.functional.cutting.tool - - - - - - - + + sf.functional.cutting.tool.search + sf.functional.cutting.tool + + + + + + + - - - sf.cutter.function.tree - sf.functional.cutting.tool.model - - - - - - - - - - sf.cutter.function.form - sf.functional.cutting.tool.model - -
- - - - - - - - - - - -
-
-
+ + + sf.cutter.function.tree + sf.functional.cutting.tool.model + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - sf.cutter.function.search - sf.functional.cutting.tool.model - - - - - - - + + + sf.cutter.function.search + sf.functional.cutting.tool.model + + + + + + + - - - sf.cutting.tool.model.tree - sf.cutting.tool.model - - - - - - - - - + + + sf.cutting.tool.model.tree + sf.cutting.tool.model + + + + + + + + + - - sf.cutting.tool.model.form - sf.cutting.tool.model - -
- - - - - - - - - - + + sf.cutting.tool.model.form + sf.cutting.tool.model + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - + + + sf.cutting.tool.model.search + sf.cutting.tool.model + + + + + + + + - - - - - + + + sf.cutting.tool.type.tree + sf.cutting.tool.type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-
- - - - sf.cutting.tool.model.search - sf.cutting.tool.model - - - - - - - - - - - - - sf.cutting.tool.type.tree - sf.cutting.tool.type - - - - - - - - - - - - sf.cutting.tool.type.form - sf.cutting.tool.type - -
- - - - - - - - - - - - -
-
-
- - - - sf.cutting.tool.type.search - sf.cutting.tool.type - - - - - - - - + + + sf.cutting.tool.type.search + sf.cutting.tool.type + + + + + + + +