979 lines
57 KiB
Python
979 lines
57 KiB
Python
# -*- coding: utf-8 -*-
|
||
import re
|
||
import json
|
||
import requests
|
||
from datetime import timedelta
|
||
from odoo import SUPERUSER_ID
|
||
from odoo import fields, models, api
|
||
from odoo.exceptions import ValidationError
|
||
from odoo.addons.sf_base.commons.common import Common
|
||
|
||
|
||
class FunctionalCuttingToolEntity(models.Model):
|
||
_name = 'sf.functional.cutting.tool.entity'
|
||
_description = '功能刀具列表'
|
||
|
||
tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组', related='functional_tool_name_id.tool_groups_id')
|
||
code = fields.Char('编码', related='functional_tool_name_id.code')
|
||
name = fields.Char(related='functional_tool_name_id.name')
|
||
functional_tool_name_id = fields.Many2one('sf.functional.tool.assembly', string='功能刀具名称', readonly=True)
|
||
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号', readonly=True)
|
||
sf_cutting_tool_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀具型号')
|
||
sf_cutting_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型',
|
||
group_expand='_read_group_mrs_cutting_tool_type_id', compute_sudo=True)
|
||
|
||
functional_tool_diameter = fields.Integer(string='刀具直径(mm)', readonly=True)
|
||
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)', readonly=True)
|
||
coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')], string='粗/中/精', readonly=True)
|
||
new_former = fields.Selection([('0', '新'), ('1', '旧')], string='新/旧', readonly=True)
|
||
tool_loading_length = fields.Float(string='总长度(mm)', readonly=True)
|
||
functional_tool_length = fields.Float(string='伸出长(mm)', readonly=True)
|
||
effective_length = fields.Float(string='有效长(mm)', readonly=True)
|
||
tool_room_num = fields.Integer(string='刀具房数量', readonly=True)
|
||
line_edge_knife_library_num = fields.Integer(string='线边刀库数量', readonly=True)
|
||
machine_knife_library_num = fields.Integer(string='机内刀库数量', readonly=True)
|
||
max_lifetime_value = fields.Integer(string='最大寿命值(min)', readonly=True)
|
||
alarm_value = fields.Integer(string='报警值(min)', readonly=True)
|
||
used_value = fields.Integer(string='已使用值(min)', readonly=True)
|
||
functional_tool_status = fields.Selection([('正常', '正常'), ('报警', '报警'), ('已拆除', '已拆除')],
|
||
string='状态', store=True, default='正常')
|
||
current_location_id = fields.Many2one('stock.location', string='当前位置', readonly=True)
|
||
current_location = fields.Char('位置', compute='_compute_current_location_id')
|
||
image = fields.Binary('图片', readonly=True)
|
||
|
||
@api.depends('barcode_id')
|
||
def _compute_current_location_id(self):
|
||
for record in self:
|
||
if record.barcode_id.quant_ids:
|
||
for quant_id in record.barcode_id.quant_ids:
|
||
if quant_id.inventory_quantity_auto_apply > 0:
|
||
record.sudo().current_location_id = quant_id.location_id
|
||
record.sudo().current_location = quant_id.location_id.name
|
||
if record.current_location_id:
|
||
record.sudo().get_location_num()
|
||
else:
|
||
record.sudo().current_location_id = False
|
||
record.sudo().current_location = False
|
||
|
||
def get_location_num(self):
|
||
"""
|
||
计算库存位置数量
|
||
"""
|
||
for obj in self:
|
||
if obj.current_location_id:
|
||
if obj.current_location_id.name in ['刀具房']:
|
||
obj.tool_room_num = 1
|
||
obj.line_edge_knife_library_num = 0
|
||
obj.machine_knife_library_num = 0
|
||
elif "线边刀库" in obj.current_location_id.name:
|
||
obj.tool_room_num = 0
|
||
obj.line_edge_knife_library_num = 1
|
||
obj.machine_knife_library_num = 0
|
||
elif "机内刀库" in obj.current_location_id.name:
|
||
obj.tool_room_num = 0
|
||
obj.line_edge_knife_library_num = 0
|
||
obj.machine_knife_library_num = 1
|
||
else:
|
||
obj.tool_room_num = 0
|
||
obj.line_edge_knife_library_num = 0
|
||
obj.machine_knife_library_num = 0
|
||
|
||
@api.model
|
||
def _read_group_mrs_cutting_tool_type_id(self, categories, domain, order):
|
||
mrs_cutting_tool_type_ids = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
|
||
return categories.browse(mrs_cutting_tool_type_ids)
|
||
|
||
# 整体式刀具型号
|
||
cutting_tool_integral_model_id = fields.Many2one('product.product', string='整体式刀具型号', readonly=True,
|
||
domain=[('cutting_tool_material_id', '=', '整体式刀具')])
|
||
# 刀片型号
|
||
cutting_tool_blade_model_id = fields.Many2one('product.product', string='刀片型号', readonly=True,
|
||
domain=[('cutting_tool_material_id', '=', '刀片')])
|
||
# 刀杆型号
|
||
cutting_tool_cutterbar_model_id = fields.Many2one('product.product', string='刀杆型号', readonly=True,
|
||
domain=[('cutting_tool_material_id', '=', '刀杆')])
|
||
# 刀盘型号
|
||
cutting_tool_cutterpad_model_id = fields.Many2one('product.product', string='刀盘型号', readonly=True,
|
||
domain=[('cutting_tool_material_id', '=', '刀盘')])
|
||
# 刀柄型号
|
||
cutting_tool_cutterhandle_model_id = fields.Many2one('product.product', string='刀柄型号', readonly=True,
|
||
domain=[('cutting_tool_material_id', '=', '刀柄')])
|
||
# 夹头型号
|
||
cutting_tool_cutterhead_model_id = fields.Many2one('product.product', string='夹头型号', readonly=True,
|
||
domain=[('cutting_tool_material_id', '=', '夹头')])
|
||
|
||
whether_standard_knife = fields.Boolean(string='是否标准刀', default=True, readonly=True)
|
||
L_D_number = fields.Float(string='L/D值(mm)', readonly=True)
|
||
hiding_length = fields.Float(string='避空长(mm)', readonly=True)
|
||
cut_time = fields.Integer(string='已切削时间(min)', readonly=True)
|
||
cut_length = fields.Float(string='已切削长度(mm)', readonly=True)
|
||
cut_number = fields.Integer(string='已切削次数', readonly=True)
|
||
|
||
suitable_machining_method_ids = fields.Many2many(
|
||
'maintenance.equipment.image', 'rel_machining_product_template_tool_entity', '适合加工方式',
|
||
domain=[('type', '=', '加工能力')], compute='_compute_maintenance_equipment_image')
|
||
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_tool_entity', '走刀方向',
|
||
domain=[('type', '=', '走刀方向')])
|
||
suitable_coolant_ids = fields.Many2many(
|
||
'maintenance.equipment.image', 'rel_coolants_product_template_tool_entity', '适合冷却方式',
|
||
domain=[('type', '=', '冷却方式')])
|
||
|
||
@api.depends('cutting_tool_integral_model_id', 'cutting_tool_blade_model_id')
|
||
def _compute_maintenance_equipment_image(self):
|
||
for record in self:
|
||
print('111')
|
||
if record.cutting_tool_integral_model_id:
|
||
print(record.cutting_tool_integral_model_id)
|
||
record.sudo().suitable_machining_method_ids = record.cutting_tool_integral_model_id.suitable_machining_method_ids.ids
|
||
record.sudo().blade_tip_characteristics_id = record.cutting_tool_integral_model_id.blade_tip_characteristics_id.id
|
||
record.sudo().handle_type_id = record.cutting_tool_integral_model_id.handle_type_id.id
|
||
record.sudo().cutting_direction_ids = record.cutting_tool_integral_model_id.cutting_direction_ids.ids
|
||
record.sudo().suitable_coolant_ids = record.cutting_tool_integral_model_id.suitable_coolant_ids.ids
|
||
print(record.cutting_tool_integral_model_id.blade_tip_characteristics_id.ids)
|
||
elif record.cutting_tool_blade_model_id:
|
||
record.sudo().suitable_machining_method_ids = record.cutting_tool_blade_model_id.suitable_machining_method_ids.ids
|
||
record.sudo().blade_tip_characteristics_id = record.cutting_tool_blade_model_id.blade_tip_characteristics_id.id
|
||
record.sudo().handle_type_id = record.cutting_tool_blade_model_id.handle_type_id.id
|
||
record.sudo().cutting_direction_ids = record.cutting_tool_blade_model_id.cutting_direction_ids.ids
|
||
record.sudo().suitable_coolant_ids = record.cutting_tool_blade_model_id.suitable_coolant_ids.ids
|
||
else:
|
||
record.sudo().suitable_machining_method_ids = []
|
||
record.sudo().blade_tip_characteristics_id = None
|
||
record.sudo().handle_type_id = None
|
||
record.sudo().cutting_direction_ids = []
|
||
record.sudo().suitable_coolant_ids = []
|
||
|
||
def _get_functional_tool_model_ids(self, functional_tool_model_code):
|
||
functional_tool_model_ids = []
|
||
for item in functional_tool_model_code:
|
||
functional_tool_model = self.env['sf.cutting_tool.standard.library'].search([('code', '=', item)])
|
||
functional_tool_model_ids.append(functional_tool_model.id)
|
||
return [(6, 0, functional_tool_model_ids)]
|
||
|
||
def open_functional_tool_warning(self):
|
||
action = self.env.ref('sf_tool_management.action_sf_functional_tool_warning')
|
||
result = action.read()[0]
|
||
result['domain'] = [('functional_tool_name_id', '=', self.functional_tool_name_id.id)]
|
||
return result
|
||
|
||
def open_stock_move_line(self):
|
||
action = self.env.ref('sf_tool_management.sf_inbound_and_outbound_records_of_functional_tools_view_act')
|
||
result = action.read()[0]
|
||
result['domain'] = [('lot_id', '=', self.barcode_id.id), ('qty_done', '>', 0)]
|
||
return result
|
||
|
||
def open_safety_stock(self):
|
||
action = self.env.ref('sf_tool_management.sf_real_time_distribution_of_functional_tools_view_act')
|
||
result = action.read()[0]
|
||
result['domain'] = [('name', '=', self.name), ('diameter', '=', self.functional_tool_diameter),
|
||
('knife_tip_r_angle', '=', self.knife_tip_r_angle),
|
||
('coarse_middle_thin', '=', self.coarse_middle_thin)]
|
||
return result
|
||
|
||
# ==========刀具组接口==========
|
||
def _register_functional_tool_groups(self, obj):
|
||
create_url = '/AutoDeviceApi/FeedBackOut'
|
||
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(obj, token, sf_secret_key)
|
||
strurl = sf_sync_config['sf_url'] + create_url
|
||
val = {
|
||
'ToolName': obj.name,
|
||
'GroupName': obj.tool_groups_id.name,
|
||
'ToolId': obj.code
|
||
}
|
||
kw = json.dumps(val, ensure_ascii=False)
|
||
r = requests.post(strurl, json={}, data={'kw': kw, 'token': token}, headers=headers)
|
||
ret = r.json()
|
||
if r == 200:
|
||
return "刀具组发送成功"
|
||
else:
|
||
raise ValidationError("刀具组发送失败")
|
||
|
||
# @api.model_create_multi
|
||
# def create(self, vals):
|
||
# obj = super(FunctionalCuttingToolEntity, self).create(vals)
|
||
# # 调用刀具组接口
|
||
# self._register_functional_tool_groups(obj)
|
||
# return obj
|
||
|
||
|
||
class FunctionalToolWarning(models.Model):
|
||
_name = 'sf.functional.tool.warning'
|
||
_description = '功能刀具预警'
|
||
|
||
code = fields.Char('编码', related='functional_tool_name_id.code')
|
||
tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组', related='functional_tool_name_id.tool_groups_id')
|
||
name = fields.Char('名称', invisible=True, readonly=True, related='functional_tool_name_id.name')
|
||
# 机床信息
|
||
production_line_id = fields.Many2one('sf.production.line', string='生产线',
|
||
group_expand='_read_group_machine_table_name_ids')
|
||
maintenance_equipment_id = fields.Many2one('maintenance.equipment', string='CNC机床')
|
||
machine_tool_code = fields.Char(string='机台号', related='maintenance_equipment_id.name')
|
||
machine_table_type_id = fields.Many2one('maintenance.equipment.category', string='机床类型')
|
||
cutter_spacing_code_id = fields.Many2one('maintenance.equipment.tool', string='刀位号',
|
||
domain="[('equipment_id', '=', maintenance_equipment_id)]")
|
||
# 功能刀具信息
|
||
functional_tool_name_id = fields.Many2one('sf.functional.tool.assembly', string='功能刀具名称')
|
||
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号', related='functional_tool_name_id.barcode_id')
|
||
mrs_cutting_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型')
|
||
diameter = fields.Integer(string='刀具直径(mm)')
|
||
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)')
|
||
# 其他信息
|
||
install_tool_time = fields.Datetime("刀具组装时间", related='functional_tool_name_id.tool_loading_time')
|
||
on_board_time = fields.Datetime('上机装刀时间')
|
||
max_lifetime_value = fields.Integer(string='最大寿命值(min)')
|
||
alarm_value = fields.Integer(string='报警值(min)')
|
||
used_value = fields.Integer(string='已使用值(min)')
|
||
functional_tool_status = fields.Selection([('正常', '正常'), ('报警', '报警'), ('已拆除', '已拆除')], string='状态')
|
||
alarm_time = fields.Datetime('报警时间')
|
||
dispose_user = fields.Char('处理人')
|
||
dispose_time = fields.Char('处理时间')
|
||
dispose_func = fields.Char('处理方法/措施', readonly=False)
|
||
|
||
@api.model
|
||
def _read_group_machine_table_name_ids(self, categories, domain, order):
|
||
machine_table_name_ids = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
|
||
return categories.browse(machine_table_name_ids)
|
||
|
||
def create_tool_warning_record(self, obj):
|
||
"""
|
||
机台换刀申请报警状态时,创建功能刀具预警记录
|
||
"""
|
||
if obj:
|
||
for tool in obj.get('tool_changing_apply_id'):
|
||
self.env['sf.functional.tool.warning'].create({
|
||
'production_line_id': tool.production_line_id.id,
|
||
'maintenance_equipment_id': tool.maintenance_equipment_id.id,
|
||
'machine_tool_code': tool.machine_tool_code,
|
||
'machine_table_type_id': tool.machine_table_type_id.id,
|
||
'cutter_spacing_code_id': tool.cutter_spacing_code_id.id,
|
||
'functional_tool_name_id': tool.functional_tool_name_id.id,
|
||
'barcode_id': tool.barcode_id.id,
|
||
'diameter': tool.diameter,
|
||
'knife_tip_r_angle': tool.knife_tip_r_angle,
|
||
'max_lifetime_value': tool.max_lifetime_value,
|
||
'alarm_value': tool.alarm_value,
|
||
'used_value': tool.used_value,
|
||
'functional_tool_status': tool.functional_tool_status,
|
||
'alarm_time': fields.Datetime.now(),
|
||
})
|
||
|
||
|
||
class StockMoveLine(models.Model):
|
||
_inherit = 'stock.move.line'
|
||
_description = '功能刀具出入库记录'
|
||
_order = 'date desc'
|
||
|
||
functional_tool_name_id = fields.Many2one('sf.functional.tool.assembly', string='功能刀具名称')
|
||
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', store=True,
|
||
group_expand='_read_group_functional_tool_type_id',
|
||
related='functional_tool_name_id.functional_tool_type_id')
|
||
diameter = fields.Integer(string='刀具直径(mm)', related='functional_tool_name_id.functional_tool_diameter')
|
||
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)', related='functional_tool_name_id.knife_tip_r_angle')
|
||
install_tool_time = fields.Datetime("刀具组装时间", related='functional_tool_name_id.tool_loading_time')
|
||
code = fields.Char('编码', related='functional_tool_name_id.code')
|
||
tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组', related='functional_tool_name_id.tool_groups_id')
|
||
|
||
@api.model
|
||
def _read_group_functional_tool_type_id(self, categories, domain, order):
|
||
names = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
|
||
return categories.browse(names)
|
||
|
||
|
||
class RealTimeDistributionOfFunctionalTools(models.Model):
|
||
_name = 'sf.real.time.distribution.of.functional.tools'
|
||
_description = '功能刀具安全库存'
|
||
|
||
name = fields.Char('功能刀具名称', readonly=True, compute='_compute_name')
|
||
tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组', readonly=False, required=True)
|
||
sf_cutting_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', readonly=False,
|
||
group_expand='_read_mrs_cutting_tool_type_ids', store=True)
|
||
diameter = fields.Integer(string='刀具直径(mm)', readonly=False)
|
||
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)', readonly=False)
|
||
tool_stock_num = fields.Integer(string='刀具房数量')
|
||
side_shelf_num = fields.Integer(string='线边刀库数量')
|
||
on_tool_stock_num = fields.Integer(string='机内刀库数量')
|
||
tool_stock_total = fields.Integer(string='当前库存量', readonly=True)
|
||
min_stock_num = fields.Integer('最低库存量')
|
||
max_stock_num = fields.Integer('最高库存量')
|
||
batch_replenishment_num = fields.Integer('批次补货量', readonly=True, compute='_compute_batch_replenishment_num')
|
||
unit = fields.Char('单位')
|
||
image = fields.Binary('图片', readonly=False)
|
||
|
||
coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')], string='粗/中/精', readonly=False)
|
||
whether_standard_knife = fields.Boolean(string='是否标准刀', default=True, readonly=False)
|
||
# 能力特征信息
|
||
suitable_machining_method_ids = fields.Many2many(
|
||
'maintenance.equipment.image', 'rel_machining_product_template_distribution', '适合加工方式',
|
||
domain=[('type', '=', '加工能力')],
|
||
related='sf_functional_cutting_tool_entity_ids.suitable_machining_method_ids')
|
||
blade_tip_characteristics_id = fields.Many2one(
|
||
'maintenance.equipment.image', '刀尖特征',
|
||
domain=[('type', '=', '刀尖特征')],
|
||
related='sf_functional_cutting_tool_entity_ids.blade_tip_characteristics_id')
|
||
handle_type_id = fields.Many2one(
|
||
'maintenance.equipment.image', '柄部类型',
|
||
domain=[('type', '=', '柄部类型')], related='sf_functional_cutting_tool_entity_ids.handle_type_id')
|
||
cutting_direction_ids = fields.Many2many(
|
||
'maintenance.equipment.image', 'rel_cutting_product_template_distribution', '走刀方向',
|
||
domain=[('type', '=', '走刀方向')], related='sf_functional_cutting_tool_entity_ids.cutting_direction_ids')
|
||
suitable_coolant_ids = fields.Many2many(
|
||
'maintenance.equipment.image', 'rel_coolants_product_template_distribution', '适合冷却方式',
|
||
domain=[('type', '=', '冷却方式')], related='sf_functional_cutting_tool_entity_ids.suitable_coolant_ids')
|
||
|
||
sf_functional_cutting_tool_entity_ids = fields.Many2many('sf.functional.cutting.tool.entity',
|
||
'sf_functional_cutting_tool_entity_ref',
|
||
string='功能刀具列表信息', readonly=True)
|
||
|
||
sf_functional_tool_assembly_ids = fields.Many2many('sf.functional.tool.assembly', 'sf_functional_tool_assembly_ref',
|
||
'功能刀具组装单', readonly=True)
|
||
|
||
@api.depends('tool_groups_id', 'diameter', 'knife_tip_r_angle')
|
||
def _compute_name(self):
|
||
for obj in self:
|
||
if obj.tool_groups_id:
|
||
obj.sudo().name = '%s-D%sR%s' % (obj.tool_groups_id.name, obj.diameter, obj.knife_tip_r_angle)
|
||
else:
|
||
obj.sudo().name = None
|
||
|
||
@api.constrains('min_stock_num', 'max_stock_num')
|
||
def _check_stock_num(self):
|
||
for obj in self:
|
||
if obj.min_stock_num > obj.max_stock_num:
|
||
raise ValidationError('【最低安全库存】不能高于【最高安全库存】!!!')
|
||
|
||
@api.model
|
||
def _read_mrs_cutting_tool_type_ids(self, categories, domain, order):
|
||
mrs_cutting_tool_type_ids = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
|
||
return categories.browse(mrs_cutting_tool_type_ids)
|
||
|
||
@api.depends('sf_functional_cutting_tool_entity_ids', 'min_stock_num', 'max_stock_num')
|
||
def _compute_batch_replenishment_num(self):
|
||
for tool in self:
|
||
if tool:
|
||
# 判断功能刀具组装单是否已经完成
|
||
tool.sudo().estimate_functional_tool_assembly_ids(tool)
|
||
tool.sudo().get_stock_num(tool)
|
||
# 计算当前库存量
|
||
tool.sudo().tool_stock_total = tool.tool_stock_num + tool.side_shelf_num + tool.on_tool_stock_num
|
||
# 如果当前库存量小于最低库存量,计算批次补货量
|
||
tool.sudo().open_batch_replenishment_num(tool)
|
||
|
||
def open_batch_replenishment_num(self, tool):
|
||
"""
|
||
计算批次补货量
|
||
"""
|
||
if tool.tool_stock_total < tool.min_stock_num:
|
||
tool.sudo().batch_replenishment_num = tool.max_stock_num - tool.tool_stock_total
|
||
# 根据判断创建功能刀具组装单
|
||
if not tool.sf_functional_tool_assembly_ids and re.match(r'^\d+$', str(tool.id)):
|
||
for i in range(tool.batch_replenishment_num):
|
||
tool.sudo().create_functional_tool_assembly(tool)
|
||
print(i, ": ", tool.sf_functional_tool_assembly_ids)
|
||
else:
|
||
tool.sudo().batch_replenishment_num = 0
|
||
|
||
def create_functional_tool_assembly(self, tool):
|
||
"""
|
||
创建功能刀具组装单
|
||
"""
|
||
functional_tool_assembly = tool.env['sf.functional.tool.assembly'].sudo().create({
|
||
'functional_tool_name': tool.name,
|
||
'functional_tool_type_id': tool.sf_cutting_tool_type_id.id,
|
||
'tool_groups_id': tool.tool_groups_id.id,
|
||
'functional_tool_diameter': tool.diameter,
|
||
'knife_tip_r_angle': tool.knife_tip_r_angle,
|
||
'coarse_middle_thin': tool.coarse_middle_thin,
|
||
'loading_task_source': '2',
|
||
'use_tool_time': fields.Datetime.now() + timedelta(hours=4),
|
||
'applicant': '系统自动',
|
||
'apply_time': fields.Datetime.now(),
|
||
'whether_standard_knife': tool.whether_standard_knife,
|
||
'reason_for_applying': '安全库存',
|
||
})
|
||
tool.sudo().sf_functional_tool_assembly_ids = [(4, functional_tool_assembly.id)]
|
||
|
||
def estimate_functional_tool_assembly_ids(self, tool):
|
||
"""
|
||
判断功能刀具组装单是否完成,如果全部完成清空sf_functional_tool_assembly_ids的数据
|
||
"""
|
||
for sf_functional_tool_assembly_id in tool.sf_functional_tool_assembly_ids:
|
||
if sf_functional_tool_assembly_id.assemble_status == '0':
|
||
return False
|
||
tool.sudo().sf_functional_tool_assembly_ids = []
|
||
|
||
def get_stock_num(self, tool):
|
||
"""
|
||
计算刀具房数量、线边刀库数量、机内刀库数量
|
||
"""
|
||
if tool:
|
||
tool.sudo().tool_stock_num = 0
|
||
tool.sudo().side_shelf_num = 0
|
||
tool.sudo().on_tool_stock_num = 0
|
||
if tool.sf_functional_cutting_tool_entity_ids:
|
||
for cutting_tool in tool.sf_functional_cutting_tool_entity_ids:
|
||
if cutting_tool.tool_room_num > 0:
|
||
tool.sudo().tool_stock_num += 1
|
||
elif cutting_tool.line_edge_knife_library_num > 0:
|
||
tool.sudo().side_shelf_num += 1
|
||
elif cutting_tool.machine_knife_library_num > 0:
|
||
tool.sudo().on_tool_stock_num += 1
|
||
|
||
def create_or_edit_safety_stock(self, vals, sf_functional_cutting_tool_entity_ids):
|
||
"""
|
||
根据传入的信息新增或者更新功能刀具安全库存的信息
|
||
"""
|
||
# 根据功能刀具名称、刀具组、直径或尖刀R角、粗/中/精查询该功能刀具是否已经存在
|
||
record = self.env['sf.real.time.distribution.of.functional.tools'].search(
|
||
[('name', '=', vals['name']), ('sf_cutting_tool_type_id', '=', vals['sf_cutting_tool_type_id']),
|
||
('diameter', '=', vals['diameter']), ('knife_tip_r_angle', '=', vals['knife_tip_r_angle']),
|
||
('coarse_middle_thin', '=', vals['coarse_middle_thin']), ('tool_groups_id', '=', vals['tool_groups_id'])])
|
||
if len(record) > 0:
|
||
for obj in record:
|
||
obj.write({'sf_functional_cutting_tool_entity_ids': [(4, sf_functional_cutting_tool_entity_ids.id)]})
|
||
else:
|
||
vals['sf_functional_cutting_tool_entity_ids'] = sf_functional_cutting_tool_entity_ids.ids
|
||
self.env['sf.real.time.distribution.of.functional.tools'].create(vals)
|
||
|
||
status_create = fields.Boolean('是否是新增状态', default=True)
|
||
|
||
@api.model_create_multi
|
||
def create(self, vals_list):
|
||
for vals in vals_list:
|
||
vals['status_create'] = False
|
||
records = super(RealTimeDistributionOfFunctionalTools, self).create(vals_list)
|
||
return records
|
||
|
||
|
||
class MachineTableToolChangingApply(models.Model):
|
||
_name = 'sf.machine.table.tool.changing.apply'
|
||
_description = '机床换刀申请'
|
||
_order = 'cutter_spacing_code_id'
|
||
|
||
name = fields.Char('名称', related='maintenance_equipment_id.name', store=True)
|
||
# 设备信息
|
||
maintenance_equipment_id = fields.Many2one('maintenance.equipment', string='CNC机床', readonly=True,
|
||
domain=[('category_id.equipment_type', '=', '机床')])
|
||
production_line_id = fields.Many2one('sf.production.line', string='生产线', readonly=True)
|
||
machine_table_type_id = fields.Many2one('maintenance.equipment.category', string='机床类型', readonly=True,
|
||
compute='_compute_machine_table_type_id')
|
||
machine_tool_code = fields.Char(string='机台号', related='maintenance_equipment_id.name')
|
||
cutter_spacing_code_id = fields.Many2one('maintenance.equipment.tool', string='刀位号', readonly=True,
|
||
required=True, domain="[('equipment_id', '=', maintenance_equipment_id)]")
|
||
# 功能刀具信息
|
||
code = fields.Char('编码', related='functional_tool_name_id.code')
|
||
tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组', related='functional_tool_name_id.tool_groups_id')
|
||
functional_tool_name = fields.Char(string='刀具名称', related='functional_tool_name_id.name', store=True)
|
||
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号', store=True,
|
||
domain=[('product_id.name', '=', '功能刀具')],
|
||
related='functional_tool_name_id.barcode_id')
|
||
functional_tool_name_id = fields.Many2one('sf.functional.tool.assembly', domain=[('assemble_status', '=', '1')],
|
||
string='功能刀具名称')
|
||
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', store=True,
|
||
related='functional_tool_name_id.after_assembly_functional_tool_type_id')
|
||
|
||
tool_position_interface_type = fields.Selection(
|
||
[('BT刀柄式', 'BT刀柄式'), ('SK刀柄式', 'SK刀柄式'), ('HSK刀柄式', 'HSK刀柄式'),
|
||
('CAT刀柄式', 'CAT刀柄式'), ('ISO刀盘式', 'ISO刀盘式'), ('DIN刀盘式', 'DIN刀盘式'),
|
||
('直装固定式', '直装固定式')], string='刀位接口型号')
|
||
diameter = fields.Integer(string='刀具直径(mm)')
|
||
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)')
|
||
max_lifetime_value = fields.Integer(string='最大寿命值(min)')
|
||
alarm_value = fields.Integer(string='报警值(min)')
|
||
used_value = fields.Integer(string='已使用值(min)')
|
||
whether_standard_knife = fields.Boolean(string='是否标准刀', default=True)
|
||
extension_length = fields.Float(string='伸出长(mm)')
|
||
effective_length = fields.Float(string='有效长(mm)')
|
||
|
||
functional_tool_status = fields.Selection([('正常', '正常'), ('报警', '报警')], string='功能刀具状态', store=True,
|
||
default='正常', compute='_compute_functional_tool_status')
|
||
|
||
assembly_order_code = fields.Char(string='组装单编码', readonly=True)
|
||
applicant = fields.Char(string='申请人', readonly=True)
|
||
reason_for_applying = fields.Char(string='申请原因', readonly=True)
|
||
remark = fields.Char(string='备注说明', readonly=False)
|
||
|
||
status = fields.Selection([('0', '未操作'), ('1', '已换刀申请'), ('2', '已转移'), ('3', '已组装')],
|
||
string='操作状态', default='0')
|
||
|
||
sf_functional_tool_assembly_id = fields.Many2one('sf.functional.tool.assembly', '功能刀具组装单', readonly=True)
|
||
|
||
@api.depends('alarm_value', 'used_value')
|
||
def _compute_functional_tool_status(self):
|
||
for record in self:
|
||
if record.alarm_value < record.used_value:
|
||
record.sudo().functional_tool_status = '报警'
|
||
else:
|
||
record.sudo().functional_tool_status = '正常'
|
||
|
||
@api.depends('maintenance_equipment_id')
|
||
def _compute_machine_table_type_id(self):
|
||
for record in self:
|
||
if record:
|
||
record.sudo().production_line_id = record.maintenance_equipment_id.production_line_id.id
|
||
record.sudo().machine_table_type_id = record.maintenance_equipment_id.category_id.id
|
||
record.sudo().machine_tool_code = record.maintenance_equipment_id.code
|
||
else:
|
||
record.sudo().production_line_id = None
|
||
record.sudo().machine_table_type_id = None
|
||
record.sudo().machine_tool_code = None
|
||
|
||
@api.constrains("cutter_spacing_code_id")
|
||
def _check_cutter_spacing_code_id(self):
|
||
for obj in self:
|
||
records = self.env['sf.machine.table.tool.changing.apply'].search([
|
||
('maintenance_equipment_id', '=', obj.maintenance_equipment_id.id),
|
||
('cutter_spacing_code_id', '=', obj.cutter_spacing_code_id.id)])
|
||
if len(records) > 1:
|
||
raise ValidationError('该刀位号已存在,请重新选择!!!')
|
||
|
||
@api.constrains('functional_tool_status')
|
||
def automation_apply_for_tool_change(self):
|
||
"""
|
||
自动申请换刀
|
||
:return:
|
||
"""
|
||
# 更新数据到机台换刀申请界面
|
||
if self.functional_tool_status == '报警' and not self.sf_functional_tool_assembly_id:
|
||
machine_table_tool_changing_apply = self.env['sf.machine.table.tool.changing.apply'].search(
|
||
[('maintenance_equipment_id', '=', self.maintenance_equipment_id.id),
|
||
('cutter_spacing_code_id', '=', self.cutter_spacing_code_id.id)
|
||
])
|
||
|
||
# 创建功能刀具预警记录
|
||
self.env['sf.functional.tool.warning'].create_tool_warning_record({'tool_changing_apply_id': self})
|
||
|
||
# 新建组装任务
|
||
sf_functional_tool_assembly = self.env['sf.functional.tool.assembly'].create({
|
||
'functional_tool_name': self.functional_tool_name,
|
||
'functional_tool_type_id': self.functional_tool_type_id.id,
|
||
'functional_tool_diameter': self.diameter,
|
||
'knife_tip_r_angle': self.knife_tip_r_angle,
|
||
'coarse_middle_thin': '3',
|
||
'new_former': '0',
|
||
'functional_tool_length': self.extension_length,
|
||
'effective_length': self.effective_length,
|
||
'loading_task_source': '1',
|
||
'use_tool_time': fields.Datetime.now() + timedelta(hours=4),
|
||
'production_line_name_id': self.production_line_id.id,
|
||
'machine_tool_name_id': self.maintenance_equipment_id.id,
|
||
'applicant': '系统自动',
|
||
'apply_time': fields.Datetime.now(),
|
||
'cutter_spacing_code_id': self.cutter_spacing_code_id.id,
|
||
'whether_standard_knife': self.whether_standard_knife,
|
||
'reason_for_applying': '机台报警自动换刀',
|
||
'sf_machine_table_tool_changing_apply_id': self.id
|
||
})
|
||
|
||
machine_table_tool_changing_apply.write(
|
||
{'status': '1',
|
||
'sf_functional_tool_assembly_id': sf_functional_tool_assembly.id})
|
||
|
||
def revocation_1(self):
|
||
"""
|
||
换刀申请撤回按键
|
||
:return:
|
||
"""
|
||
# 撤回功能刀具组装创建的任务
|
||
self.env['sf.functional.tool.assembly'].search(
|
||
[('id', '=', self.sf_functional_tool_assembly_id.id),
|
||
('loading_task_source', '=', '1')]).unlink()
|
||
|
||
# 撤回数据更新
|
||
self.env['sf.machine.table.tool.changing.apply'].search(
|
||
[('maintenance_equipment_id', '=', self.maintenance_equipment_id.id),
|
||
('cutter_spacing_code_id', '=', self.cutter_spacing_code_id.id)]).write(
|
||
{'status': '0',
|
||
'sf_functional_tool_assembly_id': None
|
||
})
|
||
|
||
def revocation_2(self):
|
||
"""
|
||
转移撤回按键
|
||
:return:
|
||
"""
|
||
self.env['sf.machine.table.tool.changing.apply'].search(
|
||
[('name', '=', self.name.id)]).write({'status': '0'})
|
||
|
||
def create_tool_change_application(self):
|
||
"""
|
||
根据已有机床刀位创建机台换刀申请记录
|
||
"""
|
||
maintenance_equipment_ids = self.env['maintenance.equipment'].sudo().search(
|
||
[('product_template_ids', '!=', False)])
|
||
tool_changing_apply = self.env['sf.machine.table.tool.changing.apply']
|
||
if maintenance_equipment_ids:
|
||
for maintenance_equipment_id in maintenance_equipment_ids:
|
||
if maintenance_equipment_id.product_template_ids:
|
||
for product_template_id in maintenance_equipment_id.product_template_ids:
|
||
tool_changing_apply.sudo().create({
|
||
'maintenance_equipment_id': product_template_id.equipment_id.id,
|
||
'cutter_spacing_code_id': product_template_id.id
|
||
})
|
||
|
||
|
||
class CAMWorkOrderProgramKnifePlan(models.Model):
|
||
_name = 'sf.cam.work.order.program.knife.plan'
|
||
_description = 'CAM工单程序用刀计划'
|
||
|
||
name = fields.Char('工单任务编号')
|
||
cam_procedure_code = fields.Char('程序名')
|
||
filename = fields.Char('文件')
|
||
cam_cutter_spacing_code = fields.Char('刀号')
|
||
tool_position_interface_type = fields.Selection(
|
||
[('BT刀柄式', 'BT刀柄式'), ('SK刀柄式', 'SK刀柄式'), ('HSK刀柄式', 'HSK刀柄式'),
|
||
('CAT刀柄式', 'CAT刀柄式'), ('ISO刀盘式', 'ISO刀盘式'), ('DIN刀盘式', 'DIN刀盘式'),
|
||
('直装固定式', '直装固定式')], string='刀位接口型号')
|
||
production_line_id = fields.Many2one('sf.production.line', string='生产线', group_expand='_read_group_names')
|
||
machine_table_name_id = fields.Many2one('maintenance.equipment', string='机床名称',
|
||
domain="[('production_line_id', '=', production_line_id)]")
|
||
machine_table_name = fields.Char(string='机台号', readonly=True, related='machine_table_name_id.name')
|
||
cutter_spacing_code_id = fields.Many2one('maintenance.equipment.tool', string='刀位号', required=True,
|
||
domain="[('equipment_id', '=', machine_table_name_id)]")
|
||
whether_standard_knife = fields.Boolean(string='是否标准刀', default=True)
|
||
need_knife_time = fields.Datetime(string='用刀时间', readonly=False)
|
||
applicant = fields.Char(string='申请人', readonly=True)
|
||
applicant_time = fields.Datetime(string='申请时间', readonly=True)
|
||
reason_for_applying = fields.Char(string='申请原因', readonly=False)
|
||
|
||
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号',
|
||
domain=[('product_id.name', '=', '功能刀具')])
|
||
functional_tool_name = fields.Char(string='功能刀具名称', compute='_compute_functional_tool_name')
|
||
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', readonly=False)
|
||
tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组')
|
||
diameter = fields.Integer(string='刀具直径(mm)', readonly=False)
|
||
tool_included_angle = fields.Float(string='刀尖R角(mm)', readonly=False)
|
||
tool_loading_length = fields.Float(string='总长度(mm)', readonly=False)
|
||
extension_length = fields.Float(string='伸出长(mm)')
|
||
effective_length = fields.Float(string='有效长(mm)')
|
||
new_former = fields.Selection([('0', '新'), ('1', '旧')], string='新/旧', readonly=False, default='0')
|
||
coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')], default='3',
|
||
string='粗/中/精', readonly=False)
|
||
L_D = fields.Float(string='L/D值', readonly=False)
|
||
clearance_length = fields.Float(string='避空长(mm)', readonly=False)
|
||
required_cutting_time = fields.Integer(string='需切削时长', readonly=False)
|
||
process_type = fields.Char('加工类型')
|
||
margin_x_y = fields.Float('余量_X/Y')
|
||
margin_z = fields.Float('余量_Z')
|
||
finish_depth = fields.Float('加工深度')
|
||
shank_model = fields.Char('刀柄型号')
|
||
estimated_processing_time = fields.Char('预计加工时间')
|
||
|
||
plan_execute_status = fields.Selection([('0', '待下发'), ('1', '执行中'), ('2', '已完成')],
|
||
string='计划执行状态', default='0', readonly=False)
|
||
|
||
sf_functional_tool_assembly_id = fields.Many2one('sf.functional.tool.assembly', '功能刀具组装', readonly=True)
|
||
|
||
@api.depends('diameter', 'tool_included_angle', 'tool_groups_id')
|
||
def _compute_functional_tool_name(self):
|
||
for obj in self:
|
||
if obj.tool_groups_id:
|
||
obj.functional_tool_name = '%s-D%sR%s' % (
|
||
obj.tool_groups_id.name, obj.diameter,
|
||
obj.tool_included_angle)
|
||
else:
|
||
obj.functional_tool_name = None
|
||
|
||
@api.model
|
||
def _read_group_names(self, categories, domain, order):
|
||
names = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
|
||
return categories.browse(names)
|
||
|
||
def apply_for_tooling(self):
|
||
"""
|
||
申请装刀
|
||
:return:
|
||
"""
|
||
record = self.env['sf.functional.tool.assembly'].create({
|
||
'functional_tool_name': self.functional_tool_name,
|
||
'functional_tool_type_id': self.functional_tool_type_id.id,
|
||
'tool_groups_id': self.tool_groups_id.id,
|
||
'functional_tool_diameter': self.diameter,
|
||
'knife_tip_r_angle': self.tool_included_angle,
|
||
'tool_loading_length': self.tool_loading_length,
|
||
'functional_tool_length': self.extension_length,
|
||
'effective_length': self.effective_length,
|
||
'whether_standard_knife': self.whether_standard_knife,
|
||
'coarse_middle_thin': self.coarse_middle_thin,
|
||
'new_former': self.new_former,
|
||
'production_line_name_id': self.production_line_id.id,
|
||
'machine_tool_name_id': self.machine_table_name_id.id,
|
||
'cutter_spacing_code_id': self.env['maintenance.equipment.tool'].sudo().search(
|
||
[('code', '=', self.cam_cutter_spacing_code), ('equipment_id', '=', self.machine_table_name_id.id)]).id,
|
||
|
||
'loading_task_source': '0',
|
||
'applicant': self.env.user.name,
|
||
'use_tool_time': self.need_knife_time,
|
||
'reason_for_applying': '工单用刀',
|
||
|
||
'sf_cam_work_order_program_knife_plan_id': self.id
|
||
})
|
||
self.sf_functional_tool_assembly_id = record.id
|
||
|
||
# 将计划执行状态改为执行中
|
||
self.env['sf.cam.work.order.program.knife.plan'].search(
|
||
[('name', '=', self.name), ('functional_tool_name', '=', self.functional_tool_name)]).write(
|
||
{'plan_execute_status': '1',
|
||
'applicant': self.env.user.name})
|
||
|
||
def revocation(self):
|
||
"""
|
||
撤回装刀申请
|
||
:return:
|
||
"""
|
||
self.env['sf.functional.tool.assembly'].search(
|
||
[('assembly_order_code', '=', self.sf_functional_tool_assembly_id.assembly_order_code),
|
||
('loading_task_source', '=', '0')]).unlink()
|
||
|
||
# 将计划执行状态改为待执行,同时清除申请人、功能刀具组装字段数据
|
||
self.env['sf.cam.work.order.program.knife.plan'].search(
|
||
[('name', '=', self.name), ('functional_tool_name', '=', self.functional_tool_name)]).write(
|
||
{'plan_execute_status': '0',
|
||
'applicant': None,
|
||
'sf_functional_tool_assembly_id': None})
|
||
|
||
def create_cam_work_plan(self, cnc_processing):
|
||
"""
|
||
根据传入的工单信息,查询是否有需要的功能刀具,如果没有则生成CAM工单程序用刀计划
|
||
"""
|
||
status = False
|
||
if cnc_processing.functional_tool_type_id and cnc_processing.cutting_tool_name:
|
||
functional_tools = self.env['sf.real.time.distribution.of.functional.tools'].sudo().search(
|
||
[('sf_cutting_tool_type_id', '=', cnc_processing.functional_tool_type_id.id),
|
||
('name', '=', cnc_processing.cutting_tool_name)])
|
||
if functional_tools:
|
||
for functional_tool in functional_tools:
|
||
if functional_tool.on_tool_stock_num == 0:
|
||
# self.env['sf.cnc.processing'].register_cnc_processing(cnc_processing)
|
||
if functional_tool.tool_stock_num == 0 and functional_tool.side_shelf_num == 0:
|
||
status = True
|
||
else:
|
||
status = True
|
||
if status:
|
||
self.env['sf.cam.work.order.program.knife.plan'].sudo().create({
|
||
'name': cnc_processing.workorder_id.production_id.name,
|
||
'cam_procedure_code': cnc_processing.program_name,
|
||
'filename': cnc_processing.cnc_id.name,
|
||
'functional_tool_type_id': cnc_processing.functional_tool_type_id.id,
|
||
'functional_tool_name': cnc_processing.cutting_tool_name,
|
||
'cam_cutter_spacing_code': cnc_processing.cutting_tool_no,
|
||
'process_type': cnc_processing.processing_type,
|
||
'margin_x_y': float(cnc_processing.margin_x_y),
|
||
'margin_z': float(cnc_processing.margin_z),
|
||
'finish_depth': float(cnc_processing.depth_of_processing_z),
|
||
'extension_length': float(cnc_processing.cutting_tool_extension_length),
|
||
'shank_model': cnc_processing.cutting_tool_handle_type,
|
||
'estimated_processing_time': cnc_processing.estimated_processing_time,
|
||
})
|
||
|
||
|
||
class FunctionalToolAssembly(models.Model):
|
||
_name = 'sf.functional.tool.assembly'
|
||
_description = '功能刀具组装'
|
||
_order = 'use_tool_time asc'
|
||
|
||
@api.depends('functional_tool_name')
|
||
def _compute_name(self):
|
||
for obj in self:
|
||
obj.name = obj.after_assembly_functional_tool_name
|
||
|
||
code = fields.Char('功能刀具编码', readonly=True)
|
||
tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组', readonly=True)
|
||
name = fields.Char(string='名称', readonly=True, compute='_compute_name')
|
||
assembly_order_code = fields.Char(string='组装单编码', readonly=True)
|
||
|
||
functional_tool_name_id = fields.Many2one('product.product', string='功能刀具', readonly=True)
|
||
functional_tool_name = fields.Char(string='功能刀具名称', readonly=True)
|
||
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', readonly=True,
|
||
group_expand='_read_group_functional_tool_type_ids')
|
||
functional_tool_diameter = fields.Integer(string='功能刀具直径(mm)', readonly=True)
|
||
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)', readonly=True)
|
||
coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')], string='粗/中/精', readonly=True)
|
||
new_former = fields.Selection([('0', '新'), ('1', '旧')], string='新/旧', readonly=True)
|
||
tool_loading_length = fields.Float(string='总长度(mm)', readonly=True)
|
||
functional_tool_length = fields.Float(string='伸出长(mm)', readonly=True)
|
||
effective_length = fields.Float(string='有效长(mm)', readonly=True)
|
||
loading_task_source = fields.Selection([('0', 'CAM装刀'), ('1', '机台换刀'), ('2', '按库存组装')],
|
||
string='装刀任务来源', readonly=True)
|
||
use_tool_time = fields.Datetime(string='用刀时间', readonly=True)
|
||
production_line_name_id = fields.Many2one('sf.production.line', string='申请产线', readonly=True)
|
||
machine_tool_name_id = fields.Many2one('maintenance.equipment', string='申请机台', readonly=True)
|
||
machine_tool_code = fields.Char(string='机台号', readonly=True)
|
||
applicant = fields.Char(string='申请人', readonly=True)
|
||
apply_time = fields.Datetime(string='申请时间', default=fields.Datetime.now(), readonly=True)
|
||
assemble_status = fields.Selection([('0', '待组装'), ('1', '已组装')], string='组装状态', default='0',
|
||
readonly=True)
|
||
cutter_spacing_code_id = fields.Many2one('maintenance.equipment.tool', string='刀位号', readonly=True)
|
||
whether_standard_knife = fields.Boolean(string='是否标准刀', default=True, readonly=True)
|
||
reason_for_applying = fields.Char(string='申请原因', readonly=True)
|
||
max_lifetime_value = fields.Integer(string='最大寿命值(min)', readonly=True)
|
||
alarm_value = fields.Integer(string='报警值(min)', readonly=True)
|
||
used_value = fields.Integer(string='已使用值(min)', readonly=True)
|
||
|
||
image = fields.Binary('图片', readonly=True)
|
||
|
||
@api.model
|
||
def _read_group_functional_tool_type_ids(self, categories, domain, order):
|
||
"""读取分组自定义以便在看板视图中显示所有的类别,即使它们为空"""
|
||
functional_tool_type_ids = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
|
||
return categories.browse(functional_tool_type_ids)
|
||
|
||
# 刀具物料信息
|
||
# 整体式刀具型号
|
||
integral_code_id = fields.Many2one('stock.lot', string='整体式刀具序列号', readonly=True)
|
||
cutting_tool_integral_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='整体式刀具型号',
|
||
related='integral_code_id.product_id.cutting_tool_model_id')
|
||
integral_name = fields.Char('整体式刀具名称', related='integral_code_id.product_id.name')
|
||
integral_specification_id = fields.Many2one('sf.tool.materials.basic.parameters', string='整体式刀具规格',
|
||
related='integral_code_id.product_id.specification_id')
|
||
sf_tool_brand_id_1 = fields.Many2one('sf.machine.brand', string='整体式刀具品牌',
|
||
related='integral_code_id.product_id.brand_id')
|
||
# 刀片型号
|
||
blade_code_id = fields.Many2one('stock.lot', '刀片序列号', readonly=True)
|
||
cutting_tool_blade_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀片型号',
|
||
related='blade_code_id.product_id.cutting_tool_model_id')
|
||
blade_name = fields.Char('刀片名称', related='blade_code_id.product_id.name')
|
||
blade_specification_id = fields.Many2one('sf.tool.materials.basic.parameters', string='刀片规格',
|
||
related='blade_code_id.product_id.specification_id')
|
||
sf_tool_brand_id_2 = fields.Many2one('sf.machine.brand', '刀片品牌', related='blade_code_id.product_id.brand_id')
|
||
# 刀杆型号
|
||
bar_code_id = fields.Many2one('stock.lot', '刀杆序列号', readonly=True)
|
||
cutting_tool_cutterbar_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀杆型号',
|
||
related='bar_code_id.product_id.cutting_tool_model_id')
|
||
bar_name = fields.Char('刀杆名称', related='bar_code_id.product_id.name')
|
||
bar_specification_id = fields.Many2one('sf.tool.materials.basic.parameters', string='刀杆规格',
|
||
related='bar_code_id.product_id.specification_id')
|
||
sf_tool_brand_id_3 = fields.Many2one('sf.machine.brand', '刀杆品牌', related='bar_code_id.product_id.brand_id')
|
||
# 刀盘型号
|
||
pad_code_id = fields.Many2one('stock.lot', '刀盘序列号', readonly=True)
|
||
cutting_tool_cutterpad_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀盘型号',
|
||
related='pad_code_id.product_id.cutting_tool_model_id')
|
||
pad_name = fields.Char('刀盘名称', related='pad_code_id.product_id.name')
|
||
pad_specification_id = fields.Many2one('sf.tool.materials.basic.parameters', string='刀盘规格',
|
||
related='pad_code_id.product_id.specification_id')
|
||
sf_tool_brand_id_4 = fields.Many2one('sf.machine.brand', '刀盘品牌', related='pad_code_id.product_id.brand_id')
|
||
# 刀柄型号
|
||
handle_code_id = fields.Many2one('stock.lot', '刀柄序列号', readonly=True)
|
||
cutting_tool_cutterhandle_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀柄型号',
|
||
related='handle_code_id.product_id.cutting_tool_model_id')
|
||
handle_name = fields.Char('刀柄名称', related='handle_code_id.product_id.name')
|
||
handle_specification_id = fields.Many2one('sf.tool.materials.basic.parameters', string='刀柄规格',
|
||
related='handle_code_id.product_id.specification_id')
|
||
sf_tool_brand_id_5 = fields.Many2one('sf.machine.brand', '刀柄品牌', related='handle_code_id.product_id.brand_id')
|
||
# 夹头型号
|
||
chuck_code_id = fields.Many2one('stock.lot', '夹头序列号', readonly=True)
|
||
cutting_tool_cutterhead_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='夹头型号',
|
||
related='chuck_code_id.product_id.cutting_tool_model_id')
|
||
chuck_name = fields.Char('夹头名称', related='chuck_code_id.product_id.name')
|
||
chuck_specification_id = fields.Many2one('sf.tool.materials.basic.parameters', string='夹头规格',
|
||
related='chuck_code_id.product_id.specification_id')
|
||
sf_tool_brand_id_6 = fields.Many2one('sf.machine.brand', '夹头品牌', related='chuck_code_id.product_id.brand_id')
|
||
|
||
# 组装功能刀具参数信息
|
||
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号', readonly=True)
|
||
after_assembly_functional_tool_name = fields.Char(string='组装后功能刀具名称', readonly=True)
|
||
after_assembly_functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model',
|
||
string='组装后功能刀具类型', readonly=True)
|
||
after_assembly_functional_tool_diameter = fields.Integer(string='组装后功能刀具直径(mm)', readonly=True)
|
||
after_assembly_knife_tip_r_angle = fields.Float(string='组装后刀尖R角(mm)', readonly=True)
|
||
after_assembly_new_former = fields.Selection([('0', '新'), ('1', '旧')], string='组装后新/旧', readonly=True)
|
||
cut_time = fields.Integer(string='已切削时间(min)', readonly=True)
|
||
cut_length = fields.Float(string='已切削长度(mm)', readonly=True)
|
||
cut_number = fields.Integer(string='已切削次数', readonly=True)
|
||
|
||
after_assembly_whether_standard_knife = fields.Boolean(string='组装后是否标准刀', default=True, readonly=True)
|
||
after_assembly_coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')],
|
||
string='组装后粗/中/精', readonly=True)
|
||
after_assembly_max_lifetime_value = fields.Integer(string='组装后最大寿命值(min)', readonly=True)
|
||
after_assembly_alarm_value = fields.Integer(string='组装后报警值(min)', readonly=True)
|
||
after_assembly_used_value = fields.Integer(string='组装后已使用值(min)', readonly=True)
|
||
after_assembly_tool_loading_length = fields.Float(string='组装后总长度(mm)', readonly=True)
|
||
after_assembly_functional_tool_length = fields.Float(string='组装后伸出长(mm)', readonly=True)
|
||
after_assembly_effective_length = fields.Float(string='组装后有效长(mm)', readonly=True)
|
||
L_D_number = fields.Float(string='L/D值(mm)', readonly=True)
|
||
hiding_length = fields.Float(string='避空长(mm)', readonly=True)
|
||
|
||
# functional_tool_cutting_type = fields.Char(string='功能刀具切削类型', readonly=False)
|
||
tool_loading_person = fields.Char(string='装刀人', readonly=True)
|
||
tool_loading_time = fields.Datetime(string='装刀时间', readonly=True)
|
||
remark = fields.Char(string='备注说明', readonly=True)
|
||
|
||
check_box_1 = fields.Boolean(string='复选框', default=False, readonly=False)
|
||
sf_machine_table_tool_changing_apply_id = fields.Many2one('sf.machine.table.tool.changing.apply', '机床换刀申请',
|
||
readonly=True)
|
||
sf_cam_work_order_program_knife_plan_id = fields.Many2one('sf.cam.work.order.program.knife.plan',
|
||
'CAM工单程序用刀计划', readonly=True, )
|
||
|
||
def _get_code(self, loading_task_source):
|
||
"""
|
||
自动生成组装单编码
|
||
"""
|
||
new_time = str(fields.Date.today())
|
||
datetime = new_time[2:4] + new_time[5:7] + new_time[-2:]
|
||
functional_tool_assembly = self.env['sf.functional.tool.assembly'].sudo().search(
|
||
[('loading_task_source', '=', loading_task_source),
|
||
('assembly_order_code', 'ilike', datetime)], limit=1, order="id desc")
|
||
if not functional_tool_assembly:
|
||
num = "%03d" % 1
|
||
else:
|
||
m = int(functional_tool_assembly.assembly_order_code[-3:]) + 1
|
||
num = "%03d" % m
|
||
if loading_task_source == '0':
|
||
code = 'CAMZZD' + datetime + str(num)
|
||
elif loading_task_source == '1':
|
||
code = 'JTZZD' + datetime + str(num)
|
||
elif loading_task_source == '2':
|
||
code = 'MTSZZD' + datetime + str(num)
|
||
else:
|
||
code = False
|
||
return code
|
||
|
||
def get_functional_tool(self, val):
|
||
functional_tools = self.env['sf.functional.tool.assembly'].search(
|
||
[('after_assembly_functional_tool_name', '=', val.get('after_assembly_functional_tool_name')),
|
||
('after_assembly_functional_tool_diameter', '=', val.get('after_assembly_functional_tool_diameter')),
|
||
('after_assembly_knife_tip_r_angle', '=', val.get('after_assembly_knife_tip_r_angle')),
|
||
('after_assembly_coarse_middle_thin', '=', val.get('after_assembly_coarse_middle_thin'))])
|
||
for functional_tool in functional_tools:
|
||
if functional_tool.barcode_id.quant_ids[-1].location_id.name == '刀具线边库':
|
||
return functional_tool
|
||
for functional_tool in functional_tools:
|
||
if functional_tool.barcode_id.quant_ids[-1].location_id.name == '刀具房':
|
||
return functional_tool
|
||
return False
|
||
|
||
def automated_assembly(self):
|
||
"""
|
||
todo 自动组装
|
||
:return:
|
||
"""
|
||
|
||
def automatic_printing_of_QR_code(self):
|
||
"""
|
||
todo 自动打印二维码
|
||
:return:
|
||
"""
|
||
|
||
def assemble_single_print(self):
|
||
"""
|
||
todo 组装单打印
|
||
:return:
|
||
"""
|
||
|
||
@api.model_create_multi
|
||
def create(self, vals):
|
||
obj = super(FunctionalToolAssembly, self).create(vals)
|
||
if obj.loading_task_source:
|
||
code = self._get_code(obj.loading_task_source)
|
||
obj.assembly_order_code = code
|
||
return obj
|