diff --git a/sf_base/commons/__init__.py b/sf_base/commons/__init__.py new file mode 100644 index 00000000..3e880316 --- /dev/null +++ b/sf_base/commons/__init__.py @@ -0,0 +1 @@ +from. import common \ No newline at end of file diff --git a/sf_base/commons/common.py b/sf_base/commons/common.py new file mode 100644 index 00000000..abdbeb10 --- /dev/null +++ b/sf_base/commons/common.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +from odoo import fields, models, api +import time +import hashlib + + + + + +class Common(models.Model): + _name = 'sf.sync.common' + _description = u'公用类' + + + + def get_headers(self,token,mrs_secret_key): + ''' + 获取requests中的heardes参数 + ''' + 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), + 'checkstr': check_mrs_str} + return headers + + diff --git a/sf_base/models/sf_base.py b/sf_base/models/sf_base.py index 1697d4b9..05334842 100644 --- a/sf_base/models/sf_base.py +++ b/sf_base/models/sf_base.py @@ -3,26 +3,28 @@ import logging from odoo import fields, models, api - _logger = logging.getLogger(__name__) class MachineBrandTags(models.Model): _name = 'mrs.machine.brand.tags' _description = '标签' - + brand_id = fields.Many2one('mrs.machine.brand', '品牌') name = fields.Char('名称', size=50) color = fields.Integer('颜色', default=0) + active = fields.Boolean('有效', default=True) class MachineControlSystem(models.Model): _name = 'mrs.machine_tool.type.control_system' _description = '控制系统' code = fields.Char('编码') - name = fields.Char('名称', size=50) + name = fields.Char('名称', size=10) # type_id = fields.Many2one('mrs.machine_tool.type') + brand_id = fields.Many2one('mrs.machine.brand', '品牌') active = fields.Boolean('有效', default=True) + # 品牌标签 class MachineBrand(models.Model): _name = 'mrs.machine.brand' @@ -48,7 +50,7 @@ class MachineTool(models.Model): number_of_knife_library = fields.Integer('刀库数量') rotate_speed = fields.Integer('转速') number_of_axles = fields.Selection( - [("3轴", "3轴"), ("4轴", "4轴"), ("5轴", "5轴")], + [("三轴", "三轴"), ("四轴", "四轴"), ("五轴", "五轴")], default="", string="轴数") # 加工进程 x_axis = fields.Integer('X轴') @@ -64,7 +66,7 @@ class MachineTool(models.Model): type_id = fields.Many2one('mrs.machine_tool.type', '型号', compute='_compute_type_id') brand_id = fields.Many2one('mrs.machine.brand', string='品牌') - status = fields.Selection( + state = fields.Selection( [("正常", "正常"), ("故障", "故障"), ("不可用", "不可用")], default="", string="状态") @@ -136,7 +138,7 @@ class MachineToolType(models.Model): # 多个型号对应一个机床 machine_tool_id = fields.Many2one('mrs.machine_tool', '机床') number_of_axles = fields.Selection( - [("3轴", "3轴"), ("4轴", "4轴"), ("5轴", "5轴")], + [("三轴", "三轴"), ("四轴", "四轴"), ("五轴", "五轴")], default="", string="轴数") # 加工进程 x_axis = fields.Integer('X轴') diff --git a/sf_base/security/ir.model.access.csv b/sf_base/security/ir.model.access.csv index 6df5e07e..2ac30253 100644 --- a/sf_base/security/ir.model.access.csv +++ b/sf_base/security/ir.model.access.csv @@ -1,17 +1,17 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_mrs_machine_tool,mrs_machine_tool,model_mrs_machine_tool,base.group_user,1,1,1,1 -access_mrs_cutting_tool_category,mrs_cutting_tool_category,model_mrs_cutting_tool_category,base.group_user,1,1,1,1 -access_mrs_machine_tool_type,mrs_machine_tool_type,model_mrs_machine_tool_type,base.group_user,1,1,1,1 -access_mrs_cutting_tool_type,mrs_cutting_tool_type,model_mrs_cutting_tool_type,base.group_user,1,1,1,1 -access_mrs_machine_brand,mrs_machine_brand,model_mrs_machine_brand,base.group_user,1,1,1,1 -access_mrs_machine_brand_tags,mrs_machine_brand_tags,model_mrs_machine_brand_tags,base.group_user,1,1,1,1 -access_mrs_machine_tool_type_control_system,mrs_machine_tool_type_control_system,model_mrs_machine_tool_type_control_system,base.group_user,1,1,1,1 +access_mrs_machine_tool,mrs_machine_tool,model_mrs_machine_tool,base.group_user,1,0,0,0 +access_mrs_cutting_tool_category,mrs_cutting_tool_category,model_mrs_cutting_tool_category,base.group_user,1,0,0,0 +access_mrs_machine_tool_type,mrs_machine_tool_type,model_mrs_machine_tool_type,base.group_user,1,0,0,0 +access_mrs_cutting_tool_type,mrs_cutting_tool_type,model_mrs_cutting_tool_type,base.group_user,1,0,0,0 +access_mrs_machine_brand,mrs_machine_brand,model_mrs_machine_brand,base.group_user,1,0,0,0 +access_mrs_machine_brand_tags,mrs_machine_brand_tags,model_mrs_machine_brand_tags,base.group_user,1,0,0,0 +access_mrs_machine_tool_type_control_system,mrs_machine_tool_type_control_system,model_mrs_machine_tool_type_control_system,base.group_user,1,0,0,0 -access_mrs_processing_order,mrs_processing_order,model_mrs_processing_order,base.group_user,1,1,1,1 -access_mrs_production_process,mrs_production_process,model_mrs_production_process,base.group_user,1,1,1,1 -access_mrs_production_materials,mrs_production_materials,model_mrs_production_materials,base.group_user,1,1,1,1 -access_mrs_materials_model,mrs_materials_model,model_mrs_materials_model,base.group_user,1,1,1,1 -access_mrs_processing_technology,mrs_processing_technology,model_mrs_processing_technology,base.group_user,1,1,1,1 +access_mrs_processing_order,mrs_processing_order,model_mrs_processing_order,base.group_user,1,0,0,0 +access_mrs_production_process,mrs_production_process,model_mrs_production_process,base.group_user,1,0,0,0 +access_mrs_production_materials,mrs_production_materials,model_mrs_production_materials,base.group_user,1,0,0,0 +access_mrs_materials_model,mrs_materials_model,model_mrs_materials_model,base.group_user,1,0,0,0 +access_mrs_processing_technology,mrs_processing_technology,model_mrs_processing_technology,base.group_user,1,0,0,0 diff --git a/sf_mrs_sync/__manifest__.py b/sf_mrs_sync/__manifest__.py index e3151056..7b48be72 100644 --- a/sf_mrs_sync/__manifest__.py +++ b/sf_mrs_sync/__manifest__.py @@ -12,7 +12,7 @@ 'website': 'https://www.sf.cs.jikimo.com', 'depends': ['account', 'sf_base', 'base'], 'data': [ - + 'views/sf_sync_config_settings_views.xml', 'data/sf_cron.xml' diff --git a/sf_mrs_sync/models/__init__.py b/sf_mrs_sync/models/__init__.py index 12d77b52..e1d23e51 100644 --- a/sf_mrs_sync/models/__init__.py +++ b/sf_mrs_sync/models/__init__.py @@ -1,2 +1,3 @@ # -*-coding:utf-8-*- -from. import sf_sync_common \ No newline at end of file +from . import sf_sync_common +from . import res_config_setting diff --git a/sf_mrs_sync/models/res_config_setting.py b/sf_mrs_sync/models/res_config_setting.py new file mode 100644 index 00000000..e42776c7 --- /dev/null +++ b/sf_mrs_sync/models/res_config_setting.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# Part of SmartGo. See LICENSE file for full copyright and licensing details. +import logging + +from odoo import api, fields, models + +_logger = logging.getLogger(__name__) + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + token = fields.Char(string='TOKEN', default='b811ac06-3f00-11ed-9aed-0242ac110003') + mrs_secret_key = fields.Char(string='密钥', default= 'wBmxej38OkErKhD6') + mrs_url = fields.Char(string='访问地址', default= 'https://mrs.cs.jikimo.com') + + @api.model + def get_values(self): + """ + 重载获取参数的方法,参数都存在系统参数中 + :return: + """ + values = super(ResConfigSettings, self).get_values() + config = self.env['ir.config_parameter'].sudo() + token = config.get_param('token', default='') + mrs_secret_key = config.get_param('mrs_secret_key', default='') + mrs_url = config.get_param('mrs_url', default='') + + values.update( + token=token, + mrs_secret_key=mrs_secret_key, + mrs_url=mrs_url, + ) + return values + + def set_values(self): + super(ResConfigSettings, self).set_values() + ir_config = self.env['ir.config_parameter'].sudo() + ir_config.set_param("token", self.token or "") + ir_config.set_param("mrs_secret_key", self.mrs_secret_key or "") + ir_config.set_param("mrs_url", self.mrs_url or "") + diff --git a/sf_mrs_sync/models/sf_sync_common.py b/sf_mrs_sync/models/sf_sync_common.py index 7484a76c..5484d294 100644 --- a/sf_mrs_sync/models/sf_sync_common.py +++ b/sf_mrs_sync/models/sf_sync_common.py @@ -1,68 +1,44 @@ # -*- 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 import models from odoo.exceptions import ValidationError import logging +from odoo.addons.sf_base.commons.common import Common +from .res_config_setting import ResConfigSettings _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} + #配置中获取token + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) - print(headers) + strUrl = sf_sync_config['mrs_url'] + self.url - r = requests.post((MRS + self.url), json={}, data=None, headers=headers) + 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']: + for item in result['production_materials_yesterday_list']: if item: brand = self.env['mrs.production.materials'].search( [("materials_no", '=', item['materials_no'])]) if brand: - print(item['name']) + brand.id=item['id'], + brand.name= item['name'], + brand.materials_no= item['materials_no'], + brand.remark= item['remark'], + brand.active= item['active'] else: self.env['mrs.production.materials'].create({ "id": item['id'], @@ -70,10 +46,38 @@ class MrsProductionMaterials(models.Model): "materials_no": item['materials_no'], "remark": item['remark'], "active": item['active'] - }) else: - raise ValidationError("访问失败") + raise ValidationError("认证未通过") + + # 同步所有材料 + def sync_all_production_materials(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_url'] + self.url + r = requests.post(strUrl, json={}, data=None, headers=headers) + r = r.json() + result = json.loads(r['result']) + if result['status'] == 1: + for item in result['production_materials_all_list']: + if item: + # brand = self.env['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): @@ -81,22 +85,19 @@ class MrsMaterialModel(models.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} + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) - print(headers) - strUrl = MRS + self.url + strUrl = sf_sync_config['mrs_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']: + for item in result['materials_model_yesterday_list']: if item: brand = self.env['mrs.materials.model'].search( [("materials_num", '=', item['materials_num'])]) @@ -117,7 +118,36 @@ class MrsMaterialModel(models.Model): }) else: - raise ValidationError("访问失败") + raise ValidationError("认证未通过") + + # 同步所有材料型号 + def sync_all_materials_model(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + strUrl = sf_sync_config['mrs_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: + 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): @@ -125,21 +155,19 @@ class MrsProductionProcess(models.Model): _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} + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) - strUrl = MRS + self.url + strUrl = sf_sync_config['mrs_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']: + for item in result['production_process_yesterday_list']: if item: brand = self.env['mrs.production.process'].search( [("process_encode", '=', item['process_encode'])]) @@ -156,7 +184,33 @@ class MrsProductionProcess(models.Model): }) else: - raise ValidationError("访问失败") + raise ValidationError("认证未通过") # 定时同步表面工艺 + + # 同步所有表面工艺 + def sync_all_production_process(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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: + 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): @@ -166,18 +220,17 @@ class MrsProcessingTechnology(models.Model): # 定时同步加工工艺 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 + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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']: + for item in result['processing_technology_yesterday_list']: if item: brand = self.env['mrs.processing.technology'].search( [("process_encode", '=', item['process_encode'])]) @@ -194,7 +247,33 @@ class MrsProcessingTechnology(models.Model): }) else: - raise ValidationError("访问失败") + raise ValidationError("认证未通过") + + # 同步所有加工工艺 + def sync_all_processing_technology(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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: + 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): @@ -204,18 +283,17 @@ class MachineBrandTags(models.Model): # 定时同步品牌类别 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 + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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']: + for item in result['machine_brand_tags_yesterday_list']: brand = self.env['mrs.machine.brand.tags'].search( [("id", '=', item['id'])]) if brand: @@ -228,7 +306,29 @@ class MachineBrandTags(models.Model): }) else: - raise ValidationError("访问失败") + raise ValidationError("认证未通过") + + # 同步所有品牌类别 + def sync_all_machine_brand_tags(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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']: + self.env['mrs.machine.brand.tags'].create({ + "id": item['id'], + "name": item['name'], + "color": item['color'], + + }) + else: + raise ValidationError("认证未通过") class MachineControlSystem(models.Model): @@ -238,18 +338,17 @@ class MachineControlSystem(models.Model): # 定时同步控制系统 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 + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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']: + for item in result['machine_control_system_yesterday_list']: if item: brand = self.env['mrs.machine_tool.type.control_system'].search( [("code", '=', item['code'])]) @@ -267,7 +366,35 @@ class MachineControlSystem(models.Model): }) else: - raise ValidationError("访问失败") + 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'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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: + 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): @@ -277,19 +404,18 @@ class MachineBrand(models.Model): # 定时同步品牌 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 ) + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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']: + for item in result['machine_brand_yesterday_list']: brand = self.env['mrs.machine.brand'].search( [("code", '=', item['code'])]) if brand: @@ -305,7 +431,33 @@ class MachineBrand(models.Model): }) else: - raise ValidationError("访问失败") + raise ValidationError("认证未通过") + + # 同步所有品牌 + def sync_all_machine_brand(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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']: + 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): @@ -315,18 +467,17 @@ class MachineTool(models.Model): # 定时同步机床 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 + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: - for item in result['machine_tool_all_list']: + for item in result['machine_tool_yesterday_list']: brand = self.env['mrs.machine_tool'].search( [("code", '=', item['code'])]) if brand: @@ -357,7 +508,47 @@ class MachineTool(models.Model): }) else: - raise ValidationError("访问失败") + raise ValidationError("认证未通过") + + # 同步所有机床 + def sync_all_machine_tool(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_url'] + self.url + r = requests.post(strUrl, json={}, data=None, headers=headers) + r = r.json() + result = json.loads(r['result']) + if result['status'] == 1: + for item in result['machine_tool_all_list']: + 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): @@ -367,18 +558,17 @@ class MachineToolType(models.Model): # 定时同步机床型号 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 + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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']: + for item in result['machine_tool_type_yesterday_list']: brand = self.env['mrs.machine_tool.type'].search( [("code", '=', item['code'])]) if brand: @@ -405,7 +595,43 @@ class MachineToolType(models.Model): }) else: - raise ValidationError("访问失败") + raise ValidationError("认证未通过") + + # 同步所有机床型号 + def sync_all_machine_tool_type(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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']: + 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): @@ -415,18 +641,17 @@ class CuttingTool(models.Model): # 定时同步刀具类别 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 + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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_category_all_list']: + for item in result['cutting_tool_category_yesterday_list']: brand = self.env['mrs.cutting_tool.category'].search( [("code", '=', item['code'])]) if brand: @@ -442,7 +667,32 @@ class CuttingTool(models.Model): }) else: - raise ValidationError("访问失败") + raise ValidationError("认证未通过") + + # 同步所有刀具类别 + def sync_all_cutting_tool_category(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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_category_all_list']: + 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): @@ -452,18 +702,17 @@ class CuttingToolType(models.Model): # 定时同步刀具型号 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 + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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_type_all_list']: + for item in result['cutting_tool_type_yesterday_list']: brand = self.env['mrs.cutting_tool.type'].search( [("code", '=', item['code'])]) if brand: @@ -486,4 +735,36 @@ class CuttingToolType(models.Model): # "category_id": item['category_id'] }) else: - raise ValidationError("访问失败") + raise ValidationError("认证未通过") + + # 同步所有刀具型号 + def sync_all_cutting_tool_type(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + + strUrl = sf_sync_config['mrs_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_type_all_list']: + 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("认证未通过") diff --git a/sf_mrs_sync/views/sf_sync_config_settings_views.xml b/sf_mrs_sync/views/sf_sync_config_settings_views.xml new file mode 100644 index 00000000..8cc9084f --- /dev/null +++ b/sf_mrs_sync/views/sf_sync_config_settings_views.xml @@ -0,0 +1,39 @@ + + + + + res.config.settings.view.form.inherit.sf_sync + res.config.settings + + + +
+

同步参数配置

+
+
+
+
+
+
+
+
+
+
+
+
+ + +
+
+ + + + + + \ No newline at end of file