Files
test/sf_mrs_connect/models/sync_common.py

1875 lines
98 KiB
Python

# -*- 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:
materials = self.env['sf.production.materials'].search(
[("materials_no", '=', item['materials_no'])])
if materials:
materials.name = item['name']
materials.remark = item['remark']
materials.active = item['active']
else:
self.env['sf.production.materials'].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.env['sf.production.materials'].search(
[("materials_no", '=', item['materials_no'])])
if not materials:
self.env['sf.production.materials'].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(self):
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
strUrl = sf_sync_config['sf_url'] + self.url
r = requests.post(strUrl, json={}, data=None, headers=headers)
r = r.json()
result = json.loads(r['result'])
if result['status'] == 1:
for item in result['materials_model_yesterday_list']:
if item:
materials_model = self.env['sf.materials.model'].search(
[("materials_no", '=', item['materials_no'])])
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.env['sf.materials.model'].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.env['sf.materials.model'].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.env['sf.materials.model'].create({
"name": item['name'],
"materials_no": item['materials_no'],
"remark": item['remark'],
"active": item['active'],
"tensile_strength": item['tensile_strength'],
"hardness": item['hardness'],
"rough_machining": item['rough_machining'],
"finish_machining": item['finish_machining'],
"materials_id": materials.id,
"need_h": item['need_h'],
"mf_materia_post": item['mf_materia_post'],
"density": item['density'],
})
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(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:
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(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:
production_process = self.env['sf.production.process'].search(
[("process_encode", '=', 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.env['sf.production.process'].create({
"name": item['name'],
"category_id": category.id,
"process_encode": 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.env['sf.production.process'].search(
[("process_encode", '=', item['code'])])
category = self.env['sf.production.process.category'].search(
[("code", '=', item['category_code'])])
if not production_process:
self.env['sf.production.process'].create({
"name": item['name'],
"category_id": category.id,
"process_encode": item['process_encode'],
"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(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.env['sf.processing.technology'].search(
[("process_encode", '=', item['process_encode'])])
if processing_technology:
processing_technology.name = item['name']
processing_technology.remark = item['remark']
processing_technology.active = item['active']
else:
self.env['sf.processing.technology'].create({
"name": item['name'],
"process_encode": item['process_encode'],
"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.env['sf.processing.technology'].search(
[("process_encode", '=', item['process_encode'])])
if not processing_technology:
self.env['sf.processing.technology'].create({
"name": item['name'],
"process_encode": item['process_encode'],
"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(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.env['sf.machine.brand.tags'].search(
[("id", '=', item['id'])])
if brand_tags:
brand_tags.name = item['name']
brand_tags.color = item['color']
else:
self.env['sf.machine.brand.tags'].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.env['sf.machine.brand.tags'].search(
[("name", '=', item['name'])])
if not brand_tags:
self.env['sf.machine.brand.tags'].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_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:
control_system = self.env['sf.machine.control_system'].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.env['sf.machine.control_system'].create({
"remark": item['remark'],
"name": item['name'],
"code": item['code'],
'brand_id': brand.id,
"active": item['active'],
})
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:
control_system = self.env['sf.machine.control_system'].search(
[("code", '=', item['code'])])
brand = self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])])
if not control_system:
self.env['sf.machine.control_system'].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(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.name = item['name']
brand.image_brand = '' if not item['image_brand'] else base64.b64encode(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.env['sf.machine.brand'].create({
"name": item['name'],
"code": item['code'],
"image_brand": '' if not item['image_brand'] else base64.b64encode(item.image_brand),
"active": item['active'],
"remark": item['remark'],
"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.env['sf.machine.brand'].search(
[("code", '=', item['code'])])
if not brand:
if item.get('image_brand'):
image = base64.b64decode(item['image_brand'])
else:
image = ''
self.env['sf.machine.brand'].create({
"name": item['name'],
"code": item['code'],
"remark": item['remark'],
"image_brand": image,
"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.b64encode(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(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.env['sf.machine_tool.type'].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.env['sf.machine_tool.type'].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.env['sf.machine_tool.type'].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.env['sf.machine_tool.type'].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(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.env['sf.processing.order'].search(
[("id", '=', item['id'])])
if processing_order:
processing_order.sequence = item['sequence']
else:
self.env['sf.processing.order'].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.env['sf.processing.order'].search(
[("id", '=', item['id'])])
if not processing_order:
self.env['sf.processing.order'].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(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.env['sf.production.process.parameter'].search(
[("code", '=', item['code'])])
process = self.env['sf.production.process'].search(
[('process_encode', '=', 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.env['sf.production.process.parameter'].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:
_logger.info('result:%s' % result)
for item in result['mrs_production_process_parameter_all_list']:
if item:
_logger.info('create可选参数:%s' % item)
production_process_parameter = self.env['sf.production.process.parameter'].search(
[("code", '=', item['code'])])
process = self.env['sf.production.process'].search(
[('process_encode', '=', item['process_id_code'])])
if not production_process_parameter:
_logger.info('create可选参数:%s' % item)
self.env['sf.production.process.parameter'].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(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.env['sf.machine_tool.category'].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.env['sf.machine_tool.category'].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.env['sf.machine_tool.category'].search(
[("code", '=', item['code'])])
if not machine_tool_category:
self.env['sf.machine_tool.category'].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(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.env['sf.cutting.tool.material'].search(
[("code", '=', item['code'])])
if not cutting_tool_material:
self.env['sf.cutting.tool.material'].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.env['sf.cutting.tool.material'].search(
[("code", '=', item['code'])])
if not cutting_tool_material:
self.env['sf.cutting.tool.material'].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(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.env['sf.functional.cutting.tool.model'].search(
[("code", '=', item['code'])])
if not functional_cutting_tool_model:
self.env['sf.functional.cutting.tool.model'].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.env['sf.functional.cutting.tool.model'].search(
[("code", '=', item['code'])])
if not functional_cutting_tool_model:
self.env['sf.functional.cutting.tool.model'].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(self):
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
strUrl = sf_sync_config['sf_url'] + self.url
r = requests.post(strUrl, json={}, data=None, headers=headers)
r = r.json()
result = json.loads(r['result'])
# print('result:%s' % result)
if result['status'] == 1:
if result.get('fixture_material_yesterday_list'):
for item in result['fixture_material_yesterday_list']:
if item:
fixture_material = self.env['sf.fixture.material'].search(
[("code", '=', item['code'])])
if not fixture_material:
self.env['sf.fixture.material'].create({
"name": item['name'],
"code": item['code'],
"category": item['category'],
"remark": item['remark'],
"active": item['active'],
})
else:
fixture_material.write({
"name": item['name'],
"category": item['category'],
"remark": item['remark'],
"active": item['active'],
})
else:
raise ValidationError("夹具物料认证未通过")
# 定时同步所有夹具物料列表
def sync_all_fixture_material(self):
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
strUrl = sf_sync_config['sf_url'] + self.url
r = requests.post(strUrl, json={}, data=None, headers=headers)
r = r.json()
result = json.loads(r['result'])
# print('result:%s' % result)
if result['status'] == 1:
if result.get('fixture_material_all_list'):
for item in result['fixture_material_all_list']:
if item:
fixture_material = self.env['sf.fixture.material'].search(
[("code", '=', item['code'])])
if not fixture_material:
self.env['sf.fixture.material'].create({
"name": item['name'],
"code": item['code'],
"category": item['category'],
"remark": item['remark'],
"active": item['active'],
})
else:
fixture_material.write({
"name": item['name'],
"category": item['category'],
"remark": item['remark'],
"active": item['active'],
})
else:
raise ValidationError("夹具物料认证未通过")
class SyncMulti_Mounting_Type(models.Model):
_inherit = 'sf.multi_mounting.type'
_description = '同步联装类型列表'
url = '/api/multi_mounting_type/list'
# 定时同步联装类型列表
def sync_multi_mounting_type(self):
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
strUrl = sf_sync_config['sf_url'] + self.url
r = requests.post(strUrl, json={}, data=None, headers=headers)
r = r.json()
result = json.loads(r['result'])
if result['status'] == 1:
if result.get('multi_mounting_type_yesterday_list'):
for item in result['multi_mounting_type_yesterday_list']:
if item:
multi_mounting_type = self.env['sf.multi_mounting.type'].search(
[("code", '=', item['code'])])
if not multi_mounting_type:
self.env['sf.multi_mounting.type'].create({
"name": item['name'],
"code": item['code'],
"remark": item['remark'],
"active": item['active'],
})
else:
multi_mounting_type.write({
"name": item['name'],
"remark": item['remark'],
"active": item['active'],
})
else:
raise ValidationError("联装类型认证未通过")
# 定时同步所有联装类型列表
def sync_all_multi_mounting_type(self):
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
strUrl = sf_sync_config['sf_url'] + self.url
r = requests.post(strUrl, json={}, data=None, headers=headers)
r = r.json()
result = json.loads(r['result'])
# print('result:%s' % result)
if result['status'] == 1:
if result.get('multi_mounting_type_all_list'):
for item in result['multi_mounting_type_all_list']:
if item:
multi_mounting_type = self.env['sf.multi_mounting.type'].search(
[("code", '=', item['code'])])
if not multi_mounting_type:
self.env['sf.multi_mounting.type'].create({
"name": item['name'],
"code": item['code'],
"remark": item['remark'],
"active": item['active'],
})
else:
multi_mounting_type.write({
"name": item['name'],
"remark": item['remark'],
"active": item['active'],
})
else:
raise ValidationError("联装类型认证未通过")
class SyncFixtureModel(models.Model):
_inherit = 'sf.fixture.model'
_description = '同步夹具型号列表'
url = '/api/fixture_model/list'
# 定时同步夹具型号列表
def sync_fixture_model(self):
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
strUrl = sf_sync_config['sf_url'] + self.url
r = requests.post(strUrl, json={}, data=None, headers=headers)
r = r.json()
result = json.loads(r['result'])
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_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.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_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(self):
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
strUrl = sf_sync_config['sf_url'] + self.url
r = requests.post(strUrl, json={}, data=None, headers=headers)
r = r.json()
result = json.loads(r['result'])
# print('result:%s' % result)
if result['status'] == 1:
if result.get('functional_fixture_type_yesterday_list'):
for item in result['functional_fixture_type_yesterday_list']:
if item:
functional_fixture_type = self.env['sf.functional.fixture.type'].search(
[("code", '=', item['code'])])
if not functional_fixture_type:
self.env['sf.functional.fixture.type'].create({
"name": item['name'],
"code": item['code'],
"remark": item['remark'],
"active": item['active'],
})
else:
functional_fixture_type.write({
"name": item['name'],
"remark": item['remark'],
"active": item['active'],
})
else:
raise ValidationError("功能夹具类型认证未通过")
# 定时同步所有功能夹具类型列表
def sync_all_functional_fixture_type(self):
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
strUrl = sf_sync_config['sf_url'] + self.url
r = requests.post(strUrl, json={}, data=None, headers=headers)
r = r.json()
result = json.loads(r['result'])
if result['status'] == 1:
if result.get('functional_fixture_type_all_list'):
for item in result['functional_fixture_type_all_list']:
if item:
functional_fixture_type = self.env['sf.functional.fixture.type'].search(
[("code", '=', item['code'])])
if not functional_fixture_type:
self.env['sf.functional.fixture.type'].create({
"name": item['name'],
"code": item['code'],
"remark": item['remark'],
"active": item['active'],
})
else:
functional_fixture_type.write({
"name": item['name'],
"remark": item['remark'],
"active": item['active'],
})
else:
raise ValidationError("功能夹具类型认证未通过")
# 同步刀具类型
class SfToolType(models.Model):
_inherit = 'sf.cutting.tool.type'
_description = '同步刀具类型'
url = '/api/mrs_cutting_tool_type/list'
# 定时同步每日刀具类型
def sync_tool_type(self):
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
strUrl = sf_sync_config['sf_url'] + self.url
r = requests.post(strUrl, json={}, data=None, headers=headers)
r = r.json()
result = json.loads(r['result'])
if result['status'] == 1:
_logger.info('result:%s' % result)
for item in result['mrs_cutting_tool_type_yesterday_list']:
if item:
cutting_tool_type = self.env['sf.cutting.tool.type'].search(
[("code", '=', item['code'])])
if not cutting_tool_type:
self.env['sf.cutting.tool.type'].create({
"name": item['name'],
"code": item['code'],
"cutting_tool_material_id": self.env['sf.cutting.tool.material'].search(
[("code", '=', item['cutting_tool_material_code'])]).id,
"remark": item['remark'],
"active": item['active'],
})
else:
cutting_tool_type.write({
"name": item['name'],
"cutting_tool_material_id": self.env['sf.cutting.tool.material'].search(
[("code", '=', item['cutting_tool_material_code'])]).id,
"remark": item['remark'],
"active": item['active'],
})
else:
raise ValidationError("刀具类型认证未通过")
# 同步所有刀具类型列表
def sync_all_tool_type(self):
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
strUrl = sf_sync_config['sf_url'] + self.url
r = requests.post(strUrl, json={}, data=None, headers=headers)
r = r.json()
result = json.loads(r['result'])
if result['status'] == 1:
_logger.info('result:%s' % result)
for item in result['mrs_cutting_tool_type_all_list']:
if item:
cutting_tool_type = self.env['sf.cutting.tool.type'].search(
[("code", '=', item['code'])])
if not cutting_tool_type:
self.env['sf.cutting.tool.type'].create({
"name": item['name'],
"code": item['code'],
"cutting_tool_material_id": self.env['sf.cutting.tool.material'].search(
[("code", '=', item['cutting_tool_material_code'])]).id,
"remark": item['remark'],
"active": item['active'],
})
else:
cutting_tool_type.write({
"name": item['name'],
"cutting_tool_material_id": self.env['sf.cutting.tool.material'].search(
[("code", '=', item['cutting_tool_material_code'])]).id,
"remark": item['remark'],
"active": item['active'],
})
else:
raise ValidationError("刀具类型认证未通过")
# 同步刀具型号
class SfToolModel(models.Model):
_inherit = 'sf.cutting.tool.model'
_description = '同步刀具型号'
url = '/api/mrs_cutting_tool_model/list'
# 定时同步每日刀具型号
def sync_tool_model(self):
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
strUrl = sf_sync_config['sf_url'] + self.url
r = requests.post(strUrl, json={}, data=None, headers=headers)
r = r.json()
result = json.loads(r['result'])
if result['status'] == 1:
_logger.info('result:%s' % result)
for item in result['mrs_cutting_tool_model_yesterday_list']:
cutting_tool_model = self.search(
[("code", '=', item['code'])])
if not cutting_tool_model:
self.env['sf.cutting.tool.model'].create({
"name": item['name'],
"code": item['code'],
"brand_id": self.env['sf.machine.brand'].search(
[("code", '=', item['brand_code'])]).id,
"material_model_id": self.env['sf.materials.model'].search(
[("materials_no", '=', item['material_model_code'])]).id,
"cutting_tool_material_id": self.env['sf.cutting.tool.material'].search(
[("code", '=', item['cutting_tool_material_code'])]).id,
"cutting_tool_type_id": self.env['sf.cutting.tool.type'].search(
[("code", '=', item['cutting_tool_type_code'])]).id,
"tool_length": item['tool_length'],
"tool_width": item['tool_width'],
"tool_height": item['tool_height'],
"tool_thickness": item['tool_thickness'],
"tool_weight": item['tool_weight'],
"coating_material": item['coating_material'],
"total_length": item['total_length'],
"shank_length": item['shank_length'],
"blade_length": item['blade_length'],
"front_angle": item['front_angle'],
"rear_angle": item['rear_angle'],
"main_included_angle": item['main_included_angle'],
"nut": item['nut'],
"top_angle": item['top_angle'],
"jump_accuracy": item['jump_accuracy'],
"working_hardness": item['working_hardness'],
"blade_diameter": item['blade_diameter'],
"wrench": item['wrench'],
"screw": item['screw'],
"accuracy_level": item['accuracy_level'],
"diameter_max": item['diameter_max'],
"clamping_diameter": item['clamping_diameter'],
"flange_length": item['flange_length'],
'chuck_ids': [(6, 0, [])] if not item.get('chuck_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['chuck_codes']),
'cutter_bar_ids': [(6, 0, [])] if not item.get('cutter_bar_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['cutter_bar_codes']),
'cutter_pad_ids': [(6, 0, [])] if not item.get('cutter_pad_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['cutter_pad_codes']),
'blade_ids': [(6, 0, [])] if not item.get('blade_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['blade_codes']),
'handle_ids': [(6, 0, [])] if not item.get('handle_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['handle_codes']),
"flange_diameter": item['flange_diameter'],
"outer_diameter": item['outer_diameter'],
"inner_diameter": item['inner_diameter'],
"active": item['active'],
})
else:
cutting_tool_model.write({
"name": item['name'],
"brand_id": self.env['sf.machine.brand'].search(
[("code", '=', item['brand_code'])]).id,
"material_model_id": self.env['sf.materials.model'].search(
[("materials_no", '=', item['material_model_code'])]).id,
"cutting_tool_material_id": self.env['sf.cutting.tool.material'].search(
[("code", '=', item['cutting_tool_material_code'])]).id,
"cutting_tool_type_id": self.env['sf.cutting.tool.type'].search(
[("code", '=', item['cutting_tool_type_code'])]).id,
"tool_length": item['tool_length'],
"tool_width": item['tool_width'],
"tool_height": item['tool_height'],
"tool_thickness": item['tool_thickness'],
"tool_weight": item['tool_weight'],
"coating_material": item['coating_material'],
"total_length": item['total_length'],
"shank_length": item['shank_length'],
"blade_length": item['blade_length'],
"front_angle": item['front_angle'],
"rear_angle": item['rear_angle'],
"main_included_angle": item['main_included_angle'],
"nut": item['nut'],
"top_angle": item['top_angle'],
"jump_accuracy": item['jump_accuracy'],
"working_hardness": item['working_hardness'],
"blade_diameter": item['blade_diameter'],
"wrench": item['wrench'],
"screw": item['screw'],
"accuracy_level": item['accuracy_level'],
"diameter_max": item['diameter_max'],
"clamping_diameter": item['clamping_diameter'],
"flange_length": item['flange_length'],
'chuck_ids': [(6, 0, [])] if not item.get('chuck_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['chuck_codes']),
'cutter_bar_ids': [(6, 0, [])] if not item.get('cutter_bar_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['cutter_bar_codes']),
'cutter_pad_ids': [(6, 0, [])] if not item.get('cutter_pad_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['cutter_pad_codes']),
'blade_ids': [(6, 0, [])] if not item.get('blade_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['blade_codes']),
'handle_ids': [(6, 0, [])] if not item.get('handle_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['handle_codes']),
"flange_diameter": item['flange_diameter'],
"outer_diameter": item['outer_diameter'],
"inner_diameter": item['inner_diameter'],
"active": item['active'],
})
else:
raise ValidationError("刀具型号认证未通过")
# 同步所有刀具型号列表
def sync_all_tool_model(self):
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
strUrl = sf_sync_config['sf_url'] + self.url
r = requests.post(strUrl, json={}, data=None, headers=headers)
r = r.json()
result = json.loads(r['result'])
print('result', result)
if result['status'] == 1:
_logger.info('result:%s' % result)
for item in result['mrs_cutting_tool_model_all_list']:
cutting_tool_model = self.search(
[("code", '=', item['code'])])
if not cutting_tool_model:
self.env['sf.cutting.tool.model'].create({
"name": item['name'],
"code": item['code'],
"brand_id": self.env['sf.machine.brand'].search(
[("code", '=', item['brand_code'])]).id,
"material_model_id": self.env['sf.materials.model'].search(
[("materials_no", '=', item['material_model_code'])]).id,
"cutting_tool_material_id": self.env['sf.cutting.tool.material'].search(
[("code", '=', item['cutting_tool_material_code'])]).id,
"cutting_tool_type_id": self.env['sf.cutting.tool.type'].search(
[("code", '=', item['cutting_tool_type_code'])]).id,
"tool_length": item['tool_length'],
"tool_width": item['tool_width'],
"tool_height": item['tool_height'],
"tool_thickness": item['tool_thickness'],
"tool_weight": item['tool_weight'],
"coating_material": item['coating_material'],
"total_length": item['total_length'],
"shank_length": item['shank_length'],
"blade_length": item['blade_length'],
"front_angle": item['front_angle'],
"rear_angle": item['rear_angle'],
"main_included_angle": item['main_included_angle'],
"nut": item['nut'],
"top_angle": item['top_angle'],
"jump_accuracy": item['jump_accuracy'],
"working_hardness": item['working_hardness'],
"blade_diameter": item['blade_diameter'],
"wrench": item['wrench'],
"screw": item['screw'],
"accuracy_level": item['accuracy_level'],
"diameter_max": item['diameter_max'],
"clamping_diameter": item['clamping_diameter'],
"flange_length": item['flange_length'],
'chuck_ids': [(6, 0, [])] if not item.get('chuck_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['chuck_codes']),
'cutter_bar_ids': [(6, 0, [])] if not item.get('cutter_bar_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['cutter_bar_codes']),
'cutter_pad_ids': [(6, 0, [])] if not item.get('cutter_pad_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['cutter_pad_codes']),
'blade_ids': [(6, 0, [])] if not item.get('blade_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['blade_codes']),
'handle_ids': [(6, 0, [])] if not item.get('handle_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['handle_codes']),
"flange_diameter": item['flange_diameter'],
"outer_diameter": item['outer_diameter'],
"inner_diameter": item['inner_diameter'],
"active": item['active'],
})
else:
cutting_tool_model.write({
"name": item['name'],
"brand_id": self.env['sf.machine.brand'].search(
[("code", '=', item['brand_code'])]).id,
"material_model_id": self.env['sf.materials.model'].search(
[("materials_no", '=', item['material_model_code'])]).id,
"cutting_tool_material_id": self.env['sf.cutting.tool.material'].search(
[("code", '=', item['cutting_tool_material_code'])]).id,
"cutting_tool_type_id": self.env['sf.cutting.tool.type'].search(
[("code", '=', item['cutting_tool_type_code'])]).id,
"tool_length": item['tool_length'],
"tool_width": item['tool_width'],
"tool_height": item['tool_height'],
"tool_thickness": item['tool_thickness'],
"tool_weight": item['tool_weight'],
"coating_material": item['coating_material'],
"total_length": item['total_length'],
"shank_length": item['shank_length'],
"blade_length": item['blade_length'],
"front_angle": item['front_angle'],
"rear_angle": item['rear_angle'],
"main_included_angle": item['main_included_angle'],
"nut": item['nut'],
"top_angle": item['top_angle'],
"jump_accuracy": item['jump_accuracy'],
"working_hardness": item['working_hardness'],
"blade_diameter": item['blade_diameter'],
"wrench": item['wrench'],
"screw": item['screw'],
"accuracy_level": item['accuracy_level'],
"diameter_max": item['diameter_max'],
"clamping_diameter": item['clamping_diameter'],
"flange_length": item['flange_length'],
'chuck_ids': [(6, 0, [])] if not item.get('chuck_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['chuck_codes']),
'cutter_bar_ids': [(6, 0, [])] if not item.get('cutter_bar_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['cutter_bar_codes']),
'cutter_pad_ids': [(6, 0, [])] if not item.get('cutter_pad_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['cutter_pad_codes']),
'blade_ids': [(6, 0, [])] if not item.get('blade_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['blade_codes']),
'handle_ids': [(6, 0, [])] if not item.get('handle_codes') else
self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids(
item['handle_codes']),
"flange_diameter": item['flange_diameter'],
"outer_diameter": item['outer_diameter'],
"inner_diameter": item['inner_diameter'],
"active": item['active'],
})
else:
raise ValidationError("刀具型号认证未通过")