注册机床
This commit is contained in:
@@ -5,6 +5,8 @@ from odoo import models
|
||||
from odoo.exceptions import ValidationError
|
||||
import logging
|
||||
from odoo.addons.sf_base.commons.common import Common
|
||||
|
||||
from odoo.http import request
|
||||
from .res_config_setting import ResConfigSettings
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
@@ -18,7 +20,7 @@ class MrsProductionMaterials(models.Model):
|
||||
# 定时同步每日材料
|
||||
def sync_production_materials(self):
|
||||
|
||||
#配置中获取token
|
||||
# 配置中获取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']
|
||||
@@ -35,11 +37,11 @@ class MrsProductionMaterials(models.Model):
|
||||
brand = self.env['mrs.production.materials'].search(
|
||||
[("materials_no", '=', item['materials_no'])])
|
||||
if brand:
|
||||
brand.id=item['id'],
|
||||
brand.name= item['name'],
|
||||
brand.materials_no= item['materials_no'],
|
||||
brand.remark= item['remark'],
|
||||
brand.active= item['active']
|
||||
brand.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'],
|
||||
@@ -491,6 +493,49 @@ class MachineTool(models.Model):
|
||||
_inherit = 'mrs.machine_tool'
|
||||
_description = '机床'
|
||||
url = '/api/machine_tool/list'
|
||||
crea_url = '/api/machine_tool/create'
|
||||
|
||||
# 注册同步机床
|
||||
def enroll_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.crea_url
|
||||
objs_all = request.env['mrs.machine_tool'].sudo().search([])
|
||||
machine_tool_list = []
|
||||
if objs_all:
|
||||
for item in objs_all:
|
||||
val = {
|
||||
'id': item.id,
|
||||
'name': item.name,
|
||||
'code': item.code,
|
||||
'precision': item.precision,
|
||||
'knife_type': item.knife_type,
|
||||
'registration_date': str(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.id,
|
||||
# 'type_id': item.type_id.id,
|
||||
# 'brand_id': item.brand_id.id,
|
||||
'factory_id': item.factory_id.id,
|
||||
'supplier_id': item.supplier_id.id,
|
||||
'x_axis': item.x_axis,
|
||||
'y_axis': item.y_axis,
|
||||
'z_axis': item.z_axis,
|
||||
'b_axis': item.b_axis,
|
||||
'c_axis': item.c_axis,
|
||||
'state': item.state,
|
||||
'active': item.active
|
||||
}
|
||||
machine_tool_list.append(val)
|
||||
kw = json.dumps(machine_tool_list, ensure_ascii=False)
|
||||
print(type(kw))
|
||||
r = requests.post(strurl, json=kw, data=None, headers=headers)
|
||||
print(r)
|
||||
else:
|
||||
raise _logger.info("没有注册机床")
|
||||
|
||||
# 定时同步机床
|
||||
def sync_machine_tool(self):
|
||||
@@ -816,7 +861,7 @@ class CuttingToolType(models.Model):
|
||||
else:
|
||||
raise ValidationError("认证未通过")
|
||||
|
||||
# 同步所有刀具型号
|
||||
# 同步所有刀具型号
|
||||
def sync_all_cutting_tool_type(self):
|
||||
sf_sync_config = self.env['res.config.settings'].get_values()
|
||||
token = sf_sync_config['token']
|
||||
|
||||
Reference in New Issue
Block a user