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

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

@@ -68,6 +68,11 @@ class MrsMaterialModel(models.Model):
density = fields.Float("密度(kg/m³)")
materials_id = fields.Many2one('sf.production.materials', "材料名")
tensile_strength = fields.Char("拉伸强度(n/mm²)")
standards_id = fields.Many2one('sf.international.standards', '制造标准')
alloy_code = fields.Char('合金牌号')
price = fields.Float('单价/kg')
apply = fields.Many2many('material.apply', string='材料应用')
materials_code = fields.Char('材料代号')
hardness = fields.Float("硬度(hrc)")
rough_machining = fields.Float("粗加工Vc(m/min)")
finish_machining = fields.Float("精加工Vc(m/min)")
@@ -172,3 +177,20 @@ class MrsProductionProcessParameter(models.Model):
for i in item.parameter_ids:
code_arr.append(i.code)
return code_arr
class ModelInternationalStandards(models.Model):
_name = 'sf.international.standards'
_description = '制造标准'
code = fields.Char('编码')
name = fields.Char('名称')
active = fields.Boolean('有效', default=True)
class MrsMaterialApply(models.Model):
_name = 'material.apply'
_description = '材料应用'
name = fields.Char('名称', default=True)
active = fields.Boolean('有效', default=True)

View File

@@ -24,6 +24,8 @@ access_sf_fixture_model,sf_fixture_model,model_sf_fixture_model,base.group_user,
access_sf_functional_fixture_type,sf_functional_fixture_type,model_sf_functional_fixture_type,base.group_user,1,1,1,1
access_sf_functional_fixture,sf_functional_fixture,model_sf_functional_fixture,base.group_user,1,1,1,1
access_sf_sync_common,sf_sync_common,model_sf_sync_common,base.group_user,1,1,1,1
access_sf_international_standards,sf_international_standards,model_sf_international_standards,base.group_user,1,1,1,1
access_material_apply,material_apply,model_material_apply,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
24 access_sf_functional_fixture_type sf_functional_fixture_type model_sf_functional_fixture_type base.group_user 1 1 1 1
25 access_sf_functional_fixture sf_functional_fixture model_sf_functional_fixture base.group_user 1 1 1 1
26 access_sf_sync_common sf_sync_common model_sf_sync_common base.group_user 1 1 1 1
27 access_sf_international_standards sf_international_standards model_sf_international_standards base.group_user 1 1 1 1
28 access_material_apply material_apply model_material_apply base.group_user 1 1 1 1
29
30
31

View File

@@ -241,17 +241,20 @@
<record model="ir.ui.view" id="sf_materials_model_tree">
<field name="model">sf.materials.model</field>
<field name="arch" type="xml">
<tree string="材料型号" create="0" delete="1">
<field name="materials_no" readonly="1"/>
<field name="name" readonly="1"/>
<field name="gain_way"/>
<tree string="材料型号" delete="0">
<field name="materials_no"/>
<field name="materials_code"/>
<field name="name"/>
<field name="standards_id" optional="hide"/>
<field name="alloy_code"/>
<field name="tensile_strength"/>
<field name="hardness"/>
<field name="hardness" optional="show"/>
<field name="need_h"/>
<field name="density"/>
<field name="rough_machining"/>
<field name="finish_machining"/>
<field name="remark"/>
<field name="apply" widget="many2many_tags" optional="show"/>
<field name="density" optional="show"/>
<field name="rough_machining" optional="hide"/>
<field name="finish_machining" optional="hide"/>
<field name="remark" optional="hide"/>
<field name='materials_id' invisible="1"/>
</tree>
</field>

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("认证未通过")