整合所有模块依赖

This commit is contained in:
jinling.yang
2023-11-08 17:13:18 +08:00
parent 3be0d1ffad
commit 3a1acb0f5a
19 changed files with 923 additions and 1208 deletions

View File

@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
from odoo.modules import get_resource_path
from odoo.addons.sf_base.commons.common import Common
from OCC.Extend.DataExchange import read_step_file
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 base64
import hashlib
@@ -14,22 +15,9 @@ import json
class ResProductMo(models.Model):
_inherit = 'product.template'
model_file = fields.Binary('模型文件')
# categ_type = fields.Selection(
# [("成品", "成品"), ("坯料", "坯料"), ("原材料", "原材料"), ("表面工艺", "表面工艺"), ("刀具", "刀具"),
# ("夹具", "夹具")],
# string='产品的类别', compute='_compute_categ_id',
# store=True)
#
# @api.depends('categ_id')
# def _compute_categ_id(self):
# for record in self:
# if record:
# record.categ_type = record.categ_id.type
categ_type = fields.Selection(string='产品的类别', related='categ_id.type', store=True)
model_name = fields.Char('模型名称')
model_long = fields.Float('模型长(mm)', digits=(16, 3))
model_width = fields.Float('模型宽(mm)', digits=(16, 3))
@@ -46,10 +34,11 @@ class ResProductMo(models.Model):
length = fields.Float('长(mm)', digits=(16, 3))
width = fields.Float('宽(mm)', digits=(16, 3))
height = fields.Float('高(mm)', digits=(16, 3))
single_manufacturing = fields.Boolean(string="单个制造")
# single_manufacturing = fields.Boolean(string="单个制造")
model_code = fields.Char('模型编码')
is_bfm = fields.Boolean('业务平台是否自动创建', default=False)
upload_model_file = fields.Many2many('ir.attachment', 'upload_model_file_attachment_ref', string='上传模型文件')
model_file = fields.Binary('模型文件')
product_model_type_id = fields.Many2one('sf.model.type', string='产品模型类型')
embryo_model_type_id = fields.Many2one('sf.model.type', string='坯料模型类型')
materials_id = fields.Many2one('sf.production.materials', string='材料')
@@ -81,7 +70,7 @@ class ResProductMo(models.Model):
# 整体式刀具特有字段
cutting_tool_total_length = fields.Float('总长度(mm)', digits=(6, 1))
cutting_tool_shank_length = fields.Float('柄部长度(mm)', digits=(6, 1))
cutting_tool_blade_length = fields.Char('刃部长度(mm)')
cutting_tool_blade_length = fields.Float('刃部长度(mm)')
cutting_tool_blade_number = fields.Selection(
[('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8')], '刃数(个)')
# 整体式刀具新增字段
@@ -92,23 +81,23 @@ class ResProductMo(models.Model):
cutting_tool_blade_tip_taper = fields.Integer('刀尖锥度(°)')
cutting_tool_blade_helix_angle = fields.Integer('刃部螺旋角(°)')
cutting_tool_blade_type = fields.Char('刃部类型')
cutting_tool_pitch = fields.Char('牙距(mm)', size=20)
cutting_tool_blade_width = fields.Char('刃部宽度(mm)', size=20)
cutting_tool_blade_depth = fields.Char('刃部深度(mm)', size=20)
cutting_tool_cut_depth = fields.Char('切削深度(mm)', size=20)
cutting_tool_cut_depth_max = fields.Char('最大切削深度(mm)', size=20)
cutting_tool_pitch = fields.Float('牙距(mm)')
cutting_tool_blade_width = fields.Float('刃部宽度(mm)')
cutting_tool_blade_depth = fields.Float('刃部深度(mm)')
cutting_tool_cut_depth = fields.Float('切削深度(mm)')
cutting_tool_cut_depth_max = fields.Float('最大切削深度(mm)')
cutting_tool_coarse_medium_fine = fields.Selection([('', ''), ('', ''), ('', '')], '粗/中/精')
cutting_tool_run_out_accuracy_max = fields.Float('端跳精度max', digits=(6, 1))
cutting_tool_run_out_accuracy_min = fields.Float('端跳精度min', digits=(6, 1))
cutting_tool_blade_tip_working_size = fields.Char('刀尖处理尺寸(R半径mm/倒角)', size=20)
fit_blade_shape_id = fields.Many2many('maintenance.equipment.image', 'rel_fit_blade_shape_product_template',
'适配刀片形状', domain=[('type', '=', '刀片形状')])
'适配刀片形状', domain=[('type', '=', '刀片形状')])
suitable_machining_method_ids = fields.Many2many('maintenance.equipment.image',
'rel_machining_product_template', '适合加工方式',
domain=[('type', '=', '加工能力')])
blade_tip_characteristics_id = fields.Many2many('maintenance.equipment.image',
'rel_blade_tip_product_template', '刀尖特征',
domain=[('type', '=', '刀尖特征')])
'rel_blade_tip_product_template', '刀尖特征',
domain=[('type', '=', '刀尖特征')])
handle_type_ids = fields.Many2many('maintenance.equipment.image', 'rel_handle_product_template', '柄部类型',
domain=[('type', '=', '柄部类型')])
cutting_direction_ids = fields.Many2many('maintenance.equipment.image', 'rel_cutting_product_template',
@@ -116,7 +105,7 @@ class ResProductMo(models.Model):
suitable_coolant_ids = fields.Many2many('maintenance.equipment.image', 'rel_coolant_product_template',
'适合冷却液', domain=[('type', '=', '冷却液')])
compaction_way_ids = fields.Many2many('maintenance.equipment.image', 'rel_compaction_product_template',
'压紧方式', domain=[('type', '=', '压紧方式')]) \
'压紧方式', domain=[('type', '=', '压紧方式')])
@api.onchange('cutting_tool_material_id')
def _onchange_cutting_tool_material_id(self):
@@ -162,29 +151,29 @@ class ResProductMo(models.Model):
item.cutting_speed_ids = False
item.feed_per_tooth_ids = False
# def choice(self):
# if self.cutting_tool_type == '整体式刀具':
# tree_view = self.env.ref('sf_base.view_sf_tool_materials_basic_parameters_integral_tree')
# elif self.cutting_tool_type == '刀片':
# tree_view = self.env.ref('sf_base.view_sf_tool_materials_basic_parameters_blade_tree')
# elif self.cutting_tool_type == '刀杆':
# tree_view = self.env.ref('sf_base.view_sf_tool_materials_basic_parameters_cutter_bar_tree')
# elif self.cutting_tool_type == '刀盘':
# tree_view = self.env.ref('sf_base.view_sf_tool_materials_basic_parameters_tree')
# elif self.cutting_tool_type == '刀柄':
# tree_view = self.env.ref('sf_base.view_sf_tool_materials_basic_parameters_tree')
# else :
# tree_view = self.env.ref('sf_base.view_sf_tool_materials_basic_parameters_tree')
# return {
# 'name': _('规格'),
# 'view_mode': 'list',
# 'view_id': tree_view.id,
# 'type': 'ir.actions.act_window',
# 'res_model': 'sf.tool.materials.basic.parameters',
# 'target': 'new',
# 'domain': [('cutting_tool_type', '=', self.cutting_tool_type),
# ('standard_library_id', '=', self.cutting_tool_model_id.id)],
# }
def choice(self):
if self.cutting_tool_type == '整体式刀具':
tree_view = self.env.ref('sf_base.view_sf_tool_materials_basic_parameters_integral_tree')
elif self.cutting_tool_type == '刀片':
tree_view = self.env.ref('sf_base.view_sf_tool_materials_basic_parameters_blade_tree')
elif self.cutting_tool_type == '刀杆':
tree_view = self.env.ref('sf_base.view_sf_tool_materials_basic_parameters_cutter_bar_tree')
elif self.cutting_tool_type == '刀盘':
tree_view = self.env.ref('sf_base.view_sf_tool_materials_basic_parameters_tree')
elif self.cutting_tool_type == '刀柄':
tree_view = self.env.ref('sf_base.view_sf_tool_materials_basic_parameters_tree')
else:
tree_view = self.env.ref('sf_base.view_sf_tool_materials_basic_parameters_tree')
return {
'name': _('规格'),
'view_mode': 'list',
'view_id': tree_view.id,
'type': 'ir.actions.act_window',
'res_model': 'sf.tool.materials.basic.parameters',
'target': 'new',
'domain': [('cutting_tool_type', '=', self.cutting_tool_type),
('standard_library_id', '=', self.cutting_tool_model_id.id)],
}
@api.onchange('specification_id')
def _onchange_specification(self):
@@ -307,7 +296,7 @@ class ResProductMo(models.Model):
[])] if not self.cutting_tool_model_id.suitable_machining_method_ids else [
(6, 0, self.cutting_tool_model_id.suitable_machining_method_ids.ids)]
self.blade_tip_characteristics_id = [(6, 0,
[])] if not self.cutting_tool_model_id.blade_tip_characteristics_id else [
[])] if not self.cutting_tool_model_id.blade_tip_characteristics_id else [
(6, 0, self.cutting_tool_model_id.blade_tip_characteristics_id.ids)]
self.handle_type_ids = [(6, 0,
@@ -325,7 +314,6 @@ class ResProductMo(models.Model):
[])] if not self.cutting_tool_model_id.compaction_way_ids else [
(6, 0, self.cutting_tool_model_id.compaction_way_ids.ids)]
# @api.constrains('suitable_machining_method_ids')
# def _check_suitable_machining_method_ids(self):
# for record in self:
@@ -410,10 +398,8 @@ class ResProductMo(models.Model):
# raise ValidationError("端跳精度最大(max)不能为0")
cutting_tool_diameter = fields.Float('直径(mm)')
cutting_tool_front_angle = fields.Integer('前角(°)')
cutting_tool_rear_angle = fields.Integer('后角(°)')
cutting_tool_main_included_angle = fields.Integer('主偏角(°)')
# cutting_tool_material_model_id = fields.Many2one('sf.materials.model', '材料型号')
# 适用夹头型号可以多选
cutting_tool_chuck_ids = fields.Many2many(
'sf.cutting_tool.standard.library',
@@ -423,11 +409,11 @@ class ResProductMo(models.Model):
domain="[('cutting_tool_type', '=', '夹头')]",
string='适用夹头型号')
# 刀片参数
cutting_tool_cut_blade_length = fields.Char('切削刃长(mm)', size=20)
cutting_tool_cut_blade_length = fields.Float('切削刃长(mm)')
cutting_tool_blade_tip_circular_arc_radius = fields.Char('刀尖圆弧半径(mm)', size=20)
cutting_tool_top_angle = fields.Integer('顶角(°)')
cutting_tool_inscribed_circle_diameter = fields.Char('内接圆直径(mm)', size=20)
cutting_tool_install_aperture_diameter = fields.Char('安装孔直径(mm)', size=20)
cutting_tool_inscribed_circle_diameter = fields.Float('内接圆直径(mm)')
cutting_tool_install_aperture_diameter = fields.Float('安装孔直径(mm)')
cutting_tool_chip_breaker_groove = fields.Selection([('', ''), ('单面', '单面'), ('双面', '双面')],
string='有无断屑槽')
cutting_tool_bladed_teeth_model = fields.Selection(
@@ -445,7 +431,7 @@ class ResProductMo(models.Model):
cutting_tool_side_cutting_edge_angle = fields.Integer('侧切削角(°)')
cutting_tool_thread_model = fields.Selection([('', ''), ('外螺纹', '外螺纹'), ('内螺纹', '内螺纹')],
string='螺纹类型')
cutting_tool_thread_num = fields.Char('每英寸螺纹数(tpi)', size=20)
cutting_tool_thread_num = fields.Float('每英寸螺纹数(tpi)')
cutting_tool_blade_tip_height_tolerance = fields.Char('刀尖高度公差(mm)', size=20)
cutting_tool_inscribed_circle_tolerance = fields.Char('内接圆公差(mm)', size=20)
cutting_tool_thickness_tolerance = fields.Char('厚度公差(mm)', size=20)
@@ -473,9 +459,9 @@ class ResProductMo(models.Model):
cutting_tool_knife_head_width = fields.Float('刀头宽度(mm)')
cutting_tool_knife_head_length = fields.Float('刀头长度(mm)')
cutting_tool_blade_diameter = fields.Float('刃径/刃部直径(mm)')
cutting_tool_cutter_arbor_diameter = fields.Char('刀杆直径(mm)', size=20)
cutting_tool_min_machining_aperture = fields.Char('最小加工孔径(mm)', size=20)
cutting_tool_install_blade_tip_num = fields.Char('可装刀片数/齿数(个)', size=20)
cutting_tool_cutter_arbor_diameter = fields.Float('刀杆直径(mm)')
cutting_tool_min_machining_aperture = fields.Integer('最小加工孔径(mm)')
cutting_tool_install_blade_tip_num = fields.Integer('可装刀片数/齿数(个)', size=20)
cutting_tool_installing_structure = fields.Char('安装结构', size=20)
cutting_tool_blade_ids = fields.Many2many(
'sf.cutting_tool.standard.library',
@@ -493,8 +479,8 @@ class ResProductMo(models.Model):
cutting_tool_is_cooling_hole = fields.Boolean('有无冷却孔', default=False)
cutting_tool_locating_slot_code = fields.Char('定位槽代号', size=20)
# 刀盘参数
cutting_tool_cutter_head_diameter = fields.Char('刀盘直径(mm)', size=20)
cutting_tool_interface_diameter = fields.Char('接口直径(mm)', size=20)
cutting_tool_cutter_head_diameter = fields.Float('刀盘直径(mm)')
cutting_tool_interface_diameter = fields.Float('接口直径(mm)')
# 刀柄参数
cutting_tool_shank_outer_diameter = fields.Float('柄部外径(mm)')
@@ -512,7 +498,7 @@ class ResProductMo(models.Model):
cutting_tool_is_high_speed_cutting = fields.Boolean('可高速切削', default=False)
cutting_tool_change_time = fields.Integer('换刀时间(s)')
cutting_tool_clamping_way = fields.Char('夹持方式')
cutting_tool_standard_speed = fields.Char('标准转速(n/min)')
cutting_tool_standard_speed = fields.Integer('标准转速(n/min)')
cutting_tool_speed_max = fields.Integer('最大转速(n/min)')
cutting_tool_cooling_type = fields.Char('冷却类型')
# 夹头参数
@@ -521,7 +507,7 @@ class ResProductMo(models.Model):
cutting_tool_outer_diameter = fields.Float('外径(mm)')
cutting_tool_inner_diameter = fields.Float('内径(mm)')
cooling_suit_type_ids = fields.Char('适用冷却套型号')
cutting_tool_max_load_capacity = fields.Char('最大负载能力(kg)')
cutting_tool_max_load_capacity = fields.Float('最大负载能力(kg)')
cutting_tool_er_size_model = fields.Char('ER尺寸型号')
cutting_tool_handle_ids = fields.Many2many(
'sf.cutting_tool.standard.library',
@@ -696,7 +682,6 @@ class ResProductMo(models.Model):
item.fixture_apply_machine_tool_type_ids = self._get_ids(
item.fixture_model_id.apply_machine_tool_type_ids)
def _get_volume_uom_id_from_ir_config_parameter(self):
product_length_in_feet_param = self.env['ir.config_parameter'].sudo().get_param('product.volume_in_cubic_feet')
if product_length_in_feet_param == '1':
@@ -888,95 +873,10 @@ class ResProductMo(models.Model):
return base64_data
class ResMrpBomMo(models.Model):
_inherit = 'mrp.bom'
subcontractor_id = fields.Many2one('res.partner', string='外包商')
def bom_create_line_has(self, embryo):
vals = {
'bom_id': self.id,
'product_id': embryo.id,
'product_tmpl_id': embryo.product_tmpl_id.id,
'product_qty': 1,
'product_uom_id': 1
}
return self.env['mrp.bom.line'].create(vals)
# 业务平台分配工厂后在智能工厂先创建销售订单再创建该产品后再次进行创建bom
def bom_create(self, product, bom_type, product_type):
bom_id = self.env['mrp.bom'].create({
'product_tmpl_id': product.product_tmpl_id.id,
'type': bom_type,
# 'subcontractor_id': '' or subcontract.partner_id.id,
'product_qty': 1,
'product_uom_id': 1
})
if bom_type == 'subcontract' and product_type is not False:
subcontract = self.get_supplier(product.materials_type_id)
bom_id.subcontractor_id = subcontract.partner_id.id
return bom_id
# 坯料BOM组件选取当前坯料原材料
# 然后根据当前的坯料的体积得出需要的原材料重量立方米m³ *材料密度 * 1000 = 所需原材料重量KG公斤
# 坯料所需原材料公式当前的坯料的体积立方米m³ *材料密度 * 1000 = 所需原材料重量KG公斤
def bom_create_line(self, embryo):
# 选取当前坯料原材料
raw_bom_line = self.get_raw_bom(embryo)
if raw_bom_line:
qty = 1
if round(embryo.volume * raw_bom_line.materials_type_id.density / 1000000) > 1:
qty = round(embryo.volume * raw_bom_line.materials_type_id.density / 1000000)
bom_line = self.env['mrp.bom.line'].create({
'bom_id': self.id,
'product_id': raw_bom_line.id,
'product_tmpl_id': raw_bom_line.product_tmpl_id.id,
'product_qty': qty,
'product_uom_id': raw_bom_line.uom_id.id,
})
return bom_line
else:
return False
# 查询材料型号默认排第一的供应商
def get_supplier(self, materials_type):
seller_id = self.env['sf.supplier.sort'].search(
[('materials_model_id', '=', materials_type.id)],
limit=1,
order='sequence asc')
return seller_id
# 匹配bom
def get_bom(self, product):
embryo_has = self.env['product.product'].search(
[('categ_id.type', '=', '坯料'), ('materials_type_id', '=', product.materials_type_id.id),
('length', '>', product.length), ('width', '>', product.width),
('height', '>', product.height), ('is_bfm', '=', False)
],
limit=1,
order='volume desc'
)
logging.info('get_bom-vals:%s' % embryo_has)
if embryo_has:
rate_of_waste = ((embryo_has.volume - product.model_volume) % embryo_has.volume) * 100
if rate_of_waste <= 20:
return embryo_has
else:
return
# 查bom的原材料
def get_raw_bom(self, product):
raw_bom = self.env['product.product'].search(
[('categ_id.type', '=', '原材料'), ('materials_type_id', '=', product.materials_type_id.id)])
return raw_bom
class SfMaintenanceEquipmentAndProductTemplate(models.Model):
_inherit = 'maintenance.equipment'
_description = '设备'
product_template_ids = fields.One2many('maintenance.equipment.tool', 'equipment_id', string='机床刀位')
@api.model_create_multi
@@ -999,8 +899,7 @@ class SfMaintenanceEquipmentTool(models.Model):
_description = '机床刀位'
equipment_id = fields.Many2one('maintenance.equipment', string='设备')
product_template_id = fields.Many2one('product.template', string='功能刀具名称',
domain="[('categ_type', '=', '刀具')]")
product_template_id = fields.Many2one('product.template', string='功能刀具名称', domain="[('categ_type', '=', '刀具')]")
image_1920 = fields.Binary('图片', related='product_template_id.image_1920')
categ_type = fields.Char(string='功能刀具类型')
diameter = fields.Char('直径')
@@ -1012,3 +911,5 @@ class SfMaintenanceEquipmentTool(models.Model):
alarm_value = fields.Char('报警值')
used_value = fields.Char('已使用值')
code = fields.Char('机床刀位号')