修改机床型号同步接口以及基础数据

This commit is contained in:
qihao.gong@jikimo.com
2023-06-07 15:26:44 +08:00
parent 46c57162d7
commit 9d1597089b
3 changed files with 186 additions and 163 deletions

View File

@@ -567,121 +567,6 @@ class MachineBrand(models.Model):
raise ValidationError("认证未通过")
class MachineTool(models.Model):
_inherit = 'sf.machine_tool'
_description = '机床'
url = '/api/machine_tool/list'
crea_url = '/api/machine_tool/create'
# 定时同步机床
def sync_machine_tool(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_all_yesterday_list']:
brand = self.env['sf.machine_tool'].search(
[("code", '=', item['code'])])
if brand:
brand.id = item['id'],
brand.name = item['name'],
brand.code = item['code'],
brand.precision = item['precision'],
brand.knife_type = item['knife_type'],
brand.registration_date = item['registration_date'],
brand.number_of_knife_library = item['number_of_knife_library'],
brand.rotate_speed = item['rotate_speed'],
brand.number_of_axles = item['number_of_axles'],
# brand.control_system_id = item['control_system_id'],
brand.type_id = item['type_id'],
brand.brand_id = item['brand_id'],
brand.x_axis = item['x_axis'],
brand.y_axis = item['y_axis'],
brand.z_axis = item['z_axis'],
brand.b_axis = item['b_axis'],
brand.c_axis = item['c_axis'],
brand.state = item['state'],
brand.active = item['active']
else:
self.env['sf.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("认证未通过")
# 同步所有机床
def sync_all_machine_tool(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_all_list']:
brand = self.env['sf.machine_tool'].search(
[("code", '=', item['code'])])
if not brand:
self.env['sf.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': self.env['sf.machine.brand'].search([('code', '=', item['brand_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'],
# "tag_ids": item['tag_ids']
})
else:
raise ValidationError("认证未通过")
class MachineToolType(models.Model):
_inherit = 'sf.machine_tool.type'
@@ -726,6 +611,7 @@ class MachineToolType(models.Model):
[('code', '=', item['machine_tool_id'])]).id
else:
print(item['machine_tool_picture'].encode('utf-8'))
self.env['sf.machine_tool.type'].create({
"id": item['id'],
"name": item['name'],
@@ -747,6 +633,28 @@ class MachineToolType(models.Model):
[('code', '=', item['control_system_id'])]).id,
"active": item['active'],
'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id,
'machine_tool_picture' : 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": item['distance'],
"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'],
"machine_tool_category": self.env['sf.machine_tool.category'].search(
[('code', '=', item['machine_tool_category'])]).id,
})
else:
@@ -772,6 +680,7 @@ class MachineToolType(models.Model):
"id": item['id'],
"name": item['name'],
"code": item['code'],
"number_of_knife_library": item['number_of_knife_library'],
"rotate_speed": item['rotate_speed'],
'machine_tool_id': self.env['sf.machine_tool'].search(
@@ -788,6 +697,27 @@ class MachineToolType(models.Model):
[('code', '=', item['control_system_id'])]).id,
"active": item['active'],
'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id,
'machine_tool_picture':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": item['distance'],
"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'],
"machine_tool_category": self.env['sf.machine_tool.category'].search(
[('code', '=', item['machine_tool_category'])]).id,
})
else: