# -*- 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: brand = self.env['sf.materials.model'].search( [("materials_no", '=', item['materials_no'])]) if brand: brand.id = item['id'], brand.name = item['name'], brand.materials_no = item['materials_no'], brand.remark = item['remark'], brand.active = item['active'], brand.mf_materia_post = item['mf_materia_post'], brand.materials_id = self.env['sf.production.materials'].search( [("materials_no", '=', item['materials_id.materials_no'])]).id, brand.need_h = item['need_h'], brand.density = item['density'] else: self.env['sf.materials.model'].create({ "id": item['id'], "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], "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: brand = self.env['sf.materials.model'].search( [("materials_no", '=', item['materials_no'])]) if not brand: self.env['sf.materials.model'].create({ "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], "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("认证未通过") 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.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'], "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'], '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.active = item['active'] else: self.env['sf.machine.brand'].create({ "id": item['id'], "name": item['name'], "code": item['code'], # "image_brand": item['image_brand'], "active": item['active'], # "tag_ids": item['tag_ids'] }) 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'], "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 MachineTool(models.Model): _inherit = 'sf.machine_tool' _description = '机床' url = '/api/machine_tool/list' crea_url = '/api/machine_tool/create' # 定时同步机床 def sync_machine_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']) if result['status'] == 1: for item in result['machine_tool_all_yesterday_list']: brand = self.env['sf.machine_tool'].search( [("code", '=', item['code'])]) if brand: brand.id = item['id'], brand.name = item['name'], brand.code = item['code'], brand.precision = item['precision'], brand.knife_type = item['knife_type'], brand.registration_date = item['registration_date'], 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 = item['control_system_id'], brand.type_id = item['type_id'], brand.brand_id = item['brand_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.state = item['state'], brand.active = item['active'] else: self.env['sf.machine_tool'].create({ "id": item['id'], "name": item['name'], "precision": item['precision'], "code": item['code'], "status": item['status'], "knife_type": item['knife_type'], "registration_date": item['registration_date'], "number_of_knife_library": item['number_of_knife_library'], "rotate_speed": item['rotate_speed'], "number_of_axles": item['number_of_axles'], # "control_system_id": item['control_system_id'], "type_id": item['type_id'], "brand_id": item['brand_id'], "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'], "state": item['state'], "active": item['active'], # "tag_ids": item['tag_ids'] }) else: raise ValidationError("认证未通过") # 同步所有机床 def sync_all_machine_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']) if result['status'] == 1: for item in result['machine_tool_all_list']: brand = self.env['sf.machine_tool'].search( [("code", '=', item['code'])]) if not brand: self.env['sf.machine_tool'].create({ "id": item['id'], "name": item['name'], "precision": item['precision'], "code": item['code'], "status": item['status'], "knife_type": item['knife_type'], "registration_date": item['registration_date'], "number_of_knife_library": item['number_of_knife_library'], "rotate_speed": item['rotate_speed'], "number_of_axles": item['number_of_axles'], # "control_system_id": item['control_system_id'], "type_id": item['type_id'], 'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, "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'], "state": item['state'], "active": item['active'], # "tag_ids": item['tag_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.name = item['name'], brand.code = item['code'], brand.precision = item['precision'], 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, brand.machine_tool_id = self.env['sf.machine_tool'].search( [('code', '=', item['machine_tool_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'], "number_of_knife_library": item['number_of_knife_library'], "rotate_speed": item['rotate_speed'], 'machine_tool_id': self.env['sf.machine_tool'].search( [('code', '=', item['machine_tool_id'])]).id, "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": item['precision'], '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": item['distance'], "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'], "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']: 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'], 'machine_tool_id': self.env['sf.machine_tool'].search( [('code', '=', item['machine_tool_id'])]).id, "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": item['precision'], '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": item['distance'], "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'], "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'], 'machine_tool_id': self.env['sf.machine_tool'].search( [('code', '=', item['machine_tool_id'])]).id, "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": item['precision'], '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": item['distance'], "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'], "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.cutting.tool.type'].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, "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.cutting.tool.type'].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, "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.cutting.tool.type'].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, "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.cutting.tool.type'].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, "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'], "remark": item['remark'], }) else: fixture_material.write({ "name": item['name'], "remark": item['remark'], }) 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'], "remark": item['remark'], }) else: fixture_material.write({ "name": item['name'], "remark": item['remark'], }) 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'], }) else: multi_mounting_type.write({ "name": item['name'], "remark": item['remark'], }) 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'], }) else: multi_mounting_type.write({ "name": item['name'], "remark": item['remark'], }) 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, "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": item['apply_machine_tool_type'], "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, "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": item['apply_machine_tool_type'], "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, "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": item['apply_machine_tool_type'], "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, "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": item['apply_machine_tool_type'], "through_hole_size": item['through_hole_size'], "screw_size": item['screw_size'], }) 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'], }) else: functional_fixture_type.write({ "name": item['name'], "remark": item['remark'], }) 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'], }) else: functional_fixture_type.write({ "name": item['name'], "remark": item['remark'], }) 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'], "functional_fixture_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'], "functional_fixture_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'], "functional_fixture_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'], "functional_fixture_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: brand = self.env['sf.cutting.tool.type'].search( [("code", '=', item['code'])]) if not brand: self.env['sf.cutting.tool.type'].create({ "name": item['name'], "code": item['code'], "mrs_cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['mrs_cutting_tool_material_id'])]).id, "integral_tool_type_code": item['integral_tool_type_code'], "blade_type_code": item['blade_type_code'], "bar_type_code": item['bar_type_code'], "pad_type_code": item['pad_type_code'], "handle_type_code": item['handle_type_code'], "chuck_type_code": item['chuck_type_code'], "remark": item['remark'], }) else: brand.write({ "name": item['name'], "code": item['code'], "mrs_cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['mrs_cutting_tool_material_id'])]).id, "integral_tool_type_code": item['integral_tool_type_code'], "blade_type_code": item['blade_type_code'], "bar_type_code": item['bar_type_code'], "pad_type_code": item['pad_type_code'], "handle_type_code": item['handle_type_code'], "chuck_type_code": item['chuck_type_code'], "remark": item['remark'], }) 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: brand = self.env['sf.cutting.tool.type'].search( [("code", '=', item['code'])]) if not brand: self.env['sf.cutting.tool.type'].create({ "name": item['name'], "code": item['code'], "mrs_cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['mrs_cutting_tool_material_id'])]).id, "integral_tool_type_code": item['integral_tool_type_code'], "blade_type_code": item['blade_type_code'], "bar_type_code": item['bar_type_code'], "pad_type_code": item['pad_type_code'], "handle_type_code": item['handle_type_code'], "chuck_type_code": item['chuck_type_code'], "remark": item['remark'], }) else: brand.write({ "name": item['name'], "code": item['code'], "mrs_cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['mrs_cutting_tool_material_id'])]).id, "integral_tool_type_code": item['integral_tool_type_code'], "blade_type_code": item['blade_type_code'], "bar_type_code": item['bar_type_code'], "pad_type_code": item['pad_type_code'], "handle_type_code": item['handle_type_code'], "chuck_type_code": item['chuck_type_code'], "remark": item['remark'], }) 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']: mrs_cutting_tool_model_blade_cutter_bar_ids_list = [] if item.get('mrs_cutting_tool_model_blade_cutter_bar_ids'): for mrs_cutting_tool_model_blade_cutter_bar_id in item[ 'mrs_cutting_tool_model_blade_cutter_bar_ids']: mrs_cutting_tool_model_blade_cutter_bar_ids_list.append( self.env['sf.cutting.tool.model'].search( [("code", '=', mrs_cutting_tool_model_blade_cutter_bar_id)]).id) mrs_cutting_tool_model_blade_cutter_pad_ids_list = [] if item.get('mrs_cutting_tool_model_blade_cutter_pad_ids'): for mrs_cutting_tool_model_blade_cutter_pad_id in item[ 'mrs_cutting_tool_model_blade_cutter_pad_ids']: mrs_cutting_tool_model_blade_cutter_pad_ids_list.append( self.env['sf.cutting.tool.model'].search( [("code", '=', mrs_cutting_tool_model_blade_cutter_pad_id)]).id) mrs_cutting_tool_model_bar_blade_ids_list = [] if item.get('mrs_cutting_tool_model_bar_blade_ids'): for mrs_cutting_tool_model_bar_blade_id in item['mrs_cutting_tool_model_bar_blade_ids']: mrs_cutting_tool_model_bar_blade_ids_list.append(self.env['sf.cutting.tool.model'].search( [("code", '=', mrs_cutting_tool_model_bar_blade_id)]).id) mrs_cutting_tool_model_pad_blade_ids_list = [] if item.get('mrs_cutting_tool_model_pad_blade_ids'): for mrs_cutting_tool_model_pad_blade_id in item['mrs_cutting_tool_model_pad_blade_ids']: mrs_cutting_tool_model_pad_blade_ids_list.append(self.env['sf.cutting.tool.model'].search( [("code", '=', mrs_cutting_tool_model_pad_blade_id)]).id) mrs_cutting_tool_model_handle_chuck_model_ids_list = [] if item.get('mrs_cutting_tool_model_handle_chuck_model_ids'): for mrs_cutting_tool_model_handle_chuck_model_id in item[ 'mrs_cutting_tool_model_handle_chuck_model_ids']: mrs_cutting_tool_model_handle_chuck_model_ids_list.append( self.env['sf.cutting.tool.model'].search( [("code", '=', mrs_cutting_tool_model_handle_chuck_model_id)]).id) mrs_cutting_tool_model_chuck_handle_model_ids_list = [] if item.get('mrs_cutting_tool_model_chuck_handle_model_ids'): for mrs_cutting_tool_model_chuck_handle_model_id in item[ 'mrs_cutting_tool_model_chuck_handle_model_ids']: mrs_cutting_tool_model_chuck_handle_model_ids_list.append( self.env['sf.cutting.tool.model'].search( [("code", '=', mrs_cutting_tool_model_chuck_handle_model_id)]).id) if item: brand = self.env['sf.cutting.tool.model'].search( [("code", '=', item['code'])]) if item.get('image'): image = base64.b64decode(item['image']) else: image = '' if not brand: new_record = self.env['sf.cutting.tool.model'].create({ "name": item['name'], "code": item['code'], "mrs_machine_brand_id": self.env['sf.machine.brand'].search( [("code", '=', item['mrs_machine_brand_id'])]).id, "mrs_materials_model_id": self.env['sf.materials.model'].search( [("materials_no", '=', item['mrs_materials_model_id'])]).id, "mrs_cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['mrs_cutting_tool_material_id'])]).id, "mrs_cutting_tool_material_name": item['mrs_cutting_tool_material_name'], "mrs_cutting_tool_type_id": self.env['sf.cutting.tool.type'].search( [("code", '=', item['mrs_cutting_tool_type_id'])]).id, "integral_code": item['integral_code'], "integral_total_length": item['integral_total_length'], "integral_shank_length": item['integral_shank_length'], "integral_blade_length": item['integral_blade_length'], "integral_diameter": item['integral_diameter'], "integral_blade_number": item['integral_blade_number'], "integral_front_angle": item['integral_front_angle'], "integral_rear_angle": item['integral_rear_angle'], "integral_main_included_angle": item['integral_main_included_angle'], "integral_nut": item['integral_nut'], "integral_scope": item['integral_scope'], "blade_code": item['blade_code'], "blade_length": item['blade_length'], "blade_width": item['blade_width'], "blade_height": item['blade_height'], "blade_top_angle": item['blade_top_angle'], "blade_front_angle": item['blade_front_angle'], "blade_rear_angle": item['blade_rear_angle'], "blade_main_included_angle": item['blade_main_included_angle'], "blade_r_angle": item['blade_r_angle'], "blade_hardness": item['blade_hardness'], "blade_radius": item['blade_radius'], "blade_nut": item['blade_nut'], "mrs_cutting_tool_model_blade_cutter_bar_ids": mrs_cutting_tool_model_blade_cutter_bar_ids_list, "mrs_cutting_tool_model_blade_cutter_pad_ids": mrs_cutting_tool_model_blade_cutter_pad_ids_list, "bar_code": item['bar_code'], "bar_c_diameter": item['bar_c_diameter'], "bar_total_length": item['bar_total_length'], "bar_blade_number": item['bar_blade_number'], "bar_d_diameter": item['bar_d_diameter'], "mrs_cutting_tool_model_bar_blade_ids": mrs_cutting_tool_model_bar_blade_ids_list, "bar_wrench": item['bar_wrench'], "bar_screw": item['bar_screw'], "bar_radius": item['bar_radius'], "bar_accuracy": item['bar_accuracy'], "bar_hardness": item['bar_hardness'], "bar_scope": item['bar_scope'], "pad_code": item['pad_code'], "pad_c_diameter": item['pad_c_diameter'], "pad_total_length": item['pad_total_length'], "pad_blade_number": item['pad_blade_number'], "pad_d_diameter": item['pad_d_diameter'], "mrs_cutting_tool_model_pad_blade_ids": mrs_cutting_tool_model_pad_blade_ids_list, "pad_wrench": item['pad_wrench'], "pad_screw": item['pad_screw'], "pad_radius": item['pad_radius'], "pad_accuracy": item['pad_accuracy'], "pad_hardness": item['pad_hardness'], "pad_scope": item['pad_scope'], "handle_code": item['handle_code'], "handle_length": item['handle_length'], "handle_diameter": item['handle_diameter'], "handle_flange_length": item['handle_flange_length'], "handle_flange_diameter": item['handle_flange_diameter'], "handle_clamping_diameter_min": item['handle_clamping_diameter_min'], "handle_clamping_diameter_max": item['handle_clamping_diameter_max'], "handle_jump_accuracy": item['handle_jump_accuracy'], "handle_max_speed": item['handle_max_speed'], "handle_weight": item['handle_weight'], "handle_body_accuracy": item['handle_body_accuracy'], "handle_nut": item['handle_nut'], "mrs_cutting_tool_model_handle_chuck_model_ids": [ (6, 0, mrs_cutting_tool_model_handle_chuck_model_ids_list)], "handle_clamping_range": item['handle_clamping_range'], "handle_detection_accuracy": item['handle_detection_accuracy'], "handle_detection_hardness": item['handle_detection_hardness'], "handle_standard_speed": item['handle_standard_speed'], "chuck_code": item['chuck_code'], "chuck_accuracy": item['chuck_accuracy'], "chuck_diameter": item['chuck_diameter'], "chuck_inner_diameter": item['chuck_inner_diameter'], "chuck_height": item['chuck_height'], "chuck_nut": item['chuck_nut'], "mrs_cutting_tool_model_chuck_handle_model_ids": mrs_cutting_tool_model_chuck_handle_model_ids_list, "chuck_clamping_range": item['chuck_clamping_range'], "chuck_feature": item['chuck_feature'], "image": image, "hide_integral": item['hide_integral'], "hide_blade": item['hide_blade'], "hide_cutter_bar": item['hide_cutter_bar'], "hide_cutter_pad": item['hide_cutter_pad'], "hide_handler": item['hide_handler'], "hide_chuck": item['hide_chuck'], "hide_model": item['hide_model'], }) new_record.write({ 'mrs_cutting_tool_model_handle_chuck_model_ids': [ (6, 0, [new_record.id] * len(mrs_cutting_tool_model_handle_chuck_model_ids_list))], }) # many2many_commands = [(0, 0, {'model_id_1': new_record.id, 'model_id_2': related_record_id}) for # related_record_id in mrs_cutting_tool_model_handle_chuck_model_ids_list] # new_record.write({ # 'mrs_cutting_tool_model_handle_chuck_model_ids': many2many_commands, # }) else: brand.write({ "name": item['name'], "code": item['code'], "mrs_machine_brand_id": self.env['sf.machine.brand'].search( [("code", '=', item['mrs_machine_brand_id'])]).id, "mrs_materials_model_id": self.env['sf.materials.model'].search( [("materials_no", '=', item['mrs_materials_model_id'])]).id, "mrs_cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['mrs_cutting_tool_material_id'])]).id, "mrs_cutting_tool_material_name": item['mrs_cutting_tool_material_name'], "mrs_cutting_tool_type_id": self.env['sf.cutting.tool.type'].search( [("code", '=', item['mrs_cutting_tool_type_id'])]).id, "integral_code": item['integral_code'], "integral_total_length": item['integral_total_length'], "integral_shank_length": item['integral_shank_length'], "integral_blade_length": item['integral_blade_length'], "integral_diameter": item['integral_diameter'], "integral_blade_number": item['integral_blade_number'], "integral_front_angle": item['integral_front_angle'], "integral_rear_angle": item['integral_rear_angle'], "integral_main_included_angle": item['integral_main_included_angle'], "integral_nut": item['integral_nut'], "integral_scope": item['integral_scope'], "blade_code": item['blade_code'], "blade_length": item['blade_length'], "blade_width": item['blade_width'], "blade_height": item['blade_height'], "blade_top_angle": item['blade_top_angle'], "blade_front_angle": item['blade_front_angle'], "blade_rear_angle": item['blade_rear_angle'], "blade_main_included_angle": item['blade_main_included_angle'], "blade_r_angle": item['blade_r_angle'], "blade_hardness": item['blade_hardness'], "blade_radius": item['blade_radius'], "blade_nut": item['blade_nut'], "mrs_cutting_tool_model_blade_cutter_bar_ids": mrs_cutting_tool_model_blade_cutter_bar_ids_list, "mrs_cutting_tool_model_blade_cutter_pad_ids": mrs_cutting_tool_model_blade_cutter_pad_ids_list, "bar_code": item['bar_code'], "bar_c_diameter": item['bar_c_diameter'], "bar_total_length": item['bar_total_length'], "bar_blade_number": item['bar_blade_number'], "bar_d_diameter": item['bar_d_diameter'], "mrs_cutting_tool_model_bar_blade_ids": mrs_cutting_tool_model_bar_blade_ids_list, "bar_wrench": item['bar_wrench'], "bar_screw": item['bar_screw'], "bar_radius": item['bar_radius'], "bar_accuracy": item['bar_accuracy'], "bar_hardness": item['bar_hardness'], "bar_scope": item['bar_scope'], "pad_code": item['pad_code'], "pad_c_diameter": item['pad_c_diameter'], "pad_total_length": item['pad_total_length'], "pad_blade_number": item['pad_blade_number'], "pad_d_diameter": item['pad_d_diameter'], "mrs_cutting_tool_model_pad_blade_ids": mrs_cutting_tool_model_pad_blade_ids_list, "pad_wrench": item['pad_wrench'], "pad_screw": item['pad_screw'], "pad_radius": item['pad_radius'], "pad_accuracy": item['pad_accuracy'], "pad_hardness": item['pad_hardness'], "pad_scope": item['pad_scope'], "handle_code": item['handle_code'], "handle_length": item['handle_length'], "handle_diameter": item['handle_diameter'], "handle_flange_length": item['handle_flange_length'], "handle_flange_diameter": item['handle_flange_diameter'], "handle_clamping_diameter_min": item['handle_clamping_diameter_min'], "handle_clamping_diameter_max": item['handle_clamping_diameter_max'], "handle_jump_accuracy": item['handle_jump_accuracy'], "handle_max_speed": item['handle_max_speed'], "handle_weight": item['handle_weight'], "handle_body_accuracy": item['handle_body_accuracy'], "handle_nut": item['handle_nut'], "mrs_cutting_tool_model_handle_chuck_model_ids": [ (6, 0, mrs_cutting_tool_model_handle_chuck_model_ids_list)], "handle_clamping_range": item['handle_clamping_range'], "handle_detection_accuracy": item['handle_detection_accuracy'], "handle_detection_hardness": item['handle_detection_hardness'], "handle_standard_speed": item['handle_standard_speed'], "chuck_code": item['chuck_code'], "chuck_accuracy": item['chuck_accuracy'], "chuck_diameter": item['chuck_diameter'], "chuck_inner_diameter": item['chuck_inner_diameter'], "chuck_height": item['chuck_height'], "chuck_nut": item['chuck_nut'], "mrs_cutting_tool_model_chuck_handle_model_ids": mrs_cutting_tool_model_chuck_handle_model_ids_list, "chuck_clamping_range": item['chuck_clamping_range'], "chuck_feature": item['chuck_feature'], "image": image, "hide_integral": item['hide_integral'], "hide_blade": item['hide_blade'], "hide_cutter_bar": item['hide_cutter_bar'], "hide_cutter_pad": item['hide_cutter_pad'], "hide_handler": item['hide_handler'], "hide_chuck": item['hide_chuck'], "hide_model": item['hide_model'], }) brand.write({ 'mrs_cutting_tool_model_handle_chuck_model_ids': [ (6, 0, [brand.id] * len(mrs_cutting_tool_model_handle_chuck_model_ids_list))], }) # many2many_commands = [(0, 0, {'model_id_1': brand.id, 'model_id_2': related_record_id}) for # related_record_id in mrs_cutting_tool_model_handle_chuck_model_ids_list] # brand.write({ # 'mrs_cutting_tool_model_handle_chuck_model_ids': many2many_commands, # }) 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']: mrs_cutting_tool_model_blade_cutter_bar_ids_list = [] if item.get('mrs_cutting_tool_model_blade_cutter_bar_ids'): for mrs_cutting_tool_model_blade_cutter_bar_id in item[ 'mrs_cutting_tool_model_blade_cutter_bar_ids']: mrs_cutting_tool_model_blade_cutter_bar_ids_list.append( self.env['sf.cutting.tool.model'].search( [("code", '=', mrs_cutting_tool_model_blade_cutter_bar_id)]).id) mrs_cutting_tool_model_blade_cutter_pad_ids_list = [] if item.get('mrs_cutting_tool_model_blade_cutter_pad_ids'): for mrs_cutting_tool_model_blade_cutter_pad_id in item[ 'mrs_cutting_tool_model_blade_cutter_pad_ids']: mrs_cutting_tool_model_blade_cutter_pad_ids_list.append( self.env['sf.cutting.tool.model'].search( [("code", '=', mrs_cutting_tool_model_blade_cutter_pad_id)]).id) mrs_cutting_tool_model_bar_blade_ids_list = [] if item.get('mrs_cutting_tool_model_bar_blade_ids'): for mrs_cutting_tool_model_bar_blade_id in item['mrs_cutting_tool_model_bar_blade_ids']: mrs_cutting_tool_model_bar_blade_ids_list.append(self.env['sf.cutting.tool.model'].search( [("code", '=', mrs_cutting_tool_model_bar_blade_id)]).id) mrs_cutting_tool_model_pad_blade_ids_list = [] if item.get('mrs_cutting_tool_model_pad_blade_ids'): for mrs_cutting_tool_model_pad_blade_id in item['mrs_cutting_tool_model_pad_blade_ids']: mrs_cutting_tool_model_pad_blade_ids_list.append(self.env['sf.cutting.tool.model'].search( [("code", '=', mrs_cutting_tool_model_pad_blade_id)]).id) mrs_cutting_tool_model_handle_chuck_model_ids_list = [] if item.get('mrs_cutting_tool_model_handle_chuck_model_ids'): for mrs_cutting_tool_model_handle_chuck_model_id in item[ 'mrs_cutting_tool_model_handle_chuck_model_ids']: mrs_cutting_tool_model_handle_chuck_model_ids_list.append( self.env['sf.cutting.tool.model'].search( [("code", '=', mrs_cutting_tool_model_handle_chuck_model_id)]).id) mrs_cutting_tool_model_chuck_handle_model_ids_list = [] if item.get('mrs_cutting_tool_model_chuck_handle_model_ids'): for mrs_cutting_tool_model_chuck_handle_model_id in item[ 'mrs_cutting_tool_model_chuck_handle_model_ids']: mrs_cutting_tool_model_chuck_handle_model_ids_list.append( self.env['sf.cutting.tool.model'].search( [("code", '=', mrs_cutting_tool_model_chuck_handle_model_id)]).id) if item: brand = self.env['sf.cutting.tool.model'].search( [("code", '=', item['code'])]) if item.get('image'): image = base64.b64decode(item['image']) else: image = '' if not brand: new_record = self.env['sf.cutting.tool.model'].create({ "name": item['name'], "code": item['code'], "mrs_machine_brand_id": self.env['sf.machine.brand'].search( [("code", '=', item['mrs_machine_brand_id'])]).id, "mrs_materials_model_id": self.env['sf.materials.model'].search( [("materials_no", '=', item['mrs_materials_model_id'])]).id, "mrs_cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['mrs_cutting_tool_material_id'])]).id, "mrs_cutting_tool_material_name": item['mrs_cutting_tool_material_name'], "mrs_cutting_tool_type_id": self.env['sf.cutting.tool.type'].search( [("code", '=', item['mrs_cutting_tool_type_id'])]).id, "integral_code": item['integral_code'], "integral_total_length": item['integral_total_length'], "integral_shank_length": item['integral_shank_length'], "integral_blade_length": item['integral_blade_length'], "integral_diameter": item['integral_diameter'], "integral_blade_number": item['integral_blade_number'], "integral_front_angle": item['integral_front_angle'], "integral_rear_angle": item['integral_rear_angle'], "integral_main_included_angle": item['integral_main_included_angle'], "integral_nut": item['integral_nut'], "integral_scope": item['integral_scope'], "blade_code": item['blade_code'], "blade_length": item['blade_length'], "blade_width": item['blade_width'], "blade_height": item['blade_height'], "blade_top_angle": item['blade_top_angle'], "blade_front_angle": item['blade_front_angle'], "blade_rear_angle": item['blade_rear_angle'], "blade_main_included_angle": item['blade_main_included_angle'], "blade_r_angle": item['blade_r_angle'], "blade_hardness": item['blade_hardness'], "blade_radius": item['blade_radius'], "blade_nut": item['blade_nut'], "mrs_cutting_tool_model_blade_cutter_bar_ids": mrs_cutting_tool_model_blade_cutter_bar_ids_list, "mrs_cutting_tool_model_blade_cutter_pad_ids": mrs_cutting_tool_model_blade_cutter_pad_ids_list, "bar_code": item['bar_code'], "bar_c_diameter": item['bar_c_diameter'], "bar_total_length": item['bar_total_length'], "bar_blade_number": item['bar_blade_number'], "bar_d_diameter": item['bar_d_diameter'], "mrs_cutting_tool_model_bar_blade_ids": mrs_cutting_tool_model_bar_blade_ids_list, "bar_wrench": item['bar_wrench'], "bar_screw": item['bar_screw'], "bar_radius": item['bar_radius'], "bar_accuracy": item['bar_accuracy'], "bar_hardness": item['bar_hardness'], "bar_scope": item['bar_scope'], "pad_code": item['pad_code'], "pad_c_diameter": item['pad_c_diameter'], "pad_total_length": item['pad_total_length'], "pad_blade_number": item['pad_blade_number'], "pad_d_diameter": item['pad_d_diameter'], "mrs_cutting_tool_model_pad_blade_ids": mrs_cutting_tool_model_pad_blade_ids_list, "pad_wrench": item['pad_wrench'], "pad_screw": item['pad_screw'], "pad_radius": item['pad_radius'], "pad_accuracy": item['pad_accuracy'], "pad_hardness": item['pad_hardness'], "pad_scope": item['pad_scope'], "handle_code": item['handle_code'], "handle_length": item['handle_length'], "handle_diameter": item['handle_diameter'], "handle_flange_length": item['handle_flange_length'], "handle_flange_diameter": item['handle_flange_diameter'], "handle_clamping_diameter_min": item['handle_clamping_diameter_min'], "handle_clamping_diameter_max": item['handle_clamping_diameter_max'], "handle_jump_accuracy": item['handle_jump_accuracy'], "handle_max_speed": item['handle_max_speed'], "handle_weight": item['handle_weight'], "handle_body_accuracy": item['handle_body_accuracy'], "handle_nut": item['handle_nut'], # "mrs_cutting_tool_model_handle_chuck_model_ids": [(6, 0, mrs_cutting_tool_model_handle_chuck_model_ids_list)], "handle_clamping_range": item['handle_clamping_range'], "handle_detection_accuracy": item['handle_detection_accuracy'], "handle_detection_hardness": item['handle_detection_hardness'], "handle_standard_speed": item['handle_standard_speed'], "chuck_code": item['chuck_code'], "chuck_accuracy": item['chuck_accuracy'], "chuck_diameter": item['chuck_diameter'], "chuck_inner_diameter": item['chuck_inner_diameter'], "chuck_height": item['chuck_height'], "chuck_nut": item['chuck_nut'], "mrs_cutting_tool_model_chuck_handle_model_ids": mrs_cutting_tool_model_chuck_handle_model_ids_list, "chuck_clamping_range": item['chuck_clamping_range'], "chuck_feature": item['chuck_feature'], "image": image, "hide_integral": item['hide_integral'], "hide_blade": item['hide_blade'], "hide_cutter_bar": item['hide_cutter_bar'], "hide_cutter_pad": item['hide_cutter_pad'], "hide_handler": item['hide_handler'], "hide_chuck": item['hide_chuck'], "hide_model": item['hide_model'], }) new_record.write({ 'mrs_cutting_tool_model_handle_chuck_model_ids': [ (6, 0, [new_record.id] * len(mrs_cutting_tool_model_handle_chuck_model_ids_list))], }) else: brand.write({ "name": item['name'], "code": item['code'], "mrs_machine_brand_id": self.env['sf.machine.brand'].search( [("code", '=', item['mrs_machine_brand_id'])]).id, "mrs_materials_model_id": self.env['sf.materials.model'].search( [("materials_no", '=', item['mrs_materials_model_id'])]).id, "mrs_cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( [("code", '=', item['mrs_cutting_tool_material_id'])]).id, "mrs_cutting_tool_material_name": item['mrs_cutting_tool_material_name'], "mrs_cutting_tool_type_id": self.env['sf.cutting.tool.type'].search( [("code", '=', item['mrs_cutting_tool_type_id'])]).id, "integral_code": item['integral_code'], "integral_total_length": item['integral_total_length'], "integral_shank_length": item['integral_shank_length'], "integral_blade_length": item['integral_blade_length'], "integral_diameter": item['integral_diameter'], "integral_blade_number": item['integral_blade_number'], "integral_front_angle": item['integral_front_angle'], "integral_rear_angle": item['integral_rear_angle'], "integral_main_included_angle": item['integral_main_included_angle'], "integral_nut": item['integral_nut'], "integral_scope": item['integral_scope'], "blade_code": item['blade_code'], "blade_length": item['blade_length'], "blade_width": item['blade_width'], "blade_height": item['blade_height'], "blade_top_angle": item['blade_top_angle'], "blade_front_angle": item['blade_front_angle'], "blade_rear_angle": item['blade_rear_angle'], "blade_main_included_angle": item['blade_main_included_angle'], "blade_r_angle": item['blade_r_angle'], "blade_hardness": item['blade_hardness'], "blade_radius": item['blade_radius'], "blade_nut": item['blade_nut'], "mrs_cutting_tool_model_blade_cutter_bar_ids": mrs_cutting_tool_model_blade_cutter_bar_ids_list, "mrs_cutting_tool_model_blade_cutter_pad_ids": mrs_cutting_tool_model_blade_cutter_pad_ids_list, "bar_code": item['bar_code'], "bar_c_diameter": item['bar_c_diameter'], "bar_total_length": item['bar_total_length'], "bar_blade_number": item['bar_blade_number'], "bar_d_diameter": item['bar_d_diameter'], "mrs_cutting_tool_model_bar_blade_ids": mrs_cutting_tool_model_bar_blade_ids_list, "bar_wrench": item['bar_wrench'], "bar_screw": item['bar_screw'], "bar_radius": item['bar_radius'], "bar_accuracy": item['bar_accuracy'], "bar_hardness": item['bar_hardness'], "bar_scope": item['bar_scope'], "pad_code": item['pad_code'], "pad_c_diameter": item['pad_c_diameter'], "pad_total_length": item['pad_total_length'], "pad_blade_number": item['pad_blade_number'], "pad_d_diameter": item['pad_d_diameter'], "mrs_cutting_tool_model_pad_blade_ids": mrs_cutting_tool_model_pad_blade_ids_list, "pad_wrench": item['pad_wrench'], "pad_screw": item['pad_screw'], "pad_radius": item['pad_radius'], "pad_accuracy": item['pad_accuracy'], "pad_hardness": item['pad_hardness'], "pad_scope": item['pad_scope'], "handle_code": item['handle_code'], "handle_length": item['handle_length'], "handle_diameter": item['handle_diameter'], "handle_flange_length": item['handle_flange_length'], "handle_flange_diameter": item['handle_flange_diameter'], "handle_clamping_diameter_min": item['handle_clamping_diameter_min'], "handle_clamping_diameter_max": item['handle_clamping_diameter_max'], "handle_jump_accuracy": item['handle_jump_accuracy'], "handle_max_speed": item['handle_max_speed'], "handle_weight": item['handle_weight'], "handle_body_accuracy": item['handle_body_accuracy'], "handle_nut": item['handle_nut'], "mrs_cutting_tool_model_handle_chuck_model_ids": [ (6, 0, mrs_cutting_tool_model_handle_chuck_model_ids_list)], "handle_clamping_range": item['handle_clamping_range'], "handle_detection_accuracy": item['handle_detection_accuracy'], "handle_detection_hardness": item['handle_detection_hardness'], "handle_standard_speed": item['handle_standard_speed'], "chuck_code": item['chuck_code'], "chuck_accuracy": item['chuck_accuracy'], "chuck_diameter": item['chuck_diameter'], "chuck_inner_diameter": item['chuck_inner_diameter'], "chuck_height": item['chuck_height'], "chuck_nut": item['chuck_nut'], "mrs_cutting_tool_model_chuck_handle_model_ids": mrs_cutting_tool_model_chuck_handle_model_ids_list, "chuck_clamping_range": item['chuck_clamping_range'], "chuck_feature": item['chuck_feature'], "image": image, "hide_integral": item['hide_integral'], "hide_blade": item['hide_blade'], "hide_cutter_bar": item['hide_cutter_bar'], "hide_cutter_pad": item['hide_cutter_pad'], "hide_handler": item['hide_handler'], "hide_chuck": item['hide_chuck'], "hide_model": item['hide_model'], }) brand.write({ 'mrs_cutting_tool_model_handle_chuck_model_ids': [ (6, 0, [brand.id] * len(mrs_cutting_tool_model_handle_chuck_model_ids_list))], }) # many2many_commands = [(0, 0, {'model_id_1': brand.id, 'model_id_2': related_record_id}) for # related_record_id in mrs_cutting_tool_model_handle_chuck_model_ids_list] # brand.write({ # 'mrs_cutting_tool_model_handle_chuck_model_ids': many2many_commands, # }) print('同步所有刀具型号列表成功') else: raise ValidationError("认证未通过")