新增调取cloud的刀具标准库接口
This commit is contained in:
@@ -79,6 +79,7 @@ class MrsMaterialModel(models.Model):
|
|||||||
active = fields.Boolean('有效', default=True)
|
active = fields.Boolean('有效', default=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MrsProductionProcessCategory(models.Model):
|
class MrsProductionProcessCategory(models.Model):
|
||||||
_name = 'sf.production.process.category'
|
_name = 'sf.production.process.category'
|
||||||
_description = '表面工艺类别'
|
_description = '表面工艺类别'
|
||||||
|
|||||||
@@ -51,10 +51,18 @@
|
|||||||
attrs="{'invisible': ['|',('categ_type', '!=', '表面工艺'),('categ_type', '=', False)]}"/>
|
attrs="{'invisible': ['|',('categ_type', '!=', '表面工艺'),('categ_type', '=', False)]}"/>
|
||||||
<field name="cutting_tool_material_id" attrs="{'invisible': [('categ_type', '!=', '刀具')]}"
|
<field name="cutting_tool_material_id" attrs="{'invisible': [('categ_type', '!=', '刀具')]}"
|
||||||
placeholder="请选择"/>
|
placeholder="请选择"/>
|
||||||
<field name="cutting_tool_model_id" placeholder="请选择"
|
<!-- <field name="cutting_tool_model_id" placeholder="请选择"-->
|
||||||
context="{'default_cutting_tool_material_id': cutting_tool_material_id,'default_cutting_tool_type_id': cutting_tool_type_id}"
|
<!-- attrs="{'invisible': [('categ_type', '!=', '刀具')]}"/>-->
|
||||||
attrs="{'invisible': [('categ_type', '!=', '刀具')]}"
|
<field name="cutting_tool_model" attrs="{'invisible': [('categ_type', '!=', '刀具')]}">
|
||||||
domain="[('cutting_tool_material_id','=',cutting_tool_material_id)]"/>
|
<templates>
|
||||||
|
|
||||||
|
<t t-foreach="cutting_tool_model_data" t-as="data">
|
||||||
|
<td>
|
||||||
|
<t t-esc="cutting_tool_model_data.name"/>
|
||||||
|
</td>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
|
</field>
|
||||||
<field name="fixture_material_id" attrs="{'invisible': [('categ_type', '!=', '夹具')]}"
|
<field name="fixture_material_id" attrs="{'invisible': [('categ_type', '!=', '夹具')]}"
|
||||||
placeholder="请选择"/>
|
placeholder="请选择"/>
|
||||||
<field name="fixture_model_id" string="型号" placeholder="请选择"
|
<field name="fixture_model_id" string="型号" placeholder="请选择"
|
||||||
@@ -106,7 +114,7 @@
|
|||||||
<page string="刀具物料参数" attrs="{'invisible': [('categ_type', '!=', '刀具')]}">
|
<page string="刀具物料参数" attrs="{'invisible': [('categ_type', '!=', '刀具')]}">
|
||||||
<group>
|
<group>
|
||||||
<group attrs="{'invisible': [('categ_type', '!=', '刀具')]}" col="1">
|
<group attrs="{'invisible': [('categ_type', '!=', '刀具')]}" col="1">
|
||||||
<field name="cutting_tool_type_id" options="{'no_create': True}" placeholder="请选择" />
|
<field name="cutting_tool_type_id" options="{'no_create': True}" placeholder="请选择"/>
|
||||||
<field name="brand_id" options="{'no_create': True}" placeholder="请选择"/>
|
<field name="brand_id" options="{'no_create': True}" placeholder="请选择"/>
|
||||||
<field name="materials_type_id" options="{'no_create': True}"
|
<field name="materials_type_id" options="{'no_create': True}"
|
||||||
attrs="{'invisible': [('cutting_tool_type', 'in', ('整体式刀具','夹头','刀柄'))]}"
|
attrs="{'invisible': [('cutting_tool_type', 'in', ('整体式刀具','夹头','刀柄'))]}"
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
from odoo.modules import get_resource_path
|
from odoo.modules import get_resource_path
|
||||||
from OCC.Extend.DataExchange import read_step_file
|
from odoo.addons.sf_base.commons.common import Common
|
||||||
from OCC.Extend.DataExchange import write_stl_file
|
# from OCC.Extend.DataExchange import read_step_file
|
||||||
|
# from OCC.Extend.DataExchange import write_stl_file
|
||||||
import logging
|
import logging
|
||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
class ResProductMo(models.Model):
|
class ResProductMo(models.Model):
|
||||||
@@ -62,6 +65,8 @@ class ResProductMo(models.Model):
|
|||||||
|
|
||||||
cutting_tool_model_id = fields.Many2one('sf.cutting.tool.model', string='型号',
|
cutting_tool_model_id = fields.Many2one('sf.cutting.tool.model', string='型号',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cutting_tool_model = fields.Char('型号')
|
||||||
cutting_tool_type_id = fields.Many2one('sf.cutting.tool.type', string='类型',
|
cutting_tool_type_id = fields.Many2one('sf.cutting.tool.type', string='类型',
|
||||||
domain="[('cutting_tool_material_id.name', '=', cutting_tool_type)]")
|
domain="[('cutting_tool_material_id.name', '=', cutting_tool_type)]")
|
||||||
|
|
||||||
@@ -104,7 +109,6 @@ class ResProductMo(models.Model):
|
|||||||
suitable_coolant_ids = fields.Many2many('maintenance.equipment.image', 'rel_coolant_product_template',
|
suitable_coolant_ids = fields.Many2many('maintenance.equipment.image', 'rel_coolant_product_template',
|
||||||
'适合冷却液', domain=[('type', '=', '冷却液')])
|
'适合冷却液', domain=[('type', '=', '冷却液')])
|
||||||
|
|
||||||
|
|
||||||
# @api.constrains('suitable_machining_method_ids')
|
# @api.constrains('suitable_machining_method_ids')
|
||||||
# def _check_suitable_machining_method_ids(self):
|
# def _check_suitable_machining_method_ids(self):
|
||||||
# for record in self:
|
# for record in self:
|
||||||
@@ -406,9 +410,31 @@ class ResProductMo(models.Model):
|
|||||||
|
|
||||||
@api.onchange('cutting_tool_material_id')
|
@api.onchange('cutting_tool_material_id')
|
||||||
def _onchange_cutting_tool_material_id(self):
|
def _onchange_cutting_tool_material_id(self):
|
||||||
for item in self:
|
try:
|
||||||
if item.cutting_tool_material_id.id != item.cutting_tool_model_id.cutting_tool_material_id.id:
|
config = self.env['res.config.settings'].get_values()
|
||||||
item.cutting_tool_model_id = False
|
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||||
|
url = config['sf_url'] + '/api/cutting_model/list'
|
||||||
|
res = {'token': config['token'], 'cutting_tool_material_code': self.cutting_tool_material_id.code}
|
||||||
|
result = requests.post(url, json={}, data=res, headers=headers)
|
||||||
|
result = result.json()
|
||||||
|
if result['status'] == 1:
|
||||||
|
self.cutting_tool_model = result['data']
|
||||||
|
except Exception as e:
|
||||||
|
logging.info("获取刀具标准库失败")
|
||||||
|
|
||||||
|
@api.depends('cutting_tool_material_id')
|
||||||
|
def _get_cutting_tool_model(self):
|
||||||
|
try:
|
||||||
|
config = self.env['res.config.settings'].get_values()
|
||||||
|
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||||
|
url = config['sf_url'] + '/api/cutting_model/list'
|
||||||
|
res = {'token': config['token'], 'cutting_tool_material_code': self.cutting_tool_material_id.code}
|
||||||
|
result = requests.post(url, json=res, data=None, headers=headers)
|
||||||
|
cutting_model_data = result.json()
|
||||||
|
if result['state'] == 1:
|
||||||
|
return {'cutting_model_data': cutting_model_data}
|
||||||
|
except Exception as e:
|
||||||
|
logging.info("获取刀具标准库失败")
|
||||||
|
|
||||||
@api.onchange('fixture_material_id')
|
@api.onchange('fixture_material_id')
|
||||||
def _onchange_fixture_material_id(self):
|
def _onchange_fixture_material_id(self):
|
||||||
@@ -736,9 +762,9 @@ class ResProductMo(models.Model):
|
|||||||
|
|
||||||
# 将attach的datas内容转为glb文件
|
# 将attach的datas内容转为glb文件
|
||||||
def transition_glb_file(self, report_path, code):
|
def transition_glb_file(self, report_path, code):
|
||||||
shapes = read_step_file(report_path)
|
# shapes = read_step_file(report_path)
|
||||||
output_file = os.path.join('/tmp', str(code) + '.stl')
|
output_file = os.path.join('/tmp', str(code) + '.stl')
|
||||||
write_stl_file(shapes, output_file, 'binary', 0.03, 0.5)
|
# write_stl_file(shapes, output_file, 'binary', 0.03, 0.5)
|
||||||
# 转化为glb
|
# 转化为glb
|
||||||
output_glb_file = os.path.join('/tmp', str(code) + '.glb')
|
output_glb_file = os.path.join('/tmp', str(code) + '.glb')
|
||||||
util_path = get_resource_path('sf_dlm', 'static/util')
|
util_path = get_resource_path('sf_dlm', 'static/util')
|
||||||
@@ -783,6 +809,7 @@ class ResMrpBomMo(models.Model):
|
|||||||
# 坯料BOM组件:选取当前坯料原材料,
|
# 坯料BOM组件:选取当前坯料原材料,
|
||||||
# 然后根据当前的坯料的体积得出需要的原材料重量(立方米m³) *材料密度 * 1000 = 所需原材料重量KG(公斤)
|
# 然后根据当前的坯料的体积得出需要的原材料重量(立方米m³) *材料密度 * 1000 = 所需原材料重量KG(公斤)
|
||||||
# 坯料所需原材料公式:当前的坯料的体积(立方米m³) *材料密度 * 1000 = 所需原材料重量KG(公斤)
|
# 坯料所需原材料公式:当前的坯料的体积(立方米m³) *材料密度 * 1000 = 所需原材料重量KG(公斤)
|
||||||
|
|
||||||
def bom_create_line(self, embryo):
|
def bom_create_line(self, embryo):
|
||||||
# 选取当前坯料原材料
|
# 选取当前坯料原材料
|
||||||
raw_bom_line = self.get_raw_bom(embryo)
|
raw_bom_line = self.get_raw_bom(embryo)
|
||||||
@@ -801,7 +828,6 @@ class ResMrpBomMo(models.Model):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
# 查询材料型号默认排第一的供应商
|
# 查询材料型号默认排第一的供应商
|
||||||
|
|
||||||
def get_supplier(self, materials_type):
|
def get_supplier(self, materials_type):
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ class sfProductionProcess(models.Model):
|
|||||||
self.create({
|
self.create({
|
||||||
"name": item['name'],
|
"name": item['name'],
|
||||||
"category_id": category.id,
|
"category_id": category.id,
|
||||||
"process_encode": item['process_encode'],
|
"process_encode": item['code'],
|
||||||
"remark": item['remark'],
|
"remark": item['remark'],
|
||||||
"active": item['active'],
|
"active": item['active'],
|
||||||
})
|
})
|
||||||
@@ -563,7 +563,7 @@ class MachineBrand(models.Model):
|
|||||||
brand = self.search([("code", '=', item['code'])])
|
brand = self.search([("code", '=', item['code'])])
|
||||||
if brand:
|
if brand:
|
||||||
brand.name = item['name']
|
brand.name = item['name']
|
||||||
brand.image_brand = '' if not item['image_brand'] else base64.b64encode(item.image_brand)
|
brand.image_brand = '' if not item['image_brand'] else base64.b64decode(item['image_brand'])
|
||||||
brand.active = item['active']
|
brand.active = item['active']
|
||||||
brand.remark = item['remark']
|
brand.remark = item['remark']
|
||||||
brand.tag_ids = self.env['sf.machine.brand.tags'].search([("name", 'in', item['tag_ids'])]).ids
|
brand.tag_ids = self.env['sf.machine.brand.tags'].search([("name", 'in', item['tag_ids'])]).ids
|
||||||
@@ -571,7 +571,7 @@ class MachineBrand(models.Model):
|
|||||||
self.create({
|
self.create({
|
||||||
"name": item['name'],
|
"name": item['name'],
|
||||||
"code": item['code'],
|
"code": item['code'],
|
||||||
"image_brand": '' if not item['image_brand'] else base64.b64encode(item.image_brand),
|
"image_brand": '' if not item['image_brand'] else base64.b64decode(item['image_brand']),
|
||||||
"active": item['active'],
|
"active": item['active'],
|
||||||
"remark": item['remark'],
|
"remark": item['remark'],
|
||||||
"tag_ids": self.env['sf.machine.brand.tags'].search([("name", 'in', item['tag_ids'])]).ids,
|
"tag_ids": self.env['sf.machine.brand.tags'].search([("name", 'in', item['tag_ids'])]).ids,
|
||||||
@@ -593,22 +593,18 @@ class MachineBrand(models.Model):
|
|||||||
for item in result['machine_brand_all_list']:
|
for item in result['machine_brand_all_list']:
|
||||||
brand = self.search([("code", '=', item['code'])])
|
brand = self.search([("code", '=', item['code'])])
|
||||||
if not brand:
|
if not brand:
|
||||||
if item.get('image_brand'):
|
|
||||||
image = base64.b64decode(item['image_brand'])
|
|
||||||
else:
|
|
||||||
image = ''
|
|
||||||
self.create({
|
self.create({
|
||||||
"name": item['name'],
|
"name": item['name'],
|
||||||
"code": item['code'],
|
"code": item['code'],
|
||||||
"remark": item['remark'],
|
"remark": item['remark'],
|
||||||
"image_brand": image,
|
"image_brand": '' if not item['image_brand'] else base64.b64decode(item['image_brand']),
|
||||||
"tag_ids": self.env['sf.machine.brand.tags'].search(
|
"tag_ids": self.env['sf.machine.brand.tags'].search(
|
||||||
[("name", 'in', item['tag_ids'])]).ids
|
[("name", 'in', item['tag_ids'])]).ids
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
brand.name = item['name']
|
brand.name = item['name']
|
||||||
brand.remark = item['remark']
|
brand.remark = item['remark']
|
||||||
brand.image_brand = '' if not item['image_brand'] else base64.b64encode(item.image_brand)
|
brand.image_brand = '' if not item['image_brand'] else base64.b64decode(item['image_brand'])
|
||||||
brand.tag_ids = self.env['sf.machine.brand.tags'].search(
|
brand.tag_ids = self.env['sf.machine.brand.tags'].search(
|
||||||
[("name", 'in', item['tag_ids'])]).ids
|
[("name", 'in', item['tag_ids'])]).ids
|
||||||
else:
|
else:
|
||||||
@@ -933,16 +929,13 @@ class sfProductionProcessParameter(models.Model):
|
|||||||
r = r.json()
|
r = r.json()
|
||||||
result = json.loads(r['result'])
|
result = json.loads(r['result'])
|
||||||
if result['status'] == 1:
|
if result['status'] == 1:
|
||||||
_logger.info('result:%s' % result)
|
|
||||||
for item in result['mrs_production_process_parameter_all_list']:
|
for item in result['mrs_production_process_parameter_all_list']:
|
||||||
if item:
|
if item:
|
||||||
_logger.info('create可选参数:%s' % item)
|
|
||||||
production_process_parameter = self.search(
|
production_process_parameter = self.search(
|
||||||
[("code", '=', item['code'])])
|
[("code", '=', item['code'])])
|
||||||
process = self.env['sf.production.process'].search(
|
process = self.env['sf.production.process'].search(
|
||||||
[('process_encode', '=', item['process_id_code'])])
|
[('process_encode', '=', item['process_id_code'])])
|
||||||
if not production_process_parameter:
|
if not production_process_parameter:
|
||||||
_logger.info('create可选参数:%s' % item)
|
|
||||||
self.create({
|
self.create({
|
||||||
"name": item['name'],
|
"name": item['name'],
|
||||||
"code": item['code'],
|
"code": item['code'],
|
||||||
@@ -1569,7 +1562,6 @@ class SfToolType(models.Model):
|
|||||||
r = r.json()
|
r = r.json()
|
||||||
result = json.loads(r['result'])
|
result = json.loads(r['result'])
|
||||||
if result['status'] == 1:
|
if result['status'] == 1:
|
||||||
_logger.info('result:%s' % result)
|
|
||||||
for item in result['mrs_cutting_tool_type_yesterday_list']:
|
for item in result['mrs_cutting_tool_type_yesterday_list']:
|
||||||
if item:
|
if item:
|
||||||
cutting_tool_type = self.search([("code", '=', item['code'])])
|
cutting_tool_type = self.search([("code", '=', item['code'])])
|
||||||
@@ -1604,7 +1596,6 @@ class SfToolType(models.Model):
|
|||||||
r = r.json()
|
r = r.json()
|
||||||
result = json.loads(r['result'])
|
result = json.loads(r['result'])
|
||||||
if result['status'] == 1:
|
if result['status'] == 1:
|
||||||
_logger.info('result:%s' % result)
|
|
||||||
for item in result['mrs_cutting_tool_type_all_list']:
|
for item in result['mrs_cutting_tool_type_all_list']:
|
||||||
if item:
|
if item:
|
||||||
cutting_tool_type = self.search([("code", '=', item['code'])])
|
cutting_tool_type = self.search([("code", '=', item['code'])])
|
||||||
@@ -1647,7 +1638,6 @@ class SfMaintenanceEquipmentImage(models.Model):
|
|||||||
r = r.json()
|
r = r.json()
|
||||||
result = json.loads(r['result'])
|
result = json.loads(r['result'])
|
||||||
if result['status'] == 1:
|
if result['status'] == 1:
|
||||||
_logger.info('result:%s' % result)
|
|
||||||
for item in result['ability_feature_library_yesterday_list']:
|
for item in result['ability_feature_library_yesterday_list']:
|
||||||
if item:
|
if item:
|
||||||
ability_feature_library = self.search([("name", '=', item['name'])])
|
ability_feature_library = self.search([("name", '=', item['name'])])
|
||||||
@@ -1678,7 +1668,6 @@ class SfMaintenanceEquipmentImage(models.Model):
|
|||||||
r = r.json()
|
r = r.json()
|
||||||
result = json.loads(r['result'])
|
result = json.loads(r['result'])
|
||||||
if result['status'] == 1:
|
if result['status'] == 1:
|
||||||
_logger.info('result:%s' % result)
|
|
||||||
for item in result['ability_feature_library_all_list']:
|
for item in result['ability_feature_library_all_list']:
|
||||||
if item:
|
if item:
|
||||||
ability_feature_library = self.search([("name", '=', item['name'])])
|
ability_feature_library = self.search([("name", '=', item['name'])])
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
from odoo.modules import get_resource_path
|
from odoo.modules import get_resource_path
|
||||||
from OCC.Extend.DataExchange import read_step_file
|
# from OCC.Extend.DataExchange import read_step_file
|
||||||
from OCC.Extend.DataExchange import write_stl_file
|
# from OCC.Extend.DataExchange import write_stl_file
|
||||||
from odoo.exceptions import ValidationError, UserError
|
from odoo.exceptions import ValidationError, UserError
|
||||||
from odoo.addons.sf_base.commons.common import Common
|
from odoo.addons.sf_base.commons.common import Common
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -89,10 +89,10 @@ class QuickEasyOrder(models.Model):
|
|||||||
|
|
||||||
# 将attach的datas内容转为glb文件
|
# 将attach的datas内容转为glb文件
|
||||||
def transition_glb_file(self, report_path, model_code):
|
def transition_glb_file(self, report_path, model_code):
|
||||||
shapes = read_step_file(report_path)
|
# shapes = read_step_file(report_path)
|
||||||
# output_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.stl')
|
# output_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.stl')
|
||||||
output_file = os.path.join('/tmp', str(model_code) + '.stl')
|
output_file = os.path.join('/tmp', str(model_code) + '.stl')
|
||||||
write_stl_file(shapes, output_file, 'binary', 0.03, 0.5)
|
# write_stl_file(shapes, output_file, 'binary', 0.03, 0.5)
|
||||||
# 转化为glb
|
# 转化为glb
|
||||||
# output_glb_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.glb')
|
# output_glb_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.glb')
|
||||||
output_glb_file = os.path.join('/tmp', str(model_code) + '.glb')
|
output_glb_file = os.path.join('/tmp', str(model_code) + '.glb')
|
||||||
|
|||||||
Reference in New Issue
Block a user