Files
jikimo_sf/sf_tool_management/models/tool_material_search.py

361 lines
19 KiB
Python

# -*- coding: utf-8 -*-
from odoo import fields, models, api, SUPERUSER_ID
# from odoo.exceptions import ValidationError
# 刀具物料搜索(待删除)
class SfToolMaterialSearch(models.Model):
_name = 'sf.tool.material.search'
_description = '刀具物料搜索'
sequence = fields.Integer('序号')
code = fields.Char('编码')
name = fields.Char('名称', required=True)
# 关联刀具类型
mrs_cutting_tool_type_id = fields.Many2one(
'sf.cutting.tool.type', '刀具类型',
domain="[('cutting_tool_material_id.name', '=', cutting_tool_material_name)]", required=True)
# 关联刀具物料名称
mrs_cutting_tool_material_name = fields.Char(related='mrs_cutting_tool_material_id.name', string='刀具物料名称',
store=True)
cutting_tool_type = fields.Char(related='mrs_cutting_tool_material_id.name', string='刀具物料类型', store=True)
mrs_machine_brand_id = fields.Many2one('sf.machine.brand', '品牌', required=True,
domain="[('tag_ids.name', 'ilike', '刀具')]")
# 关联刀具型号
# mrs_cutting_tool_model_id = fields.Many2one('sf.cutting.tool.model', '刀具型号')
# 关联刀具物料模型
mrs_cutting_tool_material_id = fields.Many2one('sf.cutting.tool.material', '刀具物料',
group_expand='_read_group_mrs_cutting_tool_material_ids',
required=True)
cutting_tool_material_name = fields.Char(string='物料名称', invisible=True)
@api.onchange('mrs_cutting_tool_material_id')
def _onchange_mrs_cutting_tool_material_id(self):
for record in self:
if record:
record.cutting_tool_material_name = record.mrs_cutting_tool_material_id.name
@api.model
def _read_group_mrs_cutting_tool_material_ids(self, categories, domain, order):
mrs_cutting_tool_material_ids = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
return categories.browse(mrs_cutting_tool_material_ids)
# 刀片特有字段
blade_code = fields.Char('刀片编码', readonly=True)
blade_length = fields.Float('刀片长度L(mm)')
blade_width = fields.Float('刀片宽度D(mm)')
blade_height = fields.Float('刀片高度T(mm)')
blade_top_angle = fields.Float('刀片顶角(°)')
blade_front_angle = fields.Float('刀片前角(°)')
blade_rear_angle = fields.Float('刀片后角(°)')
blade_main_included_angle = fields.Float('刀片主偏角(°)')
blade_r_angle = fields.Float('刀片R角(°)')
blade_hardness = fields.Integer('刀片加工硬度')
blade_accuracy = fields.Char('刀片精度等级')
blade_coating_material_id = fields.Char('刀片涂层材质')
blade_radius = fields.Float('刀片刀尖半径(mm)')
blade_nut = fields.Float('刀片配对螺母(mm)')
mrs_cutting_tool_model_blade_cutter_bar_ids = fields.Many2many(
'sf.cutting_tool.standard.library',
relation='sf_tool_material_search_blade_cutter_bar_rel',
column1='model_id_1',
column2='model_id_2',
domain="[('cutting_tool_type', '=', '刀杆')]",
string='适用刀杆型号',
default=lambda self: [], # 使用空列表作为默认值
)
mrs_cutting_tool_model_blade_cutter_pad_ids = fields.Many2many(
'sf.cutting_tool.standard.library',
relation='sf_tool_material_search_blade_cutter_pad_rel',
column1='model_id_1',
column2='model_id_2',
domain="[('cutting_tool_type', '=', '刀盘')]",
string='适用刀盘型号',
default=lambda self: [], # 使用空列表作为默认值
)
# 整体式刀具特有字段
integral_code = fields.Char('整体式刀具编码', readonly=True)
integral_total_length = fields.Float('整体式刀具总长度(mm)', digits=(6, 1))
integral_shank_length = fields.Float('整体式刀具柄部长度(mm)', digits=(6, 1))
integral_blade_length = fields.Float('整体式刀具刃部长度(mm)', digits=(6, 1))
integral_neck_length = fields.Float('整体式刀具颈部长度(mm)', digits=(6, 1))
integral_shank_diameter = fields.Float('整体式刀具柄部直径(mm)', digits=(6, 1))
integral_blade_diameter = fields.Float('整体式刀具刃部直径(mm)', digits=(6, 1))
integral_neck_diameter = fields.Float('整体式刀具颈部直径(mm)', digits=(6, 1))
integral_blade_number = fields.Integer('整体式刀具刃数(个)')
integral_blade_tip_diameter = fields.Float('整体式刀具刀尖直径(mm)', digits=(6, 1))
integral_blade_tip_taper = fields.Float('整体式刀具刀尖锥度(°)', digits=(6, 1))
integral_blade_helix_angle = fields.Float('整体式刀具刃部螺旋角(°)', digits=(6, 1))
integral_blade_type = fields.Char('整体式刀具刃部类型')
integral_coarse_medium_fine = fields.Selection([('', ''), ('', ''), ('', '')], '整体式刀具粗/中/精')
# integral_blade_material = fields.Selection([('碳素钢', '碳素钢'), ('硬质合金', '硬质合金')], '整体式刀具刀具材质')
integral_hardness = fields.Integer('整体式刀具硬度(HRC)')
integral_coating_material = fields.Char('整体式刀具涂层材质')
integral_run_out_accuracy_max = fields.Float('整体式刀具端跳精度max', digits=(6, 1))
integral_run_out_accuracy_min = fields.Float('整体式刀具端跳精度min', digits=(6, 1))
suitable_machining_method_ids = fields.Many2many('maintenance.equipment.image',
'rel_machining_product_template_material_search', '适合加工方式',
domain=[('type', '=', '加工能力')])
blade_tip_characteristics_id = fields.Many2one('maintenance.equipment.image', '刀尖特征',
domain=[('type', '=', '刀尖特征')])
handle_type_id = fields.Many2one('maintenance.equipment.image', '柄部类型', domain=[('type', '=', '柄部类型')])
cutting_direction_ids = fields.Many2many('maintenance.equipment.image',
'rel_cutting_product_template_material_search', '走刀方向',
domain=[('type', '=', '走刀方向')])
suitable_coolant_ids = fields.Many2many('maintenance.equipment.image',
'rel_coolants_product_template_material_search', '适合冷却方式',
domain=[('type', '=', '冷却方式')])
cutting_speed_ids = fields.Many2many('sf.cutting.speed', string='切削速度Vc')
feed_per_tooth_ids = fields.Many2many('sf.feed.per.tooth', 'rel_feed_per_tooth_ids', '每齿走刀量fz')
# @api.constrains('suitable_machining_method_ids')
# def _check_suitable_machining_method_ids(self):
# for record in self:
# if len(record.suitable_machining_method_ids) == 0 and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("适合加工方式不能为空!")
#
# @api.constrains('blade_tip_characteristics_ids')
# def _check_blade_tip_characteristics_ids(self):
# for record in self:
# if len(record.blade_tip_characteristics_ids) == 0 and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("刀尖特征不能为空!")
# if len(record.blade_tip_characteristics_ids) > 1 and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("刀尖特征只能单选!")
#
# @api.constrains('handle_type_ids')
# def _check_handle_type_ids(self):
# for record in self:
# if len(record.handle_type_ids) == 0 and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("柄部类型不能为空!")
# if len(record.handle_type_ids) > 1 and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("柄部类型只能单选!")
#
# @api.constrains('cutting_direction_ids')
# def _check_cutting_direction_ids(self):
# for record in self:
# if len(record.cutting_direction_ids) == 0 and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("走刀方向不能为空!")
#
# @api.constrains('suitable_coolant_ids')
# def _check_suitable_coolant_ids(self):
# for record in self:
# if not record.suitable_coolant_ids and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("适合冷却液不能为空!")
#
# @api.constrains('integral_total_length')
# def _check_integral_total_length(self):
# if self.integral_total_length <= 0 and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("总长度不能为0")
#
# @api.constrains('integral_shank_length')
# def _check_integral_shank_length(self):
# if self.integral_shank_length <= 0 and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("柄部长度不能为0")
#
# @api.constrains('integral_blade_length')
# def _check_integral_blade_length(self):
# if self.integral_blade_length <= 0 and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("刃部长度不能为0")
#
# @api.constrains('integral_blade_number')
# def _check_integral_blade_number(self):
# if self.integral_blade_number <= 0 and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("刃数不能为0")
#
# @api.constrains('integral_shank_diameter')
# def _check_integral_shank_diameter(self):
# if self.integral_shank_diameter <= 0 and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("柄部直径不能为0")
#
# @api.constrains('integral_blade_diameter')
# def _check_integral_blade_diameter(self):
# if self.integral_blade_diameter <= 0 and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("刃部直径不能为0")
#
# @api.constrains('integral_run_out_accuracy_min')
# def _check_integral_blade_diameter(self):
# if self.integral_run_out_accuracy_min <= 0 and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("端跳精度最小(min)不能为0")
#
# @api.constrains('integral_run_out_accuracy_max')
# def _check_integral_run_out_accuracy_max(self):
# if self.integral_run_out_accuracy_max <= 0 and self.cutting_tool_type == '整体式刀具':
# raise ValidationError("端跳精度最大(max)不能为0")
# integral_front_angle = fields.Float('整体式刀具前角(°)')
# integral_rear_angle = fields.Float('整体式刀具后角(°)')
# integral_main_included_angle = fields.Float('整体式刀具主偏角(°)')
# integral_accuracy = fields.Float('整体式刀具精度等级')
# integral_hardness = fields.Float('整体式刀具加工硬度(HRC)')
# integral_coating_material = fields.Char('整体式刀具涂层材质')
# integral_nut = fields.Float('整体式刀具配对螺母(mm)')
# integral_scope = fields.Char('整体式刀具适用范围')
# 刀杆特有字段
bar_code = fields.Char('刀杆编码', readonly=True)
# bar_name = fields.Char('刀杆名称', required=True)
bar_c_diameter = fields.Float('刀杆C柄径(mm)')
bar_total_length = fields.Float('刀杆L总长(mm)')
bar_blade_number = fields.Integer('刀杆刃数')
bar_d_diameter = fields.Float('刀杆D刃径(mm)')
mrs_cutting_tool_model_bar_blade_ids = fields.Many2many(
'sf.cutting_tool.standard.library',
relation='sf_tool_material_search_bar_blade_rel',
column1='model_id_1',
column2='model_id_2',
domain="[('cutting_tool_type', '=', '刀片')]",
string='刀杆适用刀片型号'
)
bar_wrench = fields.Float('刀杆配对扳手(mm)')
bar_screw = fields.Float('刀杆配备螺丝(mm)')
bar_radius = fields.Float('刀杆刀尖圆角半径')
bar_accuracy = fields.Char('刀杆精度等级')
bar_hardness = fields.Integer('刀杆硬度(°)')
bar_scope = fields.Char('刀杆适用范围')
# 刀盘特有字段
pad_code = fields.Char('刀盘编码', readonly=True)
# pad_name = fields.Char('刀盘名称', required=True)
pad_c_diameter = fields.Float('刀盘C柄径(mm)')
pad_total_length = fields.Float('刀盘L总长(mm)')
pad_blade_number = fields.Integer('刀盘刃数')
pad_d_diameter = fields.Float('刀盘D刃径(mm)')
mrs_cutting_tool_model_pad_blade_ids = fields.Many2many(
'sf.cutting_tool.standard.library',
relation='sf_tool_material_search_pad_blade_rel',
column1='model_id_1',
column2='model_id_2',
domain="[('cutting_tool_type', '=', '刀片')]",
string='刀盘适用刀片型号'
)
pad_wrench = fields.Float('刀盘配对扳手(mm)')
pad_screw = fields.Float('刀盘配备螺丝(mm)')
pad_radius = fields.Float('刀盘刀尖圆角半径')
pad_accuracy = fields.Char('刀盘精度等级')
pad_hardness = fields.Integer('刀盘硬度(°)')
pad_scope = fields.Char('刀盘适用范围')
# 刀柄特有字段
handle_code = fields.Char('刀柄编码', readonly=True)
# 柄长L(mm)、法兰柄长L1(mm)、法兰直径D1(mm)
handle_length = fields.Float('刀柄柄长L(mm)')
handle_diameter = fields.Float('刀柄直径D(mm)')
handle_flange_length = fields.Float('刀柄法兰柄长L1(mm)')
handle_flange_diameter = fields.Float('刀柄法兰直径D1(mm)')
# 夹持直径min、夹持直径max、径跳精度、最大转速n/min、3D模型图
handle_clamping_diameter_min = fields.Float('刀柄夹持直径min')
handle_clamping_diameter_max = fields.Float('刀柄夹持直径max')
handle_jump_accuracy = fields.Float('刀柄径跳精度')
handle_max_speed = fields.Float('刀柄最大转速n/min')
handle_weight = fields.Float('刀柄重量(kg)')
handle_body_accuracy = fields.Float('刀柄本体精度(mm)')
handle_nut = fields.Float('刀柄配对螺母(mm)')
mrs_cutting_tool_model_handle_chuck_model_ids = fields.Many2many(
'sf.cutting_tool.standard.library',
relation='sf_tool_material_search_handle_chuck_rel',
column1='model_id_1',
column2='model_id_2',
domain="[('cutting_tool_type', '=', '夹头')]",
string='适用夹头型号'
)
handle_clamping_range = fields.Float('刀柄夹持范围(mm)')
handle_detection_accuracy = fields.Float('刀柄检测精度')
handle_detection_hardness = fields.Integer('刀柄检测硬度')
handle_standard_speed = fields.Float('刀柄标准转速')
# 夹头特有字段
chuck_code = fields.Char('夹头编码', readonly=True)
# chuck_name = fields.Char('夹头名称', required=True)
chuck_accuracy = fields.Float('夹头精度(mm)')
# 夹持直径min、夹持直径max、3D模型图
chuck_clamping_diameter_min = fields.Float('夹头夹持直径min(mm)')
chuck_clamping_diameter_max = fields.Float('夹头夹持直径max(mm)')
chuck_diameter = fields.Float('夹头外径(mm)')
chuck_inner_diameter = fields.Float('夹头内径(mm)')
chuck_height = fields.Float('夹头高度(mm)')
chuck_nut = fields.Float('夹头配对螺母(mm)')
mrs_cutting_tool_model_chuck_handle_model_ids = fields.Many2many(
'sf.cutting_tool.standard.library',
relation='sf_tool_material_search_chuck_handle_rel',
column1='model_id_1',
column2='model_id_2',
domain="[('cutting_tool_type', '=', '刀柄')]",
string='适用刀柄型号'
)
chuck_clamping_range = fields.Float('夹头夹持范围(mm)')
chuck_feature = fields.Char('夹头特性')
image = fields.Binary('夹头图片')
# 数量、采购入库日期、采购批次、供应商、仓库名称、库区、库位、3D模型
number = fields.Integer('数量')
mrs_materials_model_id = fields.Many2one('sf.materials.model', '材料型号')
purchase_date = fields.Date('采购入库日期')
purchase_batch = fields.Char('采购批次')
supplier = fields.Char('供应商')
warehouse_name = fields.Char('仓库名称')
warehouse_area = fields.Char('库区')
warehouse_location = fields.Char('库位')
three_d_model = fields.Many2one('ir.attachment', '3D模型')
class ToolMaterial(models.Model):
_name = 'sf.tool.material.search'
_description = '刀具物料搜索'
product_id = fields.Many2one('product.product', string='刀具物料产品')
name = fields.Char('名称', related='product_id.name')
code = fields.Char('编码')
cutting_tool_material_id = fields.Many2one('sf.cutting.tool.material', '刀具物料',
related='product_id.cutting_tool_material_id',
store=True,
group_expand='_read_group_cutting_tool_material_id')
tool_material_name = fields.Char('物料名称', related='product_id.cutting_tool_material_id.name')
cutting_tool_standard_library_id = fields.Many2one('sf.cutting_tool.standard.library', '刀具型号',
related='product_id.cutting_tool_model_id')
specification_id = fields.Many2one('sf.tool.materials.basic.parameters', '规格',
related='product_id.specification_id')
image = fields.Binary('图片', related='product_id.image_1920')
number = fields.Integer('总数量', compute='_compute_number')
usable_num = fields.Integer('可用数量', compute='_compute_number')
have_been_used_num = fields.Integer('在用数量', compute='_compute_number')
scrap_num = fields.Integer('报废数量', compute='_compute_number')
barcode_ids = fields.One2many('stock.lot', 'tool_material_search_id', string='序列号', readonly=True)
active = fields.Boolean(string='已归档', default=True)
@api.depends('barcode_ids')
def _compute_number(self):
for record in self:
usable_num = 0
have_been_used_num = 0
scrap_num = 0
if record.barcode_ids:
record.number = len(record.barcode_ids)
for barcode_id in record.barcode_ids:
if barcode_id.quant_ids:
if barcode_id.quant_ids[-1].location_id.name == '刀具组装位置':
have_been_used_num = have_been_used_num + 1
else:
usable_num = usable_num + 1
record.usable_num = usable_num
record.have_been_used_num = have_been_used_num
record.scrap_num = scrap_num
else:
record.number = 0
record.usable_num = 0
record.have_been_used_num = 0
record.scrap_num = 0
@api.model
def _read_group_cutting_tool_material_id(self, categories, domain, order):
cutting_tool_material_id = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
return categories.browse(cutting_tool_material_id)