同步方法已完成,合并

This commit is contained in:
mgw
2023-06-12 14:48:06 +08:00
parent 3d04200ca7
commit 56580fa22a

View File

@@ -726,6 +726,7 @@ class MachineToolType(models.Model):
[('code', '=', item['machine_tool_id'])]).id [('code', '=', item['machine_tool_id'])]).id
else: else:
print(item['machine_tool_picture'].encode('utf-8'))
self.env['sf.machine_tool.type'].create({ self.env['sf.machine_tool.type'].create({
"id": item['id'], "id": item['id'],
"name": item['name'], "name": item['name'],
@@ -747,6 +748,27 @@ class MachineToolType(models.Model):
[('code', '=', item['control_system_id'])]).id, [('code', '=', item['control_system_id'])]).id,
"active": item['active'], "active": item['active'],
'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, '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: else:
@@ -772,6 +794,7 @@ class MachineToolType(models.Model):
"id": item['id'], "id": item['id'],
"name": item['name'], "name": item['name'],
"code": item['code'], "code": item['code'],
"number_of_knife_library": item['number_of_knife_library'], "number_of_knife_library": item['number_of_knife_library'],
"rotate_speed": item['rotate_speed'], "rotate_speed": item['rotate_speed'],
'machine_tool_id': self.env['sf.machine_tool'].search( 'machine_tool_id': self.env['sf.machine_tool'].search(
@@ -788,6 +811,27 @@ class MachineToolType(models.Model):
[('code', '=', item['control_system_id'])]).id, [('code', '=', item['control_system_id'])]).id,
"active": item['active'], "active": item['active'],
'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, '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: else:
@@ -1088,6 +1132,66 @@ class sfProductionProcessParameter(models.Model):
raise ValidationError("认证未通过") 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']:
brand = self.env['sf.machine_tool.category'].search(
[("code", '=', item['code'])])
if brand:
brand.name = item['name'],
brand.code = item['code'],
brand.category = item['category'],
brand.remark = item['remark']
else:
brand.name = item['name'],
brand.code = item['code'],
brand.category = item['category'],
brand.remark = item['remark']
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']:
brand = self.env['sf.machine_tool.category'].search(
[("code", '=', item['code'])])
if not brand:
self.env['sf.machine_tool.category'].create({
"name": item['name'],
"code": item['code'],
"category": item['category'],
"remark": item['remark'],
})
else:
raise ValidationError("认证未通过")
# 同步功能刀具列表 # 同步功能刀具列表
class sfSyncFunctional_cutting_tool(models.Model): class sfSyncFunctional_cutting_tool(models.Model):
_inherit = 'sf.functional.cutting.tool' _inherit = 'sf.functional.cutting.tool'