490 lines
19 KiB
Python
490 lines
19 KiB
Python
# -*- coding: utf-8 -*-
|
|
import logging
|
|
import math
|
|
import requests
|
|
from dateutil.relativedelta import relativedelta
|
|
from datetime import timedelta, datetime
|
|
import requests
|
|
import json
|
|
import time
|
|
import hashlib
|
|
import datetime
|
|
from odoo import models, fields, api
|
|
from odoo.exceptions import ValidationError
|
|
import logging
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
MRS = 'https://mrs.cs.jikimo.com'
|
|
# MRS = 'http://192.168.50.100:6069'
|
|
# 服务器
|
|
TOKEN = '0b231a4c-3f01-11ed-a1cb-0242ac110003'
|
|
# 本地
|
|
# TOKEN = '4130d97c-37be-11ed-84a7-f8b54df29535'
|
|
|
|
# TOKEN = '999e2cff-3e44-11ed-92e2-f8b54d90e788'
|
|
# 服务器
|
|
mrs_secret_key = 'WNHeIopD4XJy6TLK'
|
|
# 本地
|
|
# mrs_secret_key = 'BCDkXbaISz4Vg08y'
|
|
|
|
|
|
# TIMESTAMP = str(int(time.time()))
|
|
# check_str = '9524cba0-3e39-11ed-84ab-0242ac110003'+TIMESTAMP+'NIl6j3knJdhvUWKy'
|
|
# check_mrs_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest()
|
|
# HEADERS = {'TOKEN': '9524cba0-3e39-11ed-84ab-0242ac110003',
|
|
# 'TIMESTAMP': "",
|
|
# 'check_str': check_mrs_str}
|
|
|
|
|
|
class MrsProductionMaterials(models.Model):
|
|
_inherit = "mrs.production.materials"
|
|
_description = "材料"
|
|
url = '/api/production_materials/list'
|
|
|
|
# 定时同步材料
|
|
def sync_production_materials(self):
|
|
timestamp = int(time.time())
|
|
check_str = '%s%s%s' % (TOKEN, timestamp, mrs_secret_key)
|
|
check_mrs_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest()
|
|
headers = {'TOKEN': TOKEN,
|
|
'TIMESTAMP': str(timestamp),
|
|
'check_str': check_mrs_str}
|
|
|
|
print(headers)
|
|
|
|
r = requests.post((MRS + self.url), json={}, data=None, headers=headers)
|
|
r = r.json()
|
|
result = json.loads(r['result'])
|
|
if result['status'] == 1:
|
|
for item in result['production_materials_all_list']:
|
|
if item:
|
|
brand = self.env['mrs.production.materials'].search(
|
|
[("materials_no", '=', item['materials_no'])])
|
|
if brand:
|
|
print(item['name'])
|
|
else:
|
|
self.env['mrs.production.materials'].create({
|
|
"id": item['id'],
|
|
"name": item['name'],
|
|
"materials_no": item['materials_no'],
|
|
"remark": item['remark'],
|
|
"active": item['active']
|
|
|
|
})
|
|
else:
|
|
raise ValidationError("访问失败")
|
|
|
|
|
|
class MrsMaterialModel(models.Model):
|
|
_inherit = 'mrs.materials.model'
|
|
_description = '材料型号'
|
|
url = '/api/materials_model/list'
|
|
|
|
# 定时同步材料型号
|
|
def sync_materials_model(self):
|
|
timestamp = str(int(time.time()))
|
|
check_str = TOKEN + timestamp + mrs_secret_key
|
|
check_mrs_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest()
|
|
headers = {'TOKEN': TOKEN,
|
|
'TIMESTAMP': timestamp,
|
|
'check_str': check_mrs_str}
|
|
|
|
print(headers)
|
|
strUrl = MRS + self.url
|
|
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
|
r = r.json()
|
|
result = json.loads(r['result'])
|
|
if result['status'] == 1:
|
|
for item in result['materials_model_all_list']:
|
|
if item:
|
|
brand = self.env['mrs.materials.model'].search(
|
|
[("materials_num", '=', item['materials_num'])])
|
|
if brand:
|
|
print(item['name'])
|
|
else:
|
|
self.env['mrs.materials.model'].create({
|
|
"id": item['id'],
|
|
"name": item['name'],
|
|
"materials_num": item['materials_num'],
|
|
"remark": item['remark'],
|
|
"active": item['active'],
|
|
"materials_id": item['materials_id'],
|
|
"need_h": item['need_h'],
|
|
"mf_materia_post": item['mf_materia_post'],
|
|
"density": item['density'],
|
|
# "tag_ids": item['tag_ids']
|
|
|
|
})
|
|
else:
|
|
raise ValidationError("访问失败")
|
|
|
|
|
|
class MrsProductionProcess(models.Model):
|
|
_inherit = 'mrs.production.process'
|
|
_description = '表面工艺'
|
|
url = '/api/production_process/list'
|
|
|
|
# 定时同步表面工艺
|
|
def sync_production_process(self):
|
|
timestamp = str(int(time.time()))
|
|
check_str = TOKEN + timestamp + mrs_secret_key
|
|
check_mrs_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest()
|
|
headers = {'TOKEN': TOKEN,
|
|
'TIMESTAMP': timestamp,
|
|
'check_str': check_mrs_str}
|
|
|
|
strUrl = MRS + self.url
|
|
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
|
r = r.json()
|
|
result = json.loads(r['result'])
|
|
if result['status'] == 1:
|
|
for item in result['production_process_all_list']:
|
|
if item:
|
|
brand = self.env['mrs.production.process'].search(
|
|
[("process_encode", '=', item['process_encode'])])
|
|
if brand:
|
|
print(item['name'])
|
|
else:
|
|
self.env['mrs.production.process'].create({
|
|
"id": item['id'],
|
|
"name": item['name'],
|
|
"process_encode": item['process_encode'],
|
|
"remark": item['remark'],
|
|
"active": item['active'],
|
|
# "tag_ids": item['tag_ids']
|
|
|
|
})
|
|
else:
|
|
raise ValidationError("访问失败")
|
|
|
|
|
|
class MrsProcessingTechnology(models.Model):
|
|
_inherit = 'mrs.processing.technology'
|
|
_description = '加工工艺'
|
|
url = '/api/processing_technology/list'
|
|
|
|
# 定时同步加工工艺
|
|
def sync_processing_technology(self):
|
|
timestamp = str(int(time.time()))
|
|
check_str = TOKEN + timestamp + mrs_secret_key
|
|
check_mrs_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest()
|
|
headers = {'TOKEN': TOKEN,
|
|
'TIMESTAMP': timestamp,
|
|
'check_str': check_mrs_str}
|
|
strUrl = MRS + self.url
|
|
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
|
r = r.json()
|
|
result = json.loads(r['result'])
|
|
if result['status'] == 1:
|
|
for item in result['processing_technology_all_list']:
|
|
if item:
|
|
brand = self.env['mrs.processing.technology'].search(
|
|
[("process_encode", '=', item['process_encode'])])
|
|
if brand:
|
|
print(item['name'])
|
|
else:
|
|
self.env['mrs.processing.technology'].create({
|
|
"id": item['id'],
|
|
"name": item['name'],
|
|
"process_encode": item['process_encode'],
|
|
"remark": item['remark'],
|
|
"active": item['active'],
|
|
# "tag_ids": item['tag_ids']
|
|
|
|
})
|
|
else:
|
|
raise ValidationError("访问失败")
|
|
|
|
|
|
class MachineBrandTags(models.Model):
|
|
_inherit = 'mrs.machine.brand.tags'
|
|
_description = '品牌类别'
|
|
url = '/api/machine_brand_tags/list'
|
|
|
|
# 定时同步品牌类别
|
|
def sync_machine_brand_tags(self):
|
|
timestamp = str(int(time.time()))
|
|
check_str = TOKEN + timestamp + mrs_secret_key
|
|
check_mrs_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest()
|
|
headers = {'TOKEN': TOKEN,
|
|
'TIMESTAMP': timestamp,
|
|
'check_str': check_mrs_str}
|
|
strUrl = MRS + self.url
|
|
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
|
r = r.json()
|
|
result = json.loads(r['result'])
|
|
if result['status'] == 1:
|
|
for item in result['machine_brand_tags_all_list']:
|
|
brand = self.env['mrs.machine.brand.tags'].search(
|
|
[("id", '=', item['id'])])
|
|
if brand:
|
|
print(item['name'])
|
|
else:
|
|
self.env['mrs.machine.brand.tags'].create({
|
|
"id": item['id'],
|
|
"name": item['name'],
|
|
"color": item['color'],
|
|
|
|
})
|
|
else:
|
|
raise ValidationError("访问失败")
|
|
|
|
|
|
class MachineControlSystem(models.Model):
|
|
_inherit = 'mrs.machine_tool.type.control_system'
|
|
_description = '控制系统'
|
|
url = '/api/machine_control_system/list'
|
|
|
|
# 定时同步控制系统
|
|
def sync_machine_tool_type_control_system(self):
|
|
timestamp = str(int(time.time()))
|
|
check_str = TOKEN + timestamp + mrs_secret_key
|
|
check_mrs_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest()
|
|
headers = {'TOKEN': TOKEN,
|
|
'TIMESTAMP': timestamp,
|
|
'check_str': check_mrs_str}
|
|
strUrl = MRS + self.url
|
|
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
|
r = r.json()
|
|
result = json.loads(r['result'])
|
|
if result['status'] == 1:
|
|
for item in result['machine_control_system_all_list']:
|
|
if item:
|
|
brand = self.env['mrs.machine_tool.type.control_system'].search(
|
|
[("code", '=', item['code'])])
|
|
if brand:
|
|
print(item['name'])
|
|
else:
|
|
self.env['mrs.machine_tool.type.control_system'].create({
|
|
"id": item['id'],
|
|
"name": item['name'],
|
|
"code": item['code'],
|
|
|
|
# "brand_id": item['brand_id'],
|
|
"active": item['active'],
|
|
# "tag_ids": item['tag_ids']
|
|
|
|
})
|
|
else:
|
|
raise ValidationError("访问失败")
|
|
|
|
|
|
class MachineBrand(models.Model):
|
|
_inherit = 'mrs.machine.brand'
|
|
_description = '品牌'
|
|
url = '/api/machine_brand/list'
|
|
|
|
# 定时同步品牌
|
|
def sync_machine_brand(self):
|
|
timestamp = str(int(time.time()))
|
|
check_str = TOKEN + timestamp + mrs_secret_key
|
|
check_mrs_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest()
|
|
headers = {'TOKEN': TOKEN,
|
|
'TIMESTAMP': timestamp,
|
|
'check_str': check_mrs_str}
|
|
strUrl = MRS + self.url
|
|
print("打印headers密钥"+check_mrs_str )
|
|
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['mrs.machine.brand'].search(
|
|
[("code", '=', item['code'])])
|
|
if brand:
|
|
print(item['name'])
|
|
else:
|
|
self.env['mrs.machine.brand'].create({
|
|
"id": item['id'],
|
|
"name": item['name'],
|
|
"code": item['code'],
|
|
# "image_brand": item['image_brand'],
|
|
"active": item['active'],
|
|
# "tag_ids": item['tag_ids']
|
|
|
|
})
|
|
else:
|
|
raise ValidationError("访问失败")
|
|
|
|
|
|
class MachineTool(models.Model):
|
|
_inherit = 'mrs.machine_tool'
|
|
_description = '机床'
|
|
url = '/api/machine_tool/list'
|
|
|
|
# 定时同步机床
|
|
def sync_machine_tool(self):
|
|
timestamp = str(int(time.time()))
|
|
check_str = TOKEN + timestamp + mrs_secret_key
|
|
check_mrs_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest()
|
|
headers = {'TOKEN': TOKEN,
|
|
'TIMESTAMP': timestamp,
|
|
'check_str': check_mrs_str}
|
|
strUrl = MRS + self.url
|
|
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
|
r = r.json()
|
|
result = json.loads(r['result'])
|
|
if result['status'] == 1:
|
|
for item in result['machine_tool_all_list']:
|
|
brand = self.env['mrs.machine_tool'].search(
|
|
[("code", '=', item['code'])])
|
|
if brand:
|
|
print(item['name'])
|
|
else:
|
|
self.env['mrs.machine_tool'].create({
|
|
"id": item['id'],
|
|
"name": item['name'],
|
|
"precision": item['precision'],
|
|
"code": item['code'],
|
|
"status": item['status'],
|
|
"knife_type": item['knife_type'],
|
|
"registration_date": item['registration_date'],
|
|
"number_of_knife_library": item['number_of_knife_library'],
|
|
"rotate_speed": item['rotate_speed'],
|
|
"number_of_axles": item['number_of_axles'],
|
|
"control_system_id": item['control_system_id'],
|
|
"type_id": item['type_id'],
|
|
"brand_id": item['brand_id'],
|
|
"x_axis": item['x_axis'],
|
|
"y_axis": item['y_axis'],
|
|
"z_axis": item['z_axis'],
|
|
"b_axis": item['b_axis'],
|
|
"c_axis": item['c_axis'],
|
|
"state": item['state'],
|
|
"active": item['active'],
|
|
# "tag_ids": item['tag_ids']
|
|
|
|
})
|
|
else:
|
|
raise ValidationError("访问失败")
|
|
|
|
|
|
class MachineToolType(models.Model):
|
|
_inherit = 'mrs.machine_tool.type'
|
|
_description = '机床型号'
|
|
url = '/api/machine_tool_type/list'
|
|
|
|
# 定时同步机床型号
|
|
def sync_machine_tool_type(self):
|
|
timestamp = str(int(time.time()))
|
|
check_str = TOKEN + timestamp + mrs_secret_key
|
|
check_mrs_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest()
|
|
headers = {'TOKEN': TOKEN,
|
|
'TIMESTAMP': timestamp,
|
|
'check_str': check_mrs_str}
|
|
strUrl = MRS + self.url
|
|
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
|
r = r.json()
|
|
result = json.loads(r['result'])
|
|
if result['status'] == 1:
|
|
for item in result['machine_tool_type_all_list']:
|
|
brand = self.env['mrs.machine_tool.type'].search(
|
|
[("code", '=', item['code'])])
|
|
if brand:
|
|
print(item['name'])
|
|
else:
|
|
self.env['mrs.machine_tool.type'].create({
|
|
"id": item['id'],
|
|
"name": item['name'],
|
|
"code": item['code'],
|
|
"brand_id": item['brand_id'],
|
|
"number_of_knife_library": item['number_of_knife_library'],
|
|
"rotate_speed": item['rotate_speed'],
|
|
"machine_tool_id": item['machine_tool_id'],
|
|
"number_of_axles": item['number_of_axles'],
|
|
"x_axis": item['x_axis'],
|
|
"y_axis": item['y_axis'],
|
|
"z_axis": item['z_axis'],
|
|
"b_axis": item['b_axis'],
|
|
"c_axis": item['c_axis'],
|
|
"remark": item['remark'],
|
|
"precision": item['precision'],
|
|
"control_system_id": item['control_system_id'],
|
|
"active": item['active']
|
|
|
|
})
|
|
else:
|
|
raise ValidationError("访问失败")
|
|
|
|
|
|
class CuttingTool(models.Model):
|
|
_inherit = 'mrs.cutting_tool.category'
|
|
_description = '刀具类别'
|
|
url = '/api/cutting_tool_category/list'
|
|
|
|
# 定时同步刀具类别
|
|
def sync_cutting_tool_category(self):
|
|
timestamp = str(int(time.time()))
|
|
check_str = TOKEN + timestamp + mrs_secret_key
|
|
check_mrs_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest()
|
|
headers = {'TOKEN': TOKEN,
|
|
'TIMESTAMP': timestamp,
|
|
'check_str': check_mrs_str}
|
|
strUrl = MRS + 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_category_all_list']:
|
|
brand = self.env['mrs.cutting_tool.category'].search(
|
|
[("code", '=', item['code'])])
|
|
if brand:
|
|
print(item['name'])
|
|
else:
|
|
self.env['mrs.cutting_tool.category'].create({
|
|
"id": item['id'],
|
|
"name": item['name'],
|
|
"code": item['code'],
|
|
"remark": item['remark'],
|
|
"active": item['active'],
|
|
# "tag_ids": item['tag_ids']
|
|
|
|
})
|
|
else:
|
|
raise ValidationError("访问失败")
|
|
|
|
|
|
class CuttingToolType(models.Model):
|
|
_inherit = 'mrs.cutting_tool.type'
|
|
_description = '刀具型号'
|
|
url = '/api/cutting_tool_type/list'
|
|
|
|
# 定时同步刀具型号
|
|
def sync_cutting_tool_type(self):
|
|
timestamp = str(int(time.time()))
|
|
check_str = TOKEN + timestamp + mrs_secret_key
|
|
check_mrs_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest()
|
|
headers = {'TOKEN': TOKEN,
|
|
'TIMESTAMP': timestamp,
|
|
'check_str': check_mrs_str}
|
|
strUrl = MRS + 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_type_all_list']:
|
|
brand = self.env['mrs.cutting_tool.type'].search(
|
|
[("code", '=', item['code'])])
|
|
if brand:
|
|
print(item['name'])
|
|
else:
|
|
self.env['mrs.cutting_tool.type'].create({
|
|
"id": item['id'],
|
|
"name": item['name'],
|
|
"remark": item['remark'],
|
|
"code": item['code'],
|
|
"active": item['active'],
|
|
"diameter": item['diameter'],
|
|
"cone_angle_pitch": item['cone_angle_pitch'],
|
|
"shank_diameter": item['shank_diameter'],
|
|
"long_blade": item['long_blade'],
|
|
"taper_shank_length": item['taper_shank_length'],
|
|
"tool_length": item['tool_length'],
|
|
"blade_number": item['blade_number'],
|
|
# "brand_id": item['brand_id'],
|
|
# "category_id": item['category_id']
|
|
})
|
|
else:
|
|
raise ValidationError("访问失败")
|