# -*- 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 MrStaticResourceDataSync(models.Model): _name = 'sf.static.resource.datasync' _description = '同步cloud的静态资源库' def _cron_static_resource_yesterday_func(self): try: self.env['sf.machine.brand.tags'].sync_machine_brand_tags_yesterday() logging.info("品牌类别已每日同步成功") self.env['sf.machine.brand'].sync_machine_brand_yesterday() logging.info("品牌已每日同步成功") self.env['sf.machine_tool.category'].sync_machine_tool_category_yesterday() logging.info("机床类型已每日同步成功") self.env['sf.machine_tool.type'].sync_machine_tool_type_yesterday() logging.info("机床型号已每日同步成功") self.env['sf.machine.control_system'].sync_machine_control_system_yesterday() logging.info("数控系统已每日同步成功") self.env['sf.production.materials'].sync_production_materials_yesterday() logging.info("材料已每日同步成功") self.env['sf.materials.model'].sync_materials_model_yesterday() # logging.info("材料型号已每日同步成功") # self.env['mrs.international.standards']._cron_mrs_international_standards_func() # logging.info("材料型号材料应用已每日同步成功") # self.env['material.apply']._cron_material_apply_func() logging.info("材料型号材料应用已每日同步成功") self.env['sf.production.process.category'].sync_production_process_category_yesterday() logging.info("表面工艺类别已每日同步成功") self.env['sf.production.process'].sync_production_process_yesterday() logging.info("表面工艺已每日同步成功") self.env['sf.production.process.parameter'].sync_production_process_parameter_yesterday() logging.info("表面工艺可选参数已每日同步成功") self.env['sf.processing.technology'].sync_processing_technology_yesterday() logging.info("加工工艺已每日同步成功") self.env['sf.processing.order'].sync_processing_order_yesterday() logging.info("工序已同步已每日同步成功") self.env['sf.fixture.material'].sync_fixture_material_yesterday() logging.info("夹具物料已每日同步成功") self.env['sf.multi_mounting.type'].sync_multi_mounting_type_yesterday() logging.info("联装类型已每日同步成功") self.env['sf.fixture.model'].sync_fixture_model_yesterday() logging.info("夹具型号已每日同步成功") self.env['sf.functional.fixture.type'].sync_functional_fixture_type_yesterday() logging.info("功能夹具类型已每日同步成功") self.env['sf.cutting.tool.material'].sync_cutting_tool_material_yesterday() logging.info("刀具物料已每日同步成功") self.env['sf.cutting.tool.type'].sync_tool_type_yesterday() logging.info("刀具类型已每日同步成功") self.env['sf.cutting_tool.standard.library'].sync_cutting_tool_standard_library_yesterday() logging.info("刀具标准库已每日同步成功") self.env['sf.functional.cutting.tool.model'].sync_functional_cutting_tool_model_yesterday() logging.info("功能刀具类型已每日同步成功") self.env['maintenance.equipment.image'].sync_maintenance_equipment_image_yesterday() logging.info("能力特征库已每日同步成功") except Exception as e: logging.info("捕获错误信息:%s" % e) raise ValidationError("数据错误导致同步失败,请联系管理员") class sfProductionMaterials(models.Model): _inherit = "sf.production.materials" _description = "材料" url = '/api/production_materials/list' # 定时同步每日材料 def sync_production_materials_yesterday(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: materials = self.search([("materials_no", '=', item['materials_no'])]) if materials: materials.name = item['name'] materials.remark = item['remark'] materials.active = item['active'] else: self.create({ "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], "active": item['active'], }) else: raise ValidationError("材料认证未通过") # 同步所有材料 def sync_all_production_materials(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_materials_all_list']: if item: materials = self.search([("materials_no", '=', item['materials_no'])]) if not materials: self.create({ "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], "active": item['active'], }) else: materials.name = item['name'] materials.remark = item['remark'] materials.active = item['active'] else: raise ValidationError("材料认证未通过") class sfMaterialModel(models.Model): _inherit = 'sf.materials.model' _description = '材料型号' url = '/api/materials_model/list' # 定时同步每日材料型号 def sync_materials_model_yesterday(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.search([("materials_no", '=', item['materials_no'])]) materials = self.env['sf.production.materials'].search( [("materials_no", '=', item['materials_id.materials_no'])]) if materials_model: 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 = materials.id materials_model.need_h = item['need_h'] materials_model.density = item['density'] materials_model.active = item['active'] else: self.create({ "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": materials.id, "need_h": item['need_h'], "mf_materia_post": item['mf_materia_post'], "density": item['density'], }) 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.search([("materials_no", '=', item['materials_no'])]) materials = self.env['sf.production.materials'].search( [("materials_no", '=', item['materials_id.materials_no'])]) if not materials_model: self.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, "standards_id": self.env['sf.international.standards'].search( [("name", '=', item['standards_id'])]).id, "need_h": item['need_h'], "alloy_code": item['alloy_code'], "mf_materia_post": item['mf_materia_post'], "density": item['density'], "materials_code": item['materials_code'], "apply": self.env['material.apply'].search( [("name", 'in', item['apply'])]).ids # "tag_ids": item['tag_ids'] }) else: materials_model.name = item['name'] 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 = materials.id materials_model.need_h = item['need_h'] materials_model.density = item['density'] materials_model.active = item['active'] else: raise ValidationError("材料型号认证未通过") class sfProductionProcessCategory(models.Model): _inherit = 'sf.production.process.category' _description = '表面工艺类别' url = '/api/production_process_category/list' # 定时同步每日表面工艺类别 def sync_production_process_category_yesterday(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.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.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.search([("code", '=', item['code'])]) if not category: self.create({ "name": item['name'], "code": item['code'], "active": item['active'], }) else: category.name = item['name'] category.active = item['active'] else: raise ValidationError("表面工艺类别认证未通过") class sfProductionProcess(models.Model): _inherit = 'sf.production.process' _description = '表面工艺' url = '/api/production_process/list' # 定时同步每日表面工艺 def sync_production_process_yesterday(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( [("code", '=', item['code'])]) if brand: brand.name = item['name'], brand.category_id = self.env['sf.production.process.category'].search( [("code", '=', item['category_code'])]).id, brand.code = item['code'], brand.remark = item['remark'], brand.active = item['active'], brand.remark = item['remark'] production_process = self.search([("code", '=', item['code'])]) category = self.env['sf.production.process.category'].search( [("code", '=', item['category_code'])]) if production_process: production_process.name = item['name'] production_process.category_id = category.id production_process.remark = item['remark'] production_process.active = item['active'] else: self.create({ "name": item['name'], "category_id": self.env['sf.production.process.category'].search( [("code", '=', item['category_code'])]).id, "code": item['code'], "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: production_process = self.search([("code", '=', item['code'])]) category = self.env['sf.production.process.category'].search( [("code", '=', item['category_code'])]) if not production_process: self.create({ "name": item['name'], "category_id": category.id, "code": item['code'], "remark": item['remark'], "active": item['active'], }) else: production_process.name = item['name'] production_process.category_id = category.id production_process.remark = item['remark'] production_process.active = item['active'] else: raise ValidationError("表面工艺认证未通过") class sfProcessingTechnology(models.Model): _inherit = 'sf.processing.technology' _description = '加工工艺' url = '/api/processing_technology/list' # 定时同步加工工艺 def sync_processing_technology_yesterday(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: processing_technology = self.search([("code", '=', item['code'])]) if processing_technology: processing_technology.name = item['name'] processing_technology.remark = item['remark'] processing_technology.active = item['active'] else: self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], "active": item['active'], }) 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: processing_technology = self.search([("code", '=', item['code'])]) if not processing_technology: self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], "active": item['active'], }) else: processing_technology.name = item['name'] processing_technology.remark = item['remark'] processing_technology.active = item['active'] else: raise ValidationError("加工工艺认证未通过") class MachineBrandTags(models.Model): _inherit = 'sf.machine.brand.tags' _description = '品牌类别' url = '/api/machine_brand_tags/list' # 定时同步品牌类别 def sync_machine_brand_tags_yesterday(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_tags = self.search([("id", '=', item['id'])]) if brand_tags: brand_tags.name = item['name'] brand_tags.color = item['color'] else: self.create({ "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_tags = self.search([("name", '=', item['name'])]) if not brand_tags: self.create({ "name": item['name'], "color": item['color'], }) else: brand_tags.name = item['name'] brand_tags.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_control_system_yesterday(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: control_system = self.search([("code", '=', item['code'])]) brand = self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]) if control_system: control_system.name = item['name'] control_system.remark = item['remark'] control_system.brand_id = brand.id control_system.active = item['active'] else: self.create({ "remark": item['remark'], "name": item['name'], "code": item['code'], 'brand_id': brand.id, "active": item['active'], }) else: raise ValidationError("数控系统认证未通过") # 同步所有控制系统 def sync_all_machine_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: control_system = self.search([("code", '=', item['code'])]) brand = self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]) if not control_system: self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], 'brand_id': brand.id, "active": item['active'], }) else: control_system.name = item['name'] control_system.remark = item['remark'] control_system.brand_id = brand.id control_system.active = item['active'] else: raise ValidationError("数控系统认证未通过") class MachineBrand(models.Model): _inherit = 'sf.machine.brand' _description = '品牌' url = '/api/machine_brand/list' # 定时同步品牌 def sync_machine_brand_yesterday(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.search([("code", '=', item['code'])]) if brand: brand.name = item['name'] brand.image_brand = '' if not item['image_brand'] else base64.b64decode(item['image_brand']) brand.active = item['active'] brand.remark = item['remark'] brand.tag_ids = self.env['sf.machine.brand.tags'].search([("name", 'in', item['tag_ids'])]).ids else: self.create({ "name": item['name'], "code": item['code'], "image_brand": '' if not item['image_brand'] else base64.b64decode(item['image_brand']), "active": item['active'], "remark": item['remark'], "tag_ids": self.env['sf.machine.brand.tags'].search([("name", 'in', item['tag_ids'])]).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.search([("code", '=', item['code'])]) if not brand: self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], "image_brand": '' if not item['image_brand'] else base64.b64decode(item['image_brand']), "tag_ids": self.env['sf.machine.brand.tags'].search( [("name", 'in', item['tag_ids'])]).ids }) else: brand.name = item['name'] brand.remark = item['remark'] brand.image_brand = '' if not item['image_brand'] else base64.b64decode(item['image_brand']) 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_yesterday(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']: machine_tool_type = self.search([("code", '=', item['code'])]) control_system = self.env['sf.machine.control_system'].search( [('code', '=', item['control_system_id'])]) brand = self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]) category = self.env['sf.machine_tool.category'].search([('code', '=', item['machine_tool_category'])]) if machine_tool_type: machine_tool_type.write({ "name": item['name'], "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': control_system.id, "active": item['active'], 'brand_id': brand.id, 'machine_tool_picture': '' if not item['machine_tool_picture'] else 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": category.id, }) else: self.create({ "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': control_system.id, "active": item['active'], 'brand_id': brand.id, 'machine_tool_picture': '' if not item['machine_tool_picture'] else 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": 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 = '' machine_tool_type = self.search([("code", '=', item['code'])]) control_system = self.env['sf.machine.control_system'].search( [('code', '=', item['control_system_id'])]) brand = self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]) category = self.env['sf.machine_tool.category'].search([('code', '=', item['machine_tool_category'])]) if not machine_tool_type: self.create({ "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': control_system.id, "active": item['active'], 'brand_id': brand.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": category.id, }) else: machine_tool_type.write({ "name": item['name'], "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': control_system.id, "active": item['active'], 'brand_id': brand.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": category.id, }) else: raise ValidationError("机床型号认证未通过") class sfProcessingOrder(models.Model): _inherit = 'sf.processing.order' _description = '工序' url = '/api/processing_order/list' # 定时同步工序 def sync_processing_order_yesterday(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']: processing_order = self.search([("id", '=', item['id'])]) if processing_order: processing_order.sequence = item['sequence'] else: self.create({ "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']: processing_order = self.search([("id", '=', item['id'])]) if not processing_order: self.create({ "sequence": item['sequence'], }) else: processing_order.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_yesterday(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: production_process_parameter = self.search([("code", '=', item['code'])]) process = self.env['sf.production.process'].search( [('code', '=', item['process_id_code'])]) if production_process_parameter: production_process_parameter.name = item['name'] production_process_parameter.active = item['active'] production_process_parameter.process_id = process.id production_process_parameter.materials_model_ids = self.env['sf.materials.model'].search( [('materials_no', 'in', item['materials_model_ids_codes'])]) else: self.create({ "name": item['name'], "code": item['code'], "active": item['active'], "process_id": process.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: for item in result['mrs_production_process_parameter_all_list']: if item: production_process_parameter = self.search( [("code", '=', item['code'])]) process = self.env['sf.production.process'].search( [('code', '=', item['process_id_code'])], limit=1) if not production_process_parameter: self.create({ "name": item['name'], "code": item['code'], "active": item['active'], "process_id": process.id, 'materials_model_ids': self.env['sf.materials.model'].search( [('materials_no', 'in', item['materials_model_ids_codes'])]), }) else: production_process_parameter.name = item['name'] production_process_parameter.process_id = process.id production_process_parameter.materials_model_ids = self.env['sf.materials.model'].search( [('materials_no', 'in', item['materials_model_ids_codes'])]) production_process_parameter.active = item['active'] else: raise ValidationError("表面工艺可选参数认证未通过") class MachineToolCategory(models.Model): _inherit = 'sf.machine_tool.category' _description = '机床类型' url = '/api/machine_tool_category/list' # 定时同步机床类型 def sync_machine_tool_category_yesterday(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']: machine_tool_category = self.search([("code", '=', item['code'])]) if machine_tool_category: machine_tool_category.name = item['name'] machine_tool_category.category = item['category'] machine_tool_category.remark = item['remark'] machine_tool_category.active = item['active'] else: self.create({ "name": item['name'], "code": item['code'], "category": item['category'], "remark": item['remark'], "active": item['active'], }) 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']: machine_tool_category = self.search([("code", '=', item['code'])]) if not machine_tool_category: self.create({ "name": item['name'], "code": item['code'], "category": item['category'], "remark": item['remark'], "active": item['active'], }) else: machine_tool_category.name = item['name'] machine_tool_category.category = item['category'] machine_tool_category.remark = item['remark'] machine_tool_category.active = item['active'] 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_yesterday(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: cutting_tool_material = self.search([("code", '=', item['code'])]) if not cutting_tool_material: self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], "active": item['active'], }) else: cutting_tool_material.write({ "name": item['name'], "remark": item['remark'], "active": item['active'], }) 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: cutting_tool_material = self.search([("code", '=', item['code'])]) if not cutting_tool_material: self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], "active": item['active'], }) else: cutting_tool_material.write({ "name": item['name'], "remark": item['remark'], "active": item['active'], }) 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_yesterday(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: functional_cutting_tool_model = self.search([("code", '=', item['code'])]) if not functional_cutting_tool_model: self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], "active": item['active'], }) else: functional_cutting_tool_model.write({ "name": item['name'], "remark": item['remark'], "active": item['active'], }) 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: functional_cutting_tool_model = self.search([("code", '=', item['code'])]) if not functional_cutting_tool_model: self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], "active": item['active'], }) else: functional_cutting_tool_model.write({ "name": item['name'], "remark": item['remark'], "active": item['active'], }) else: raise ValidationError("功能刀具类型认证未通过") class SyncFixtureMaterial(models.Model): _inherit = 'sf.fixture.material' _description = '同步夹具物料列表' url = '/api/fixture_material/list' # 定时同步夹具物料列表 def sync_fixture_material_yesterday(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.search([("code", '=', item['code'])]) if not fixture_material: self.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.search([("code", '=', item['code'])]) if not fixture_material: self.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_yesterday(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: if result.get('multi_mounting_type_yesterday_list'): for item in result['multi_mounting_type_yesterday_list']: if item: multi_mounting_type = self.search([("code", '=', item['code'])]) if not multi_mounting_type: self.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.search([("code", '=', item['code'])]) if not multi_mounting_type: self.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_yesterday(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: if result.get('fixture_model_yesterday_list'): for item in result['fixture_model_yesterday_list']: if item: fixture_model = self.search([("code", '=', item['code'])]) if not fixture_model: self.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_ids": self.env['sf.machine_tool.type'].sudo()._get_ids( item['apply_machine_tool_type_code']), "through_hole_size": item['through_hole_size'], "screw_size": item['screw_size'], "active": item['active'], }) 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_ids": self.env['sf.machine_tool.type'].sudo()._get_ids( item['apply_machine_tool_type_code']), "through_hole_size": item['through_hole_size'], "screw_size": item['screw_size'], "active": item['active'], }) 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.search([("code", '=', item['code'])]) if not fixture_model: self.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_ids": self.env['sf.machine_tool.type'].sudo()._get_ids( item['apply_machine_tool_type_code']), "through_hole_size": item['through_hole_size'], "screw_size": item['screw_size'], "active": item['active'], }) 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_ids": self.env['sf.machine_tool.type'].sudo()._get_ids( item['apply_machine_tool_type_code']), "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_yesterday(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.search([("code", '=', item['code'])]) if not functional_fixture_type: self.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']) 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.search([("code", '=', item['code'])]) if not functional_fixture_type: self.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 SfToolType(models.Model): _inherit = 'sf.cutting.tool.type' _description = '同步刀具类型' url = '/api/mrs_cutting_tool_type/list' # 定时同步每日刀具类型 def sync_tool_type_yesterday(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_cutting_tool_type_yesterday_list']: if item: cutting_tool_type = self.search([("code", '=', item['code'])]) cutting_tool_material = self.env['sf.cutting.tool.material'].search( [("code", '=', item['cutting_tool_material_code'])]) if not cutting_tool_type: self.create({ "name": item['name'], "code": item['code'], "cutting_tool_material_id": cutting_tool_material.id, "remark": item['remark'], "active": item['active'], }) else: cutting_tool_type.write({ "name": item['name'], "cutting_tool_material_id": cutting_tool_material.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: for item in result['mrs_cutting_tool_type_all_list']: if item: cutting_tool_type = self.search([("code", '=', item['code'])]) cutting_tool_material = self.env['sf.cutting.tool.material'].search( [("code", '=', item['cutting_tool_material_code'])]) if not cutting_tool_type: self.create({ "name": item['name'], "code": item['code'], "cutting_tool_material_id": cutting_tool_material.id, "remark": item['remark'], "active": item['active'], }) else: cutting_tool_type.write({ "name": item['name'], "cutting_tool_material_id": cutting_tool_material.id, "remark": item['remark'], "active": item['active'], }) else: raise ValidationError("刀具类型认证未通过") # 同步能力特征库 class SfMaintenanceEquipmentImage(models.Model): _inherit = 'maintenance.equipment.image' _description = '能力特征库' url = '/api/maintenance_equipment_image/list' # 定时同步每日能力特征库 def sync_maintenance_equipment_image_yesterday(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['ability_feature_library_yesterday_list']: if item: ability_feature_library = self.search([("name", '=', item['name'])]) if not ability_feature_library: self.create({ "name": item['name'], "type": item['type'], "image": '' if not item['image'] else base64.b64decode(item['image']), "active": item['active'], }) else: ability_feature_library.write({ "type": item['type'], "image": '' if not item['image'] else base64.b64decode(item['image']), "active": item['active'], }) else: raise ValidationError("能力特征库认证未通过") # 同步所有能力特征库 def sync_all_maintenance_equipment_image(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['ability_feature_library_all_list']: if item: ability_feature_library = self.search([("name", '=', item['name'])]) if not ability_feature_library: self.create({ "name": item['name'], "type": item['type'], "image": '' if not item['image'] else base64.b64decode(item['image']), "active": item['active'], }) else: ability_feature_library.write({ "type": item['type'], "image": '' if not item['image'] else base64.b64decode(item['image']), "active": item['active'], }) else: raise ValidationError("认证未通过") class MaterialApply(models.Model): _inherit = 'material.apply' _description = '材料应用' url = '/api/material_apply/list' # 定时同步材料应用 def sync_material_apply(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['material_apply_yesterday_list']: material_apply = self.search([("name", '=', item['name'])]) if material_apply: material_apply.name = item['name'] material_apply.active = item['active'] else: self.create({ "name": item['name'], "active": item['active'], }) else: raise ValidationError("材料应用认证未通过") # 同步所有材料应用 def sync_all_material_apply(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['material_apply_all_list']: material_apply = self.search([("name", '=', item['name'])]) if not material_apply: self.create({ "name": item['name'], "active": item['active'], }) else: material_apply.name = item['name'] material_apply.active = item['active'] else: raise ValidationError("材料应用认证未通过") class ModelInternationalStandards(models.Model): _inherit = 'sf.international.standards' _description = '制造标准' url = '/api/mrs_international_standards/list' # 定时同步制造标准 def sync_mrs_international_standards(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_international_standards_yesterday_list']: international_standards = self.search([("name", '=', item['name'])]) if international_standards: international_standards.name = item['name'] international_standards.active = item['active'] else: self.create({ "name": item['name'], "active": item['active'], }) else: raise ValidationError("制造标准认证未通过") # 同步所有制造标准 def sync_all_mrs_international_standards(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_international_standards_all_list']: international_standards = self.search([("name", '=', item['name'])]) if not international_standards: self.create({ "name": item['name'], "active": item['active'], }) else: international_standards.name = item['name'] international_standards.active = item['active'] else: raise ValidationError("制造标准认证未通过") class Cutting_tool_standard_library(models.Model): _inherit = 'sf.cutting_tool.standard.library' _description = '刀具标准库' url = '/api/cutting_tool_standard_library/list' # 定时同步刀具标准库 def sync_cutting_tool_standard_library_yesterday(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['cutting_tool_standard_library_yesterday_list']: cutting_tool_standard_library = self.search( [("code", '=', item['code'])]) if cutting_tool_standard_library: cutting_tool_standard_library.write( {"name": item['name'], "active": item['active']} ) else: self.create({ "name": item['name'], "active": item['active'], }) else: raise ValidationError("刀具标准库认证未通过") # 同步所有刀具标准库 def sync_all_cutting_tool_standard_library(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['cutting_tool_standard_library_all_list']: cutting_tool_standard_library = self.search( [("code", '=', item['code'].replace("JKM", result['factory_short_name']))]) cutting_tool_type = self.env['sf.cutting.tool.type'].search( [("code", '=', item['cutting_tool_type_code'])]) cutting_tool_material = self.env['sf.cutting.tool.material'].search( [("code", '=', item['cutting_tool_material_code'])]) materials_model = self.env['sf.materials.model'].search( [("materials_no", '=', item['material_model_code'])]) brand = self.env['sf.machine.brand'].search([("code", '=', item['brand_code'])]) basic_param_list = [] for basic_param_item in item['basic_parameter']: basic_param_list.append( self.env['sf.tool.materials.basic.parameters']._json_basic_param(basic_param_item)) cutting_speed_list = [] for cutting_speed_item in item['cutting_speed']: cutting_speed_list.append( self.env['sf.cutting.speed']._json_cutting_speed(cutting_speed_item)) feed_per_tooth_list = [] for feed_per_tooth_item in item['basic_parameter']: feed_per_tooth_list.append( self.env['sf.feed.per.tooth']._json_feed_per_tooth(feed_per_tooth_item)) if not cutting_tool_standard_library: self.create({ "code": item['code'].replace("JKM", result['factory_short_name']), "name": item['name'], "cutting_tool_material_id": cutting_tool_material.id, "cutting_tool_type_id": cutting_tool_type.id, "brand_id": brand.id, "material_model_id": materials_model.id, "tool_hardness": item['tool_hardness'], "coating_material": item['coating_material'], "blade_type": item['blade_type'], "blade_diameter": item['blade_diameter'], "working_hardness": item['working_hardness'], "integral_coarse_medium_fine": item['integral_coarse_medium_fine'], "integral_run_out_accuracy_max": item['integral_run_out_accuracy_max'], "integral_run_out_accuracy_min": item['integral_run_out_accuracy_min'], "basic_parameters_ids": basic_param_list, "cutting_speed_ids": cutting_speed_list, "feed_per_tooth_ids": feed_per_tooth_list, "active": item['active'], }) else: cutting_tool_standard_library.write( {"name": item['name'], "cutting_tool_material_id": cutting_tool_material.id, "cutting_tool_type_id": cutting_tool_type.id, "brand_id": brand.id, "material_model_id": materials_model.id, "tool_hardness": item['tool_hardness'], "coating_material": item['coating_material'], "blade_type": item['blade_type'], "blade_diameter": item['blade_diameter'], "working_hardness": item['working_hardness'], "integral_coarse_medium_fine": item['integral_coarse_medium_fine'], "integral_run_out_accuracy_max": item['integral_run_out_accuracy_max'], "integral_run_out_accuracy_min": item['integral_run_out_accuracy_min'], "basic_parameters_ids": basic_param_list, "cutting_speed_ids": cutting_speed_list, "feed_per_tooth_ids": feed_per_tooth_list, "active": item['active'], } ) else: raise ValidationError("刀具标准库认证未通过")