# -*- coding: utf-8 -*- import requests import json import base64 from odoo import models from odoo.exceptions import ValidationError import logging from odoo.addons.sf_base.commons.common import Common _logger = logging.getLogger(__name__) class sfProductionMaterials(models.Model): _inherit = "sf.production.materials" _description = "材料" url = '/api/production_materials/list' # 定时同步每日材料 def sync_production_materials(self): # 配置中获取token 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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['production_materials_yesterday_list']: if item: brand = self.env['sf.production.materials'].search( [("materials_no", '=', item['materials_no'])]) if brand: brand.id = item['id'], brand.name = item['name'], brand.remark = item['remark'], brand.active = item['active'] else: self.env['sf.production.materials'].create({ "id": item['id'], "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], "active": item['active'] }) else: raise ValidationError("认证未通过") # 同步所有材料 def sync_all_production_materials(self): _logger = '正在同步所有材料' 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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['production_materials_all_list']: if item: brand = self.env['sf.production.materials'].search( [("materials_no", '=', item['materials_no'])]) if not brand: self.env['sf.production.materials'].create({ "id": item['id'], "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], "active": item['active'] }) else: raise ValidationError("认证未通过") class sfMaterialModel(models.Model): _inherit = 'sf.materials.model' _description = '材料型号' url = '/api/materials_model/list' # 定时同步每日材料型号 def sync_materials_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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['materials_model_yesterday_list']: if item: materials_model = self.env['sf.materials.model'].search( [("materials_no", '=', item['materials_no'])]) if materials_model: materials_model.id = item['id'], materials_model.name = item['name'], materials_model.materials_no = item['materials_no'], materials_model.remark = item['remark'], materials_model.tensile_strength = item['tensile_strength'], materials_model.hardness = item['hardness'], materials_model.materials_no = item['materials_no'], materials_model.rough_machining = item['rough_machining'], materials_model.finish_machining = item['finish_machining'], materials_model.mf_materia_post = item['mf_materia_post'], materials_model.materials_id = self.env['sf.production.materials'].search( [("materials_no", '=', item['materials_id.materials_no'])]).id, materials_model.need_h = item['need_h'], materials_model.density = item['density'] else: self.env['sf.materials.model'].create({ "id": item['id'], "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], "tensile_strength": item['tensile_strength'], "hardness": item['hardness'], "rough_machining": item['rough_machining'], "finish_machining": item['finish_machining'], "active": item['active'], "materials_id": self.env['sf.production.materials'].search( [("materials_no", '=', item['materials_id.materials_no'])]).id, "need_h": item['need_h'], "mf_materia_post": item['mf_materia_post'], "density": item['density'], # "tag_ids": item['tag_ids'] }) else: raise ValidationError("认证未通过") # 同步所有材料型号 def sync_all_materials_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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['materials_model_all_list']: if item: materials_model = self.env['sf.materials.model'].search( [("materials_no", '=', item['materials_no'])]) if not materials_model: self.env['sf.materials.model'].create({ "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], "active": item['active'], "tensile_strength": item['tensile_strength'], "hardness": item['hardness'], "rough_machining": item['rough_machining'], "finish_machining": item['finish_machining'], "materials_id": self.env['sf.production.materials'].search( [("materials_no", '=', item['materials_id.materials_no'])]).id, "need_h": item['need_h'], "mf_materia_post": item['mf_materia_post'], "density": item['density'], # "tag_ids": item['tag_ids'] }) else: raise ValidationError("认证未通过") class sfProductionProcessCategory(models.Model): _inherit = 'sf.production.process.category' _description = '表面工艺类别' url = '/api/production_process_category/list' # 定时同步每日表面工艺类别 def sync_production_process_category(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['production_process_category_yesterday_list']: if item: production_process_category = self.env['sf.production.process.category'].search( [("code", '=', item['code'])]) if production_process_category: production_process_category.name = item['name'], production_process_category.code = item['code'], production_process_category.active = item['active'] else: self.env['sf.production.process.category'].create({ "name": item['name'], "code": item['code'], "active": item['active'], }) else: raise ValidationError("认证未通过") # 定时同步表面工艺 # 同步所有表面工艺类别 def sync_all_production_process_category(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['production_process_category_all_list']: if item: category = self.env['sf.production.process.category'].search( [("code", '=', item['code'])]) if not category: self.env['sf.production.process.category'].create({ "name": item['name'], "code": item['code'], "active": item['active'], }) else: raise ValidationError("认证未通过") class sfProductionProcess(models.Model): _inherit = 'sf.production.process' _description = '表面工艺' url = '/api/production_process/list' # 定时同步每日表面工艺 def sync_production_process(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['production_process_yesterday_list']: if item: brand = self.env['sf.production.process'].search( [("process_encode", '=', item['process_encode'])]) if brand: brand.name = item['name'], brand.category_id = self.env['sf.production.process.category'].search( [("code", '=', item['category_code'])]).id, brand.process_encode = item['process_encode'], brand.remark = item['remark'], brand.active = item['active'], brand.remark = item['remark'] else: self.env['sf.production.process'].create({ "name": item['name'], "category_id": self.env['sf.production.process.category'].search( [("code", '=', item['category_code'])]).id, "process_encode": item['process_encode'], "remark": item['remark'], "active": item['active'], }) else: raise ValidationError("认证未通过") # 定时同步表面工艺 # 同步所有表面工艺 def sync_all_production_process(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['production_process_all_list']: if item: brand = self.env['sf.production.process'].search( [("process_encode", '=', item['process_encode'])]) if not brand: self.env['sf.production.process'].create({ "name": item['name'], "category_id": self.env['sf.production.process.category'].search( [("code", '=', item['category_code'])]).id, "process_encode": item['process_encode'], "remark": item['remark'], "active": item['active'], # "tag_ids": item['tag_ids'] }) else: raise ValidationError("认证未通过") class sfProcessingTechnology(models.Model): _inherit = 'sf.processing.technology' _description = '加工工艺' url = '/api/processing_technology/list' # 定时同步加工工艺 def sync_processing_technology(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['processing_technology_yesterday_list']: if item: brand = self.env['sf.processing.technology'].search( [("process_encode", '=', item['process_encode'])]) if brand: brand.id = item['id'], brand.name = item['name'], brand.process_encode = item['process_encode'], brand.remark = item['remark'], brand.active = item['active'] else: self.env['sf.processing.technology'].create({ "id": item['id'], "name": item['name'], "process_encode": item['process_encode'], "remark": item['remark'], "active": item['active'], # "tag_ids": item['tag_ids'] }) else: raise ValidationError("认证未通过") # 同步所有加工工艺 def sync_all_processing_technology(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['processing_technology_all_list']: if item: brand = self.env['sf.processing.technology'].search( [("process_encode", '=', item['process_encode'])]) if not brand: self.env['sf.processing.technology'].create({ "id": item['id'], "name": item['name'], "process_encode": item['process_encode'], "remark": item['remark'], "active": item['active'], # "tag_ids": item['tag_ids'] }) else: raise ValidationError("认证未通过") class MachineBrandTags(models.Model): _inherit = 'sf.machine.brand.tags' _description = '品牌类别' url = '/api/machine_brand_tags/list' # 定时同步品牌类别 def sync_machine_brand_tags(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_brand_tags_yesterday_list']: brand = self.env['sf.machine.brand.tags'].search( [("id", '=', item['id'])]) if brand: brand.id = item['id'], brand.name = item['name'], brand.color = item['color'] else: self.env['sf.machine.brand.tags'].create({ "id": item['id'], "name": item['name'], "color": item['color'], }) else: raise ValidationError("认证未通过") # 同步所有品牌类别 def sync_all_machine_brand_tags(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_brand_tags_all_list']: brand = self.env['sf.machine.brand.tags'].search( [("name", '=', item['name'])]) if not brand: self.env['sf.machine.brand.tags'].create({ "id": item['id'], "name": item['name'], "color": item['color'], }) else: raise ValidationError("认证未通过") class MachineControlSystem(models.Model): _inherit = 'sf.machine.control_system' _description = '控制系统' url = '/api/machine_control_system/list' # 定时同步控制系统 def sync_machine_tool_type_control_system(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_control_system_yesterday_list']: if item: brand = self.env['sf.machine.control_system'].search( [("code", '=', item['code'])]) if brand: brand.id = item['id'], brand.name = item['name'], brand.code = item['code'], brand.remark = item['remark'], brand.brand_id = self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, brand.active = item['active'] else: self.env['sf.machine.control_system'].create({ "id": item['id'], "remark": item['remark'], "name": item['name'], "code": item['code'], 'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, "active": item['active'], # "tag_ids": item['tag_ids'] }) else: raise ValidationError("认证未通过") # 同步所有控制系统 def sync_all_machine_tool_type_control_system(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_control_system_all_list']: if item: brand = self.env['sf.machine.control_system'].search( [("code", '=', item['code'])]) if not brand: self.env['sf.machine.control_system'].create({ "id": item['id'], "name": item['name'], "code": item['code'], "remark": item['remark'], 'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, "active": item['active'], # "tag_ids": item['tag_ids'] }) else: raise ValidationError("认证未通过") class MachineBrand(models.Model): _inherit = 'sf.machine.brand' _description = '品牌' url = '/api/machine_brand/list' # 定时同步品牌 def sync_machine_brand(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_brand_yesterday_list']: brand = self.env['sf.machine.brand'].search( [("code", '=', item['code'])]) if brand: brand.id = item['id'], brand.name = item['name'], brand.code = item['code'], brand.image_brand = '' if not item['image_brand'] else base64.b64encode(item.image_brand), brand.active = item['active'], brand.remark = item['remark'], else: self.env['sf.machine.brand'].create({ "id": item['id'], "name": item['name'], "code": item['code'], "image_brand": '' if not item['image_brand'] else base64.b64encode(item.image_brand), "active": item['active'], "remark": item['remark'], }) else: raise ValidationError("认证未通过") # 同步所有品牌 def sync_all_machine_brand(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_brand_all_list']: brand = self.env['sf.machine.brand'].search( [("code", '=', item['code'])]) if not brand: self.env['sf.machine.brand'].create({ "id": item['id'], "name": item['name'], "code": item['code'], "remark": item['remark'], "image_brand": '' if not item['image_brand'] else base64.b64encode(item.image_brand), "tag_ids": self.env['sf.machine.brand.tags'].search( [("name", 'in', item['tag_ids'])]).ids }) else: raise ValidationError("认证未通过") class MachineToolType(models.Model): _inherit = 'sf.machine_tool.type' _description = '机床型号' url = '/api/machine_tool_type/list' # 定时同步机床型号 def sync_machine_tool_type(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_tool_type_yesterday_list']: brand = self.env['sf.machine_tool.type'].search( [("code", '=', item['code'])]) if brand: brand.id = item['id'], brand.knife_type = item['knife_type'], brand.name = item['name'], brand.code = item['code'], brand.precision_min = item['precision_min'], brand.precision_max = item['precision_max'], brand.number_of_knife_library = item['number_of_knife_library'], brand.rotate_speed = item['rotate_speed'], brand.number_of_axles = item['number_of_axles'], brand.control_system_id = self.env['sf.machine.control_system'].search( [('code', '=', item['control_system_id'])]).id, brand.x_axis = item['x_axis'], brand.y_axis = item['y_axis'], brand.z_axis = item['z_axis'], brand.b_axis = item['b_axis'], brand.c_axis = item['c_axis'], brand.active = item['active'], brand.remark = item['remark'], brand.brand_id = self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, else: # print(item['machine_tool_picture'].encode('utf-8')) self.env['sf.machine_tool.type'].create({ "id": item['id'], "name": item['name'], "code": item['code'], "knife_type": item['knife_type'], "number_of_knife_library": item['number_of_knife_library'], "rotate_speed": item['rotate_speed'], "number_of_axles": item['number_of_axles'], "x_axis": item['x_axis'], "y_axis": item['y_axis'], "z_axis": item['z_axis'], "b_axis": item['b_axis'], "c_axis": item['c_axis'], "remark": item['remark'], "precision_min": item['precision_min'], "precision_max": item['precision_max'], 'control_system_id': self.env['sf.machine.control_system'].search( [('code', '=', item['control_system_id'])]).id, "active": item['active'], 'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, 'machine_tool_picture': item['machine_tool_picture'].encode('utf-8'), "heightened_way": item['heightened_way'], "workpiece_load": item['workpiece_load'], "lead_screw": item['lead_screw'], "workbench_L": item['workbench_L'], "workbench_W": item['workbench_W'], "guide_rail": item['guide_rail'], "machine_tool_L": item['machine_tool_L'], "machine_tool_W": item['machine_tool_W'], "machine_tool_H": item['machine_tool_H'], "feed_speed": item['feed_speed'], "tool_speed": item['tool_speed'], "distance_min": item['distance_min'], "distance_max": item['distance_max'], "taper": item['taper'], "torque": item['torque'], "motor_power": item['motor_power'], "tool_quality_max": item['tool_quality_max'], "tool_long_max": item['tool_long_max'], "tool_diameter_max": item['tool_diameter_max'], "tool_diameter_min": item['tool_diameter_min'], "machine_tool_category": self.env['sf.machine_tool.category'].search( [('code', '=', item['machine_tool_category'])]).id, }) else: raise ValidationError("认证未通过") # 同步所有机床型号 def sync_all_machine_tool_type(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_tool_type_all_list']: if item.get('machine_tool_picture'): image = base64.b64decode(item['machine_tool_picture']) else: image = '' brand = self.env['sf.machine_tool.type'].search( [("code", '=', item['code'])]) if not brand: self.env['sf.machine_tool.type'].create({ "id": item['id'], "name": item['name'], "code": item['code'], "number_of_knife_library": item['number_of_knife_library'], "rotate_speed": item['rotate_speed'], "number_of_axles": item['number_of_axles'], "x_axis": item['x_axis'], "y_axis": item['y_axis'], "z_axis": item['z_axis'], "b_axis": item['b_axis'], "c_axis": item['c_axis'], "knife_type": item['knife_type'], "remark": item['remark'], "precision_min": item['precision_min'], "precision_max": item['precision_max'], 'control_system_id': self.env['sf.machine.control_system'].search( [('code', '=', item['control_system_id'])]).id, "active": item['active'], 'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, 'machine_tool_picture': image, "heightened_way": item['heightened_way'], "workpiece_load": item['workpiece_load'], "lead_screw": item['lead_screw'], "workbench_L": item['workbench_L'], "workbench_W": item['workbench_W'], "guide_rail": item['guide_rail'], "machine_tool_L": item['machine_tool_L'], "machine_tool_W": item['machine_tool_W'], "machine_tool_H": item['machine_tool_H'], "feed_speed": item['feed_speed'], "tool_speed": item['tool_speed'], "distance_min": item['distance_min'], "distance_max": item['distance_max'], "taper": item['taper'], "torque": item['torque'], "motor_power": item['motor_power'], "tool_quality_max": item['tool_quality_max'], "tool_long_max": item['tool_long_max'], "tool_diameter_max": item['tool_diameter_max'], "tool_diameter_min": item['tool_diameter_min'], "machine_tool_category": self.env['sf.machine_tool.category'].search( [('code', '=', item['machine_tool_category'])]).id, }) else: brand.write({ "id": item['id'], "name": item['name'], "code": item['code'], "number_of_knife_library": item['number_of_knife_library'], "rotate_speed": item['rotate_speed'], "number_of_axles": item['number_of_axles'], "x_axis": item['x_axis'], "y_axis": item['y_axis'], "z_axis": item['z_axis'], "b_axis": item['b_axis'], "knife_type": item['knife_type'], "c_axis": item['c_axis'], "remark": item['remark'], "precision_min": item['precision_min'], "precision_max": item['precision_max'], 'control_system_id': self.env['sf.machine.control_system'].search( [('code', '=', item['control_system_id'])]).id, "active": item['active'], 'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, 'machine_tool_picture': base64.b64decode(item['machine_tool_picture']), "heightened_way": item['heightened_way'], "workpiece_load": item['workpiece_load'], "lead_screw": item['lead_screw'], "workbench_L": item['workbench_L'], "workbench_W": item['workbench_W'], "guide_rail": item['guide_rail'], "machine_tool_L": item['machine_tool_L'], "machine_tool_W": item['machine_tool_W'], "machine_tool_H": item['machine_tool_H'], "feed_speed": item['feed_speed'], "tool_speed": item['tool_speed'], "distance_min": item['distance_min'], "distance_max": item['distance_max'], "taper": item['taper'], "torque": item['torque'], "motor_power": item['motor_power'], "tool_quality_max": item['tool_quality_max'], "tool_long_max": item['tool_long_max'], "tool_diameter_max": item['tool_diameter_max'], "tool_diameter_min": item['tool_diameter_min'], "machine_tool_category": self.env['sf.machine_tool.category'].search( [('code', '=', item['machine_tool_category'])]).id, }) else: raise ValidationError("认证未通过") class sfProcessingOrder(models.Model): _inherit = 'sf.processing.order' _description = '工序' url = '/api/processing_order/list' # 定时同步工序 def sync_processing_order(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['processing_order_yesterday_list']: brand = self.env['sf.processing.order'].search( [("id", '=', item['id'])]) if brand: brand.id = item['id'] brand.sequence = item['sequence'] else: self.env['sf.processing.order'].create({ "id": item['id'], "sequence": item['sequence'], }) else: raise ValidationError("认证未通过") # 同步所有工序 def sync_all_processing_order(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['processing_order_all_list']: brand = self.env['sf.processing.order'].search( [("id", '=', item['id'])]) if not brand: self.env['sf.processing.order'].create({ "id": item['id'], "sequence": item['sequence'], }) else: raise ValidationError("认证未通过") class sfProductionProcessParameter(models.Model): _inherit = 'sf.production.process.parameter' _description = '表面工艺可选参数' url = '/api/production_process_parameter/list' # 定时同步每日表面工艺 def sync_production_process_parameter(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['mrs_production_process_parameter_yesterday_list']: if item: brand = self.env['sf.production.process.parameter'].search( [("code", '=', item['code'])]) if brand: brand.name = item['name'], brand.code = item['code'], brand.active = item['active'], # brand.price = item['price'], else: self.env['sf.production.process.parameter'].create({ "name": item['name'], "code": item['code'], "active": item['active'], # "price": item['price'], "process_id": self.env['sf.production.process'].search( [('process_encode', '=', item['process_id_code'])]).id, 'materials_model_ids': self.env['sf.materials.model'].search( [('materials_no', 'in', item['materials_model_ids_codes'])]) }) else: raise ValidationError("认证未通过") # 定时同步表面工艺 # 同步所有表面工艺 def sync_all_production_process_parameter(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: _logger.info('result:%s' % result) for item in result['mrs_production_process_parameter_all_list']: if item: _logger.info('create可选参数:%s' % item) brand = self.env['sf.production.process.parameter'].search( [("code", '=', item['code'])]) if not brand: _logger.info('create可选参数:%s' % item) self.env['sf.production.process.parameter'].create({ "name": item['name'], "code": item['code'], # "price": item['price'], "active": item['active'], "process_id": self.env['sf.production.process'].search( [('process_encode', '=', item['process_id_code'])]).id, 'materials_model_ids': self.env['sf.materials.model'].search( [('materials_no', 'in', item['materials_model_ids_codes'])]) }) else: raise ValidationError("认证未通过") class MachineToolCategory(models.Model): _inherit = 'sf.machine_tool.category' _description = '机床类型' url = '/api/machine_tool_category/list' # 定时同步机床类型 def sync_machine_tool_category(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_tool_category_yesterday_list']: brand = self.env['sf.machine_tool.category'].search( [("code", '=', item['code'])]) if brand: brand.name = item['name'], brand.code = item['code'], brand.category = item['category'], brand.remark = item['remark'] else: brand.name = item['name'], brand.code = item['code'], brand.category = item['category'], brand.remark = item['remark'] else: raise ValidationError("认证未通过") # 同步所有机床类型 def sync_all_machine_tool_category(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_tool_category_all_list']: brand = self.env['sf.machine_tool.category'].search( [("code", '=', item['code'])]) if not brand: self.env['sf.machine_tool.category'].create({ "name": item['name'], "code": item['code'], "category": item['category'], "remark": item['remark'], }) else: raise ValidationError("认证未通过") # 同步刀具物料 class sfSyncCutting_tool_Material(models.Model): _inherit = 'sf.cutting.tool.material' _description = '刀具物料同步' url = '/api/mrs_cutting_tool_material/list' # 定时同步每日刀具物料 def sync_cutting_tool_material(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('mrs_cutting_tool_material_yesterday_list'): for item in result['mrs_cutting_tool_material_yesterday_list']: if item: brand = self.env['sf.cutting.tool.material'].search( [("code", '=', item['code'])]) if not brand: self.env['sf.cutting.tool.material'].create({ "name": item['name'], "code": item['code'], "remark": item['remark'], }) else: brand.write({ "name": item['name'], "code": item['code'], "remark": item['remark'], }) else: raise ValidationError("认证未通过") # 同步所有刀具物料 def sync_all_cutting_tool_material(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('mrs_cutting_tool_material_all_list'): for item in result['mrs_cutting_tool_material_all_list']: if item: brand = self.env['sf.cutting.tool.material'].search( [("code", '=', item['code'])]) if not brand: self.env['sf.cutting.tool.material'].create({ "name": item['name'], "code": item['code'], "remark": item['remark'], }) else: brand.write({ "name": item['name'], "code": item['code'], "remark": item['remark'], }) # 同步功能刀具列表 class sfSyncFunctional_cutting_tool(models.Model): _inherit = 'sf.functional.cutting.tool' _description = '功能刀具同步' url = '/api/mrs_functional_cutting_tool/list' # 定时同步每日功能刀具 def sync_functional_cutting_tool(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('mrs_functional_cutting_tool_yesterday_list'): for item in result['mrs_functional_cutting_tool_yesterday_list']: if item: brand = self.env['sf.functional.cutting.tool'].search( [("code", '=', item['code'])]) if item.get('image'): image = base64.b64decode(item['image']) else: image = '' if not brand: self.env['sf.functional.cutting.tool'].create({ "name": item['name'], "code": item['code'], # 功能刀具类型 "mrs_cutting_tool_type_id": self.env['sf.functional.cutting.tool.model'].search( [('code', '=', item['mrs_cutting_tool_type_id'])]).id, # # 刀具型号 # "mrs_cutting_tool_model_id": self.env['sf.cutting.tool.model'].search( # [('code', '=', item['mrs_cutting_tool_model_id'])]).id, "mrs_cutting_tool_integral_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_integral_model_ids']), "mrs_cutting_tool_blade_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_blade_model_ids']), "mrs_cutting_tool_cutterbar_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterbar_model_ids']), "mrs_cutting_tool_cutterpad_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterpad_model_ids']), "mrs_cutting_tool_cutterhandle_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterhandle_model_ids']), "mrs_cutting_tool_cutterhead_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterhead_model_ids']), "diameter": item['diameter'], "tool_grade": item['tool_grade'], "machining_accuracy": item['machining_accuracy'], "tool_length": item['tool_length'], "blade_number": item['blade_number'], "integral_blade_length": item['integral_blade_length'], "effective_blade_length": item['effective_blade_length'], "max_life": item['max_life'], "is_standard": item['is_standard'], "applicable_range": item['applicable_range'], "image": image, }) else: brand.write({ "name": item['name'], "code": item['code'], # 功能刀具类型 "mrs_cutting_tool_type_id": self.env['sf.functional.cutting.tool.model'].search( [('code', '=', item['mrs_cutting_tool_type_id'])]).id, "mrs_cutting_tool_integral_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_integral_model_ids']), "mrs_cutting_tool_blade_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_blade_model_ids']), "mrs_cutting_tool_cutterbar_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterbar_model_ids']), "mrs_cutting_tool_cutterpad_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterpad_model_ids']), "mrs_cutting_tool_cutterhandle_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterhandle_model_ids']), "mrs_cutting_tool_cutterhead_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterhead_model_ids']), "diameter": item['diameter'], "tool_grade": item['tool_grade'], "machining_accuracy": item['machining_accuracy'], "tool_length": item['tool_length'], "blade_number": item['blade_number'], "integral_blade_length": item['integral_blade_length'], "effective_blade_length": item['effective_blade_length'], "max_life": item['max_life'], "is_standard": item['is_standard'], "applicable_range": item['applicable_range'], "image": image, }) else: raise ValidationError("认证未通过") # 同步所有功能刀具 def sync_all_functional_cutting_tool(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) print('result:%s' % result) if result['status'] == 1: if result.get('mrs_functional_cutting_tool_all_list'): for item in result['mrs_functional_cutting_tool_all_list']: if item: brand = self.env['sf.functional.cutting.tool'].search( [("code", '=', item['code'])]) if item.get('image'): image = base64.b64decode(item['image']) else: image = '' if not brand: self.env['sf.functional.cutting.tool'].create({ "name": item['name'], "code": item['code'], # 功能刀具类型 "mrs_cutting_tool_type_id": self.env['sf.functional.cutting.tool.model'].search( [('code', '=', item['mrs_cutting_tool_type_id'])]).id, "mrs_cutting_tool_integral_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_integral_model_ids']), "mrs_cutting_tool_blade_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_blade_model_ids']), "mrs_cutting_tool_cutterbar_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterbar_model_ids']), "mrs_cutting_tool_cutterpad_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterpad_model_ids']), "mrs_cutting_tool_cutterhandle_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterhandle_model_ids']), "mrs_cutting_tool_cutterhead_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterhead_model_ids']), "diameter": item['diameter'], "tool_grade": item['tool_grade'], "machining_accuracy": item['machining_accuracy'], "tool_length": item['tool_length'], "blade_number": item['blade_number'], "integral_blade_length": item['integral_blade_length'], "effective_blade_length": item['effective_blade_length'], "max_life": item['max_life'], "is_standard": item['is_standard'], "applicable_range": item['applicable_range'], "image": image, }) else: brand.write({ "name": item['name'], "code": item['code'], # 功能刀具类型 "mrs_cutting_tool_type_id": self.env['sf.functional.cutting.tool.model'].search( [('code', '=', item['mrs_cutting_tool_type_id'])]).id, "mrs_cutting_tool_integral_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_integral_model_ids']), "mrs_cutting_tool_blade_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_blade_model_ids']), "mrs_cutting_tool_cutterbar_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterbar_model_ids']), "mrs_cutting_tool_cutterpad_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterpad_model_ids']), "mrs_cutting_tool_cutterhandle_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterhandle_model_ids']), "mrs_cutting_tool_cutterhead_model_ids": self._get_functional_tool_model_ids( item['mrs_cutting_tool_cutterhead_model_ids']), "diameter": item['diameter'], "tool_grade": item['tool_grade'], "machining_accuracy": item['machining_accuracy'], "tool_length": item['tool_length'], "blade_number": item['blade_number'], "integral_blade_length": item['integral_blade_length'], "effective_blade_length": item['effective_blade_length'], "max_life": item['max_life'], "is_standard": item['is_standard'], "applicable_range": item['applicable_range'], "image": image, }) else: raise ValidationError("认证未通过") # 同步功能刀具类型列表 class SyncFunctionalCuttingToolModel(models.Model): _inherit = 'sf.functional.cutting.tool.model' _description = '同步功能刀具类型列表' url = '/api/mrs_functional_cutting_tool_model/list' # 定时同步每日功能刀具类型列表 def sync_functional_cutting_tool_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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('mrs_functional_cutting_tool_model_yesterday_list'): for item in result['mrs_functional_cutting_tool_model_yesterday_list']: if item: brand = self.env['sf.functional.cutting.tool.model'].search( [("code", '=', item['code'])]) if not brand: self.env['sf.functional.cutting.tool.model'].create({ "name": item['name'], "code": item['code'], "remark": item['remark'], }) else: brand.write({ "name": item['name'], "code": item['code'], "remark": item['remark'], }) else: raise ValidationError("认证未通过") # 同步所有功能刀具类型列表 def sync_all_functional_cutting_tool_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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('mrs_functional_cutting_tool_model_all_list'): for item in result['mrs_functional_cutting_tool_model_all_list']: if item: brand = self.env['sf.functional.cutting.tool.model'].search( [("code", '=', item['code'])]) if not brand: self.env['sf.functional.cutting.tool.model'].create({ "name": item['name'], "code": item['code'], "remark": item['remark'], }) else: brand.write({ "name": item['name'], "code": item['code'], "remark": item['remark'], }) print('同步功能刀具类型列表成功') else: raise ValidationError("认证未通过") class SyncFixtureMaterial(models.Model): _inherit = 'sf.fixture.material' _description = '同步夹具物料列表' url = '/api/fixture_material/list' # 定时同步夹具物料列表 def sync_fixture_material(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('fixture_material_yesterday_list'): for item in result['fixture_material_yesterday_list']: if item: fixture_material = self.env['sf.fixture.material'].search( [("code", '=', item['code'])]) if not fixture_material: self.env['sf.fixture.material'].create({ "name": item['name'], "code": item['code'], "category": item['category'], "remark": item['remark'], "active": item['active'], }) else: fixture_material.write({ "name": item['name'], "category": item['category'], "remark": item['remark'], "active": item['active'], }) else: raise ValidationError("认证未通过") # 定时同步所有夹具物料列表 def sync_all_fixture_material(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('fixture_material_all_list'): for item in result['fixture_material_all_list']: if item: fixture_material = self.env['sf.fixture.material'].search( [("code", '=', item['code'])]) if not fixture_material: self.env['sf.fixture.material'].create({ "name": item['name'], "code": item['code'], "category": item['category'], "remark": item['remark'], "active": item['active'], }) else: fixture_material.write({ "name": item['name'], "category": item['category'], "remark": item['remark'], "active": item['active'], }) else: raise ValidationError("认证未通过") class SyncMulti_Mounting_Type(models.Model): _inherit = 'sf.multi_mounting.type' _description = '同步联装类型列表' url = '/api/multi_mounting_type/list' # 定时同步联装类型列表 def sync_multi_mounting_type(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('multi_mounting_type_yesterday_list'): for item in result['multi_mounting_type_yesterday_list']: if item: multi_mounting_type = self.env['sf.multi_mounting.type'].search( [("code", '=', item['code'])]) if not multi_mounting_type: self.env['sf.multi_mounting.type'].create({ "name": item['name'], "code": item['code'], "remark": item['remark'], "active": item['active'], }) else: multi_mounting_type.write({ "name": item['name'], "remark": item['remark'], "active": item['active'], }) else: raise ValidationError("认证未通过") # 定时同步所有联装类型列表 def sync_all_multi_mounting_type(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('multi_mounting_type_all_list'): for item in result['multi_mounting_type_all_list']: if item: multi_mounting_type = self.env['sf.multi_mounting.type'].search( [("code", '=', item['code'])]) if not multi_mounting_type: self.env['sf.multi_mounting.type'].create({ "name": item['name'], "code": item['code'], "remark": item['remark'], "active": item['active'], }) else: multi_mounting_type.write({ "name": item['name'], "remark": item['remark'], "active": item['active'], }) else: raise ValidationError("认证未通过") class SyncFixtureModel(models.Model): _inherit = 'sf.fixture.model' _description = '同步夹具型号列表' url = '/api/fixture_model/list' # 定时同步夹具型号列表 def sync_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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('fixture_model_yesterday_list'): for item in result['fixture_model_yesterday_list']: if item: fixture_model = self.env['sf.fixture.model'].search( [("code", '=', item['code'])]) if not fixture_model: self.env['sf.fixture.model'].create({ "name": item['name'], "code": item['code'], "fixture_material_id": self.env['sf.fixture.material'].search( [('code', '=', item['fixture_material_code'])]).id, "multi_mounting_type_id": self.env['sf.multi_mounting.type'].search( [('code', '=', item['multi_mounting_type_code'])]).id, "brand_id": self.env['sf.machine.brand'].search([('code', '=', item['brand_code'])]).id, "manufacturer_model_number": item['manufacturer_model_number'], "clamping_way": item['clamping_way'], "port_type": item['port_type'], "model_file": '' if not item['model_file'] else base64.b64decode(item['model_file']), "length": item['length'], "width": item['width'], "height": item['height'], "weight": item['weight'], "clamp_workpiece_length_max": item['clamp_workpiece_length_max'], "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'], "materials_model_id": self.env['sf.materials.model'].search( [('materials_no', '=', item['materials_model_code'])]).id, "driving_way": item['driving_way'], "apply_machine_tool_type_id": self.env['sf.machine_tool.type'].search( [('code', '=', item['apply_machine_tool_type_code'])]).id, "through_hole_size": item['through_hole_size'], "screw_size": item['screw_size'], }) else: fixture_model.write({ "name": item['name'], "fixture_material_id": self.env['sf.fixture.material'].search( [('code', '=', item['fixture_material_code'])]).id, "multi_mounting_type_id": self.env['sf.multi_mounting.type'].search( [('code', '=', item['multi_mounting_type_code'])]).id, "brand_id": self.env['sf.machine.brand'].search([('code', '=', item['brand_code'])]).id, "manufacturer_model_number": item['manufacturer_model_number'], "clamping_way": item['clamping_way'], "port_type": item['port_type'], "model_file": '' if not item['model_file'] else base64.b64decode(item['model_file']), "length": item['length'], "width": item['width'], "height": item['height'], "weight": item['weight'], "clamp_workpiece_length_max": item['clamp_workpiece_length_max'], "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'], "materials_model_id": self.env['sf.materials.model'].search( [('materials_no', '=', item['materials_model_code'])]).id, "driving_way": item['driving_way'], "apply_machine_tool_type_id": self.env['sf.machine_tool.type'].search( [('code', '=', item['apply_machine_tool_type_code'])]).id, "through_hole_size": item['through_hole_size'], "screw_size": item['screw_size'], }) else: raise ValidationError("认证未通过") # 定时同步所有夹具型号列表 def sync_all_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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('fixture_model_all_list'): for item in result['fixture_model_all_list']: if item: fixture_model = self.env['sf.fixture.model'].search( [("code", '=', item['code'])]) if not fixture_model: self.env['sf.fixture.model'].create({ "name": item['name'], "code": item['code'], "fixture_material_id": self.env['sf.fixture.material'].search( [('code', '=', item['fixture_material_code'])]).id, "multi_mounting_type_id": self.env['sf.multi_mounting.type'].search( [('code', '=', item['multi_mounting_type_code'])]).id, "brand_id": self.env['sf.machine.brand'].search([('code', '=', item['brand_code'])]).id, "manufacturer_model_number": item['manufacturer_model_number'], "clamping_way": item['clamping_way'], "port_type": item['port_type'], "model_file": '' if not item['model_file'] else base64.b64decode(item['model_file']), "length": item['length'], "width": item['width'], "height": item['height'], "weight": item['weight'], "clamp_workpiece_length_max": item['clamp_workpiece_length_max'], "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'], "materials_model_id": self.env['sf.materials.model'].search( [('materials_no', '=', item['materials_model_code'])]).id, "driving_way": item['driving_way'], "apply_machine_tool_type_id": self.env['sf.machine_tool.type'].search( [('code', '=', item['apply_machine_tool_type_code'])]).id, "through_hole_size": item['through_hole_size'], "screw_size": item['screw_size'], }) else: fixture_model.write({ "name": item['name'], "fixture_material_id": self.env['sf.fixture.material'].search( [('code', '=', item['fixture_material_code'])]).id, "multi_mounting_type_id": self.env['sf.multi_mounting.type'].search( [('code', '=', item['multi_mounting_type_code'])]).id, "brand_id": self.env['sf.machine.brand'].search([('code', '=', item['brand_code'])]).id, "manufacturer_model_number": item['manufacturer_model_number'], "clamping_way": item['clamping_way'], "port_type": item['port_type'], "model_file": '' if not item['model_file'] else base64.b64decode(item['model_file']), "length": item['length'], "width": item['width'], "height": item['height'], "weight": item['weight'], "clamp_workpiece_length_max": item['clamp_workpiece_length_max'], "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'], "materials_model_id": self.env['sf.materials.model'].search( [('materials_no', '=', item['materials_model_code'])]).id, "driving_way": item['driving_way'], "apply_machine_tool_type_id": self.env['sf.machine_tool.type'].search( [('code', '=', item['apply_machine_tool_type_code'])]).id, "through_hole_size": item['through_hole_size'], "screw_size": item['screw_size'], "active": item['active'], }) else: raise ValidationError("认证未通过") class SyncFunctionalFixtureType(models.Model): _inherit = 'sf.functional.fixture.type' _description = '同步功能夹具类型列表' url = '/api/functional_fixture_type/list' # 定时同步功能夹具类型列表 def sync_functional_fixture_type(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('functional_fixture_type_yesterday_list'): for item in result['functional_fixture_type_yesterday_list']: if item: functional_fixture_type = self.env['sf.functional.fixture.type'].search( [("code", '=', item['code'])]) if not functional_fixture_type: self.env['sf.functional.fixture.type'].create({ "name": item['name'], "code": item['code'], "remark": item['remark'], "active": item['active'], }) else: functional_fixture_type.write({ "name": item['name'], "remark": item['remark'], "active": item['active'], }) else: raise ValidationError("认证未通过") # 定时同步所有功能夹具类型列表 def sync_all_functional_fixture_type(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('functional_fixture_type_all_list'): for item in result['functional_fixture_type_all_list']: if item: functional_fixture_type = self.env['sf.functional.fixture.type'].search( [("code", '=', item['code'])]) if not functional_fixture_type: self.env['sf.functional.fixture.type'].create({ "name": item['name'], "code": item['code'], "remark": item['remark'], "active": item['active'], }) else: functional_fixture_type.write({ "name": item['name'], "remark": item['remark'], "active": item['active'], }) else: raise ValidationError("认证未通过") class SyncFunctionalFixture(models.Model): _inherit = 'sf.functional.fixture' _description = '同步功能夹具列表' url = '/api/functional_fixture/list' # 定时同步每日功能夹具列表 def sync_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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('functional_fixture_yesterday_list'): for item in result['functional_fixture_yesterday_list']: if item: functional_fixture = self.env['sf.functional.fixture'].search( [("code", '=', item['code'])]) if not functional_fixture: self.env['sf.functional.fixture'].create({ "name": item['name'], "code": item['code'], "type_id": self.env['sf.functional.fixture.type'].search( [("code", '=', item['functional_fixture_type_code'])]).id, "zero_chuck_model_ids": self._get_fixture_model_ids(item['zero_chuck_model_codes']), "transfer_tray_model_ids": self._get_fixture_model_ids( item['transfer_tray_model_codes']), "pneumatic_tray_model_ids": self._get_fixture_model_ids( item['pneumatic_tray_model_codes']), "magnetic_tray_model_ids": self._get_fixture_model_ids( item['magnetic_tray_model_codes']), "vice_tray_model_ids": self._get_fixture_model_ids(item['vice_tray_model_codes']), }) else: functional_fixture.write({ "name": item['name'], "type_id": self.env['sf.functional.fixture.type'].search( [("code", '=', item['functional_fixture_type_code'])]).id, "zero_chuck_model_ids": self._get_fixture_model_ids(item['zero_chuck_model_codes']), "transfer_tray_model_ids": self._get_fixture_model_ids( item['transfer_tray_model_codes']), "pneumatic_tray_model_ids": self._get_fixture_model_ids( item['pneumatic_tray_model_codes']), "magnetic_tray_model_ids": self._get_fixture_model_ids( item['magnetic_tray_model_codes']), "vice_tray_model_ids": self._get_fixture_model_ids(item['vice_tray_model_codes']), }) else: raise ValidationError("认证未通过") # 定时同步所有功能夹具列表 def sync_all_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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) # print('result:%s' % result) if result['status'] == 1: if result.get('functional_fixture_all_list'): for item in result['functional_fixture_all_list']: if item: functional_fixture = self.env['sf.functional.fixture'].search( [("code", '=', item['code'])]) if not functional_fixture: self.env['sf.functional.fixture'].create({ "name": item['name'], "code": item['code'], "type_id": self.env['sf.functional.fixture.type'].search( [("code", '=', item['functional_fixture_type_code'])]).id, "zero_chuck_model_ids": self._get_fixture_model_ids(item['zero_chuck_model_codes']), "transfer_tray_model_ids": self._get_fixture_model_ids( item['transfer_tray_model_codes']), "pneumatic_tray_model_ids": self._get_fixture_model_ids( item['pneumatic_tray_model_codes']), "magnetic_tray_model_ids": self._get_fixture_model_ids( item['magnetic_tray_model_codes']), "vice_tray_model_ids": self._get_fixture_model_ids(item['vice_tray_model_codes']), }) else: functional_fixture.write({ "name": item['name'], "type_id": self.env['sf.functional.fixture.type'].search( [("code", '=', item['functional_fixture_type_code'])]).id, "zero_chuck_model_ids": self._get_fixture_model_ids(item['zero_chuck_model_codes']), "transfer_tray_model_ids": self._get_fixture_model_ids( item['transfer_tray_model_codes']), "pneumatic_tray_model_ids": self._get_fixture_model_ids( item['pneumatic_tray_model_codes']), "magnetic_tray_model_ids": self._get_fixture_model_ids( item['magnetic_tray_model_codes']), "vice_tray_model_ids": self._get_fixture_model_ids(item['vice_tray_model_codes']), }) else: raise ValidationError("认证未通过") # 同步刀具类型 class SfToolType(models.Model): _inherit = 'sf.cutting.tool.type' _description = '同步刀具类型' url = '/api/mrs_cutting_tool_type/list' # 定时同步每日刀具类型 def sync_tool_type(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: _logger.info('result:%s' % result) for item in result['mrs_cutting_tool_type_yesterday_list']: if item: cutting_tool_type = self.env['sf.cutting.tool.type'].search( [("code", '=', item['code'])]) if not cutting_tool_type: self.env['sf.cutting.tool.type'].create({ "name": item['name'], "code": item['code'], "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['cutting_tool_material_code'])]).id, "remark": item['remark'], "active": item['active'], }) else: cutting_tool_type.write({ "name": item['name'], "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['cutting_tool_material_code'])]).id, "remark": item['remark'], "active": item['active'], }) else: raise ValidationError("认证未通过") # 同步所有刀具类型列表 def sync_all_tool_type(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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: _logger.info('result:%s' % result) for item in result['mrs_cutting_tool_type_all_list']: if item: cutting_tool_type = self.env['sf.cutting.tool.type'].search( [("code", '=', item['code'])]) if not cutting_tool_type: self.env['sf.cutting.tool.type'].create({ "name": item['name'], "code": item['code'], "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['cutting_tool_material_code'])]).id, "remark": item['remark'], "active": item['active'], }) else: cutting_tool_type.write({ "name": item['name'], "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['cutting_tool_material_code'])]).id, "remark": item['remark'], "active": item['active'], }) else: raise ValidationError("认证未通过") # 同步刀具型号 class SfToolModel(models.Model): _inherit = 'sf.cutting.tool.model' _description = '同步刀具型号' url = '/api/mrs_cutting_tool_model/list' # 定时同步每日刀具型号 def sync_tool_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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: _logger.info('result:%s' % result) for item in result['mrs_cutting_tool_model_yesterday_list']: cutting_tool_model = self.search( [("code", '=', item['code'])]) if not cutting_tool_model: self.env['sf.cutting.tool.model'].create({ "name": item['name'], "code": item['code'], "brand_id": self.env['sf.machine.brand'].search( [("code", '=', item['brand_code'])]).id, "material_model_id": self.env['sf.materials.model'].search( [("materials_no", '=', item['material_model_code'])]).id, "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['cutting_tool_material_code'])]).id, "cutting_tool_type_id": self.env['sf.cutting.tool.type'].search( [("code", '=', item['cutting_tool_type_code'])]).id, "tool_length": item['tool_length'], "tool_width": item['tool_width'], "tool_height": item['tool_height'], "tool_thickness": item['tool_thickness'], "tool_weight": item['tool_weight'], "coating_material": item['coating_material'], "total_length": item['total_length'], "shank_length": item['shank_length'], "blade_length": item['blade_length'], "front_angle": item['front_angle'], "rear_angle": item['rear_angle'], "main_included_angle": item['main_included_angle'], "nut": item['nut'], "top_angle": item['top_angle'], "jump_accuracy": item['jump_accuracy'], "working_hardness": item['working_hardness'], "blade_diameter": item['blade_diameter'], "wrench": item['wrench'], "screw": item['screw'], "accuracy_level": item['accuracy_level'], "diameter_max": item['diameter_max'], "clamping_diameter": item['clamping_diameter'], "flange_length": item['flange_length'], 'chuck_ids': [(6, 0, [])] if not item.get('chuck_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['chuck_codes']), 'cutter_bar_ids': [(6, 0, [])] if not item.get('cutter_bar_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['cutter_bar_codes']), 'cutter_pad_ids': [(6, 0, [])] if not item.get('cutter_pad_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['cutter_pad_codes']), 'blade_ids': [(6, 0, [])] if not item.get('blade_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['blade_codes']), 'handle_ids': [(6, 0, [])] if not item.get('handle_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['handle_codes']), "flange_diameter": item['flange_diameter'], "outer_diameter": item['outer_diameter'], "inner_diameter": item['inner_diameter'], "active": item['active'], }) else: cutting_tool_model.write({ "name": item['name'], "code": item['code'], "brand_id": self.env['sf.machine.brand'].search( [("code", '=', item['brand_code'])]).id, "material_model_id": self.env['sf.materials.model'].search( [("materials_no", '=', item['material_model_code'])]).id, "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['cutting_tool_material_code'])]).id, "cutting_tool_type_id": self.env['sf.cutting.tool.type'].search( [("code", '=', item['cutting_tool_type_code'])]).id, "tool_length": item['tool_length'], "tool_width": item['tool_width'], "tool_height": item['tool_height'], "tool_thickness": item['tool_thickness'], "tool_weight": item['tool_weight'], "coating_material": item['coating_material'], "total_length": item['total_length'], "shank_length": item['shank_length'], "blade_length": item['blade_length'], "front_angle": item['front_angle'], "rear_angle": item['rear_angle'], "main_included_angle": item['main_included_angle'], "nut": item['nut'], "top_angle": item['top_angle'], "jump_accuracy": item['jump_accuracy'], "working_hardness": item['working_hardness'], "blade_diameter": item['blade_diameter'], "wrench": item['wrench'], "screw": item['screw'], "accuracy_level": item['accuracy_level'], "diameter_max": item['diameter_max'], "clamping_diameter": item['clamping_diameter'], "flange_length": item['flange_length'], 'chuck_ids': [(6, 0, [])] if not item.get('chuck_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['chuck_codes']), 'cutter_bar_ids': [(6, 0, [])] if not item.get('cutter_bar_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['cutter_bar_codes']), 'cutter_pad_ids': [(6, 0, [])] if not item.get('cutter_pad_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['cutter_pad_codes']), 'blade_ids': [(6, 0, [])] if not item.get('blade_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['blade_codes']), 'handle_ids': [(6, 0, [])] if not item.get('handle_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['handle_codes']), "flange_diameter": item['flange_diameter'], "outer_diameter": item['outer_diameter'], "inner_diameter": item['inner_diameter'], "active": item['active'], }) print('同步所有刀柄类型列表成功') else: raise ValidationError("认证未通过") # 同步所有刀具型号列表 def sync_all_tool_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.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) print('result', result) if result['status'] == 1: _logger.info('result:%s' % result) for item in result['mrs_cutting_tool_model_all_list']: cutting_tool_model = self.search( [("code", '=', item['code'])]) if not cutting_tool_model: self.env['sf.cutting.tool.model'].create({ "name": item['name'], "code": item['code'], "brand_id": self.env['sf.machine.brand'].search( [("code", '=', item['brand_code'])]).id, "material_model_id": self.env['sf.materials.model'].search( [("materials_no", '=', item['material_model_code'])]).id, "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['cutting_tool_material_code'])]).id, "cutting_tool_type_id": self.env['sf.cutting.tool.type'].search( [("code", '=', item['cutting_tool_type_code'])]).id, "tool_length": item['tool_length'], "tool_width": item['tool_width'], "tool_height": item['tool_height'], "tool_thickness": item['tool_thickness'], "tool_weight": item['tool_weight'], "coating_material": item['coating_material'], "total_length": item['total_length'], "shank_length": item['shank_length'], "blade_length": item['blade_length'], "front_angle": item['front_angle'], "rear_angle": item['rear_angle'], "main_included_angle": item['main_included_angle'], "nut": item['nut'], "top_angle": item['top_angle'], "jump_accuracy": item['jump_accuracy'], "working_hardness": item['working_hardness'], "blade_diameter": item['blade_diameter'], "wrench": item['wrench'], "screw": item['screw'], "accuracy_level": item['accuracy_level'], "diameter_max": item['diameter_max'], "clamping_diameter": item['clamping_diameter'], "flange_length": item['flange_length'], 'chuck_ids': [(6, 0, [])] if not item.get('chuck_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['chuck_codes']), 'cutter_bar_ids': [(6, 0, [])] if not item.get('cutter_bar_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['cutter_bar_codes']), 'cutter_pad_ids': [(6, 0, [])] if not item.get('cutter_pad_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['cutter_pad_codes']), 'blade_ids': [(6, 0, [])] if not item.get('blade_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['blade_codes']), 'handle_ids': [(6, 0, [])] if not item.get('handle_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['handle_codes']), "flange_diameter": item['flange_diameter'], "outer_diameter": item['outer_diameter'], "inner_diameter": item['inner_diameter'], "active": item['active'], }) else: cutting_tool_model.write({ "name": item['name'], "code": item['code'], "brand_id": self.env['sf.machine.brand'].search( [("code", '=', item['brand_code'])]).id, "material_model_id": self.env['sf.materials.model'].search( [("materials_no", '=', item['material_model_code'])]).id, "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['cutting_tool_material_code'])]).id, "cutting_tool_type_id": self.env['sf.cutting.tool.type'].search( [("code", '=', item['cutting_tool_type_code'])]).id, "tool_length": item['tool_length'], "tool_width": item['tool_width'], "tool_height": item['tool_height'], "tool_thickness": item['tool_thickness'], "tool_weight": item['tool_weight'], "coating_material": item['coating_material'], "total_length": item['total_length'], "shank_length": item['shank_length'], "blade_length": item['blade_length'], "front_angle": item['front_angle'], "rear_angle": item['rear_angle'], "main_included_angle": item['main_included_angle'], "nut": item['nut'], "top_angle": item['top_angle'], "jump_accuracy": item['jump_accuracy'], "working_hardness": item['working_hardness'], "blade_diameter": item['blade_diameter'], "wrench": item['wrench'], "screw": item['screw'], "accuracy_level": item['accuracy_level'], "diameter_max": item['diameter_max'], "clamping_diameter": item['clamping_diameter'], "flange_length": item['flange_length'], 'chuck_ids': [(6, 0, [])] if not item.get('chuck_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['chuck_codes']), 'cutter_bar_ids': [(6, 0, [])] if not item.get('cutter_bar_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['cutter_bar_codes']), 'cutter_pad_ids': [(6, 0, [])] if not item.get('cutter_pad_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['cutter_pad_codes']), 'blade_ids': [(6, 0, [])] if not item.get('blade_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['blade_codes']), 'handle_ids': [(6, 0, [])] if not item.get('handle_codes') else self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( item['handle_codes']), "flange_diameter": item['flange_diameter'], "outer_diameter": item['outer_diameter'], "inner_diameter": item['inner_diameter'], "active": item['active'], }) print('同步所有刀具型号列表成功') else: raise ValidationError("认证未通过")