材料型号同步接口修改 新增国际标准和材料应用

This commit is contained in:
qihao.gong@jikimo.com
2023-10-09 17:35:39 +08:00
parent ea3dbb290f
commit b9d6e0ea35
5 changed files with 165 additions and 18 deletions

View File

@@ -29,7 +29,7 @@ class ResConfigSettings(models.TransientModel):
_logger.info("同步资源库表面工艺类别")
self.env['sf.production.process'].sync_all_production_process()
_logger.info("同步资源库表面工艺")
self.env['sf.processing.technology'].sync_all_processing_technology()
# self.env['sf.processing.technology'].sync_all_processing_technology()
_logger.info("同步资源库加工工艺")
self.env['sf.machine.brand.tags'].sync_all_machine_brand_tags()
_logger.info("同步资源库品牌类别")
@@ -47,8 +47,8 @@ class ResConfigSettings(models.TransientModel):
_logger.info("同步所有刀具类型...")
self.env['sf.cutting.tool.type'].sync_all_tool_type()
_logger.info("同步所有刀具类型完成")
_logger.info("同步所有刀具型号...")
self.env['sf.cutting.tool.model'].sync_all_tool_model()
# _logger.info("同步所有刀具型号...")
# self.env['sf.cutting.tool.model'].sync_all_tool_model()
_logger.info("同步所有刀具型号完成")
_logger.info("定时同步所有功能刀具类型列表...")
self.env['sf.functional.cutting.tool.model'].sync_all_functional_cutting_tool_model()
@@ -64,9 +64,13 @@ class ResConfigSettings(models.TransientModel):
_logger.info("同步夹具型号")
self.env['sf.functional.fixture.type'].sync_all_functional_fixture_type()
_logger.info("同步功能夹具类型")
self.env['sf.functional.fixture'].sync_all_functional_fixture()
# self.env['sf.functional.fixture'].sync_all_functional_fixture()
self.env['sf.machine_tool.type'].sync_all_machine_tool_type()
_logger.info("同步资源库机床型号")
self.env['sf.international.standards'].sync_all_mrs_international_standards()
_logger.info("同步资源库国际标准")
self.env['material.apply'].sync_all_material_apply()
_logger.info("同步资源库材料应用")
except Exception as e:
_logger.info("捕获错误信息:%s" % e)
raise ValidationError("数据错误导致同步失败,请联系管理员")

View File

@@ -165,9 +165,15 @@ class sfMaterialModel(models.Model):
"finish_machining": item['finish_machining'],
"materials_id": self.env['sf.production.materials'].search(
[("materials_no", '=', item['materials_id.materials_no'])]).id,
"standards_id": self.env['sf.international.standards'].search(
[("name", '=', item['standards_id'])]).id,
"need_h": item['need_h'],
"alloy_code": item['alloy_code'],
"mf_materia_post": item['mf_materia_post'],
"density": item['density'],
"materials_code": item['materials_code'],
"apply": self.env['material.apply'].search(
[("name", 'in', item['apply'])]).ids
# "tag_ids": item['tag_ids']
})
@@ -255,12 +261,12 @@ class sfProductionProcess(models.Model):
for item in result['production_process_yesterday_list']:
if item:
brand = self.env['sf.production.process'].search(
[("process_encode", '=', item['process_encode'])])
[("process_encode", '=', item['code'])])
if brand:
brand.name = item['name'],
brand.category_id = self.env['sf.production.process.category'].search(
[("code", '=', item['category_code'])]).id,
brand.process_encode = item['process_encode'],
brand.process_encode = item['code'],
brand.remark = item['remark'],
brand.active = item['active'],
brand.remark = item['remark']
@@ -269,7 +275,7 @@ class sfProductionProcess(models.Model):
"name": item['name'],
"category_id": self.env['sf.production.process.category'].search(
[("code", '=', item['category_code'])]).id,
"process_encode": item['process_encode'],
"process_encode": item['code'],
"remark": item['remark'],
"active": item['active'],
})
@@ -291,13 +297,13 @@ class sfProductionProcess(models.Model):
for item in result['production_process_all_list']:
if item:
brand = self.env['sf.production.process'].search(
[("process_encode", '=', item['process_encode'])])
[("process_encode", '=', item['code'])])
if not brand:
self.env['sf.production.process'].create({
"name": item['name'],
"category_id": self.env['sf.production.process.category'].search(
[("code", '=', item['category_code'])]).id,
"process_encode": item['process_encode'],
"process_encode": item['code'],
"remark": item['remark'],
"active": item['active'],
# "tag_ids": item['tag_ids']
@@ -2176,3 +2182,113 @@ class SfToolModel(models.Model):
print('同步所有刀具型号列表成功')
else:
raise ValidationError("认证未通过")
class MaterialApply(models.Model):
_inherit = 'material.apply'
_description = '材料应用'
url = '/api/material_apply/list'
# 定时同步材料应用
def sync_material_apply(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['material_apply_yesterday_list']:
brand = self.env['material.apply'].search(
[("name", '=', item['name'])])
if brand:
brand.name = item['name'],
brand.active = item['active']
else:
self.env['material.apply'].create({
"name": item['name'],
"active": item['active'],
})
else:
raise ValidationError("认证未通过")
# 同步所有材料应用
def sync_all_material_apply(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['material_apply_all_list']:
brand = self.env['material.apply'].search(
[("name", '=', item['name'])])
if not brand:
self.env['material.apply'].create({
"name": item['name'],
"active": item['active'],
})
else:
raise ValidationError("认证未通过")
class ModelInternationalStandards(models.Model):
_inherit = 'sf.international.standards'
_description = '制造标准'
url = '/api/mrs_international_standards/list'
# 定时同步制造标准
def sync_mrs_international_standards(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['mrs_international_standards_yesterday_list']:
brand = self.env['sf.international.standards'].search(
[("name", '=', item['name'])])
if brand:
brand.name = item['name'],
brand.active = item['active']
else:
self.env['sf.international.standards'].create({
"name": item['name'],
"active": item['active'],
})
else:
raise ValidationError("认证未通过")
# 同步所有制造标准
def sync_all_mrs_international_standards(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['mrs_international_standards_all_list']:
brand = self.env['sf.international.standards'].search(
[("name", '=', item['name'])])
if not brand:
self.env['sf.international.standards'].create({
"name": item['name'],
"active": item['active'],
})
else:
raise ValidationError("认证未通过")