325 lines
15 KiB
Python
325 lines
15 KiB
Python
# -*- coding: utf-8 -*-
|
||
from odoo import fields, models, api
|
||
|
||
|
||
class FunctionalCuttingToolEntity(models.Model):
|
||
_name = 'sf.functional.cutting.tool.entity'
|
||
_inherit = 'sf.functional.cutting.tool'
|
||
_description = '功能刀具管理'
|
||
|
||
order = fields.Char(string='序')
|
||
functional_cutting_tool_id = fields.Many2one('sf.functional.cutting.tool', string='功能刀具', invisible=True)
|
||
# 功能刀具预警 特有字段
|
||
install_tool_time = fields.Char("装刀时间")
|
||
outbound_time = fields.Char('出库时间')
|
||
on_board_time = fields.Char('上机时间')
|
||
machine_tool_code = fields.Char('机台号')
|
||
cutting_tool_code = fields.Char('刀位号')
|
||
idle_time = fields.Char('闲置时长')
|
||
alarm_value = fields.Char('报警值')
|
||
used_value = fields.Char('已使用值')
|
||
alarm_type = fields.Char('报警类型')
|
||
alarm_time = fields.Char('报警时间')
|
||
dispose_user = fields.Char('处理人')
|
||
dispose_time = fields.Char('处理时间')
|
||
dispose_func = fields.Char('处理方法/措施')
|
||
remark = fields.Char('备注')
|
||
|
||
# 功能刀具出入库记录 特有字段
|
||
thickness = fields.Selection([('1', '粗'), ('2', '中'), ('3', '精')], string='粗/中/精')
|
||
max_life_span = fields.Char(string='最大寿命值')
|
||
# alarm_value = fields.Char(string='报警值')
|
||
# used_value = fields.Char(string='已使用值')
|
||
current_state = fields.Char(string='当前状态')
|
||
current_store_area = fields.Char(string='当前库区')
|
||
current_store_place = fields.Char(string='当前库位')
|
||
number = fields.Integer(string='数量')
|
||
reason_application = fields.Char(string='申请原因')
|
||
applicant = fields.Char(string='申请人')
|
||
return_staff = fields.Char(string='归还人')
|
||
return_time = fields.Date(string='归还入库时间')
|
||
tool_state = fields.Char(string="刀具状态")
|
||
tool_install_staff = fields.Char(string='装刀人')
|
||
tool_install_time = fields.Datetime(string='装刀时间')
|
||
receive_equipment = fields.Char(string='领用机台')
|
||
receive_staff = fields.Char(string='领用人')
|
||
receive_time = fields.Char(string='领用出库时间')
|
||
# remark = fields.Text(string='备注/说明')
|
||
|
||
# 功能刀具实时分布
|
||
tool_stock_num = fields.Text(string='刀具房库存数量')
|
||
side_shelf_num = fields.Text(string='线边货架货架数量')
|
||
on_tool_stock_num = fields.Text(string='机内刀库库存数量')
|
||
tool_stock_total = fields.Text(string='合计')
|
||
return_reuse_num_re = fields.Text(string='归还再用数量(精)')
|
||
return_reuse_num_co = fields.Text(string='归还再用数量(粗)')
|
||
return_processing_num = fields.Text(string='归还需磨削数量')
|
||
return_total = fields.Text(string='合计')
|
||
total = fields.Text(string='总计')
|
||
|
||
# remark = fields.Char(string='备注/说明')
|
||
|
||
# @api.onchange('functional_cutting_tool_id')
|
||
# def get_functional_cutting_tool_info(self):
|
||
# for item in self:
|
||
# item.code = item.functional_cutting_tool_id.code,
|
||
# item.name = item.functional_cutting_tool_id.name,
|
||
# item.functional_model_number = item.functional_cutting_tool_id.functional_model_number,
|
||
# item.integral_model_number = item.functional_cutting_tool_id.integral_model_number,
|
||
# item.blade_model_number = item.functional_cutting_tool_id.blade_model_number,
|
||
# item.cutterbar_model_number = item.functional_cutting_tool_id.cutterbar_model_number,
|
||
# item.cutterpad_model_number = item.functional_cutting_tool_id.cutterpad_model_number,
|
||
# item.handle_model_number = item.functional_cutting_tool_id.handle_model_number,
|
||
# item.chuck_model_number = item.functional_cutting_tool_id.chuck_model_number,
|
||
# item.diameter = item.functional_cutting_tool_id.diameter,
|
||
# item.tool_grade = item.functional_cutting_tool_id.tool_grade,
|
||
# item.machining_accuracy = item.functional_cutting_tool_id.machining_accuracy,
|
||
# item.ctool_lengthode = item.functional_cutting_tool_id.tool_length,
|
||
# item.blade_number = item.functional_cutting_tool_id.blade_number,
|
||
# item.integral_blade_length = item.functional_cutting_tool_id.integral_blade_length,
|
||
# item.effective_blade_length = item.functional_cutting_tool_id.effective_blade_length,
|
||
# item.max_life = item.functional_cutting_tool_id.max_life,
|
||
# item.is_standard = item.functional_cutting_tool_id.is_standard,
|
||
# item.applicable_range = item.functional_cutting_tool_id.applicable_range,
|
||
|
||
@api.model
|
||
def create(self, vals):
|
||
|
||
if not vals.get('order'):
|
||
vals['order'] = self._generate_code()
|
||
return super(FunctionalCuttingToolEntity, self).create(vals)
|
||
|
||
@api.model
|
||
def _generate_code(self):
|
||
last_tool = self.search([], order='id desc', limit=1)
|
||
if last_tool:
|
||
last_code = int(last_tool.code.split('-')[-1])
|
||
new_code = '{:03d}'.format(last_code + 1)
|
||
else:
|
||
new_code = '001'
|
||
return new_code
|
||
|
||
|
||
class MachineTableToolChangingApply(models.Model):
|
||
_name = 'sf.machine.table.tool.changing.apply'
|
||
_description = '机床换刀申请'
|
||
|
||
apply_to_tool_change_ids = fields.One2many(
|
||
'sf.tool.change.requirement.information',
|
||
'tool_change_to_apply_id',
|
||
string='换刀需求信息',
|
||
attrs="{'invisible': 1}")
|
||
|
||
CNC_machine_table = fields.Char(string='CNC机床')
|
||
# todo 机床类型和刀位号 为 Many2one
|
||
machine_table_type = fields.Char(string='机床类型')
|
||
machine_tool_code = fields.Char(string='机台号', attrs="{'invisible': 1}")
|
||
cutter_spacing_code = fields.Char(string='刀位号')
|
||
functional_tool_code = fields.Char(string='功能刀具编码')
|
||
functional_tool_name = fields.Char(string='功能刀具名称')
|
||
# todo 功能刀具类型为 Many2one
|
||
functional_tool_type = fields.Char(string='功能刀具类型')
|
||
diameter = fields.Char(string='直径')
|
||
coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')], string='粗/中/精')
|
||
hilt_name = fields.Char(string='刀柄名称')
|
||
hilt_code = fields.Char(string='刀柄编号')
|
||
max_lifetime_value = fields.Char(string='最大寿命值')
|
||
alarm_value = fields.Char(string='报警值')
|
||
used_value = fields.Char(string='已使用值')
|
||
functional_tool_status = fields.Selection([('正常', '正常'), ('异常', '异常')], string='功能刀具状态', default='正常')
|
||
|
||
replacement_tool_code = fields.Char(string='待换刀具编码')
|
||
replacement_tool_name = fields.Char(string='待换刀具名称')
|
||
replacement_tool_type = fields.Char(string='待换刀具类型')
|
||
replacement_tool_coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')],
|
||
string='粗/中/精')
|
||
new_former = fields.Selection([('0', '新'), ('1', '旧')], string='新/旧')
|
||
applicant = fields.Char(string='申请人')
|
||
used_tool_time = fields.Datetime(string='用刀时间')
|
||
reason_for_applying = fields.Char(string='申请原因')
|
||
remark = fields.Char(string='备注说明')
|
||
|
||
status = fields.Selection([('0', '未操作'), ('1', '已换刀申请'), ('2', '已转移')], string='操作状态', default='0')
|
||
|
||
@api.onchange('functional_tool_status')
|
||
def automation_apply_for_tool_change(self):
|
||
"""
|
||
自动申请换刀
|
||
:return:
|
||
"""
|
||
# 更新数据到机台换刀申请界面
|
||
# todo 换刀申请条件需补充完善
|
||
if(self.functional_tool_status == '异常'):
|
||
self.env['sf.machine.table.tool.changing.apply'].search([
|
||
('CNC_machine_table', '=', self.CNC_machine_table)]).write({
|
||
'replacement_tool_code': self.functional_tool_code,
|
||
'replacement_tool_name': self.functional_tool_name,
|
||
'replacement_tool_type': self.functional_tool_type,
|
||
'replacement_tool_coarse_middle_thin': self.coarse_middle_thin,
|
||
'new_former': '0',
|
||
'applicant': '自动申请',
|
||
'used_tool_time': fields.Datetime.now(),
|
||
'reason_for_applying': '功能刀具状态异常',
|
||
'remark': None,
|
||
'status': '1'
|
||
})
|
||
|
||
# 新建组装任务
|
||
self.env['sf.functional.tool.assembly'].create({
|
||
'functional_tool_code': self.functional_tool_code,
|
||
'functional_tool_name': self.functional_tool_name,
|
||
'functional_tool_type': self.functional_tool_type,
|
||
'functional_tool_diameter': self.diameter,
|
||
'loading_task_source': '1',
|
||
'applicant': self.applicant,
|
||
'reason_for_applying': self.reason_for_applying,
|
||
'use_tool_time': self.used_tool_time,
|
||
'machine_tool_name': self.CNC_machine_table,
|
||
'machine_tool_code': self.machine_tool_code,
|
||
'cutter_spacing_code': self.cutter_spacing_code
|
||
})
|
||
|
||
|
||
|
||
def new_assembly_task(self,vals):
|
||
"""
|
||
新建组装任务
|
||
:param vals:
|
||
:return:
|
||
"""
|
||
# todo 增加设置直径的值
|
||
# tool_changing_apply = self.env['sf.machine.table.tool.changing.apply'].search(
|
||
# [('CNC_machine_table', '=', vals.get('CNC_machine_table'))])
|
||
# for i in tool_changing_apply:
|
||
# print(i)
|
||
# vals['functional_tool_diameter'] = self.diameter
|
||
|
||
self.env['sf.functional.tool.assembly'].create(vals)
|
||
|
||
|
||
def revocation_1(self):
|
||
"""
|
||
换刀申请撤回按键
|
||
:return:
|
||
"""
|
||
# 撤回数据更新
|
||
self.env['sf.machine.table.tool.changing.apply'].search([('CNC_machine_table', '=', self.CNC_machine_table)]).write({
|
||
'replacement_tool_code': None,
|
||
'replacement_tool_name': None,
|
||
'replacement_tool_type': None,
|
||
'replacement_tool_coarse_middle_thin': None,
|
||
'new_former': None,
|
||
'applicant': None,
|
||
'used_tool_time': None,
|
||
'reason_for_applying': None,
|
||
'remark': None,
|
||
'status': '0'
|
||
})
|
||
|
||
# 撤回功能刀具组装创建新任务
|
||
self.env['sf.functional.tool.assembly'].search(
|
||
[('functional_tool_code', '=', self.functional_tool_code)]).unlink()
|
||
|
||
|
||
def revocation_2(self):
|
||
"""
|
||
转移撤回按键
|
||
:return:
|
||
"""
|
||
self.env['sf.machine.table.tool.changing.apply'].search(
|
||
[('CNC_machine_table', '=', self.CNC_machine_table)]).write({
|
||
'status': '0'
|
||
})
|
||
|
||
|
||
class CAMWorkOrderProgramKnifePlan(models.Model):
|
||
_name = 'sf.cam.work.order.program.knife.plan'
|
||
_description = 'CAM工单程序用刀计划'
|
||
|
||
ticket_task_code = fields.Char(string='工单任务编号')
|
||
cam_procedure_code = fields.Char(string='CAM程序编号')
|
||
cam_cutter_spacing_code = fields.Char(string='CAM刀位号')
|
||
functional_tool_code = fields.Char(string='功能刀具编码')
|
||
functional_tool_name = fields.Char(string='功能刀具名称')
|
||
functional_tool_type = fields.Char(string='功能刀具类型')
|
||
machine_table_name = fields.Char(string='机床名称')
|
||
machine_tool_cutter_spacing_code = fields.Char(string='机床刀位号')
|
||
diameter = fields.Char(string='直径(程式)')
|
||
tool_loading_length = fields.Char(string='装刀长')
|
||
clearance_length = fields.Char(string='避空长')
|
||
tool_included_angle = fields.Char(string='刀尖角(R角)')
|
||
L_D = fields.Char(string='L/D')
|
||
coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')], string='粗/中/精')
|
||
required_cutting_time = fields.Char(string='需要切割时间')
|
||
whether_standard_tool = fields.Boolean(string='是否标准刀')
|
||
need_knife_time = fields.Datetime(string='需要用刀时间')
|
||
plan_execute_status = fields.Selection([('0', '待下发'), ('1', '执行中'), ('2', '已完成')], string='计划执行状态')
|
||
applicant = fields.Char(string='申请人')
|
||
reason_for_applying = fields.Char(string='申请原因')
|
||
remark = fields.Char(string='备注说明')
|
||
|
||
def automation_apply_for_tooling(self):
|
||
"""
|
||
todo 自动申请装刀
|
||
:return:
|
||
"""
|
||
|
||
def revocation(self):
|
||
"""
|
||
撤回装刀申请
|
||
:return:
|
||
"""
|
||
self.env['sf.functional.tool.assembly'].search(
|
||
[('functional_tool_code', '=', self.functional_tool_code)]).unlink()
|
||
|
||
# 将计划执行状态改为待执行
|
||
self.env['sf.cam.work.order.program.knife.plan'].search(
|
||
[('functional_tool_code', '=', self.functional_tool_code)]).write({'plan_execute_status': '0'})
|
||
|
||
|
||
|
||
|
||
|
||
class FunctionalToolAssembly(models.Model):
|
||
_name = 'sf.functional.tool.assembly'
|
||
_description = '功能刀具组装'
|
||
|
||
functional_tool_code = fields.Char(string='功能刀具编码')
|
||
functional_tool_name = fields.Char(string='功能刀具名称')
|
||
functional_tool_type = fields.Char(string='功能刀具类型')
|
||
functional_tool_diameter = fields.Char(string='功能刀具直径')
|
||
functional_tool_length = fields.Char(string='功能刀具伸出长')
|
||
functional_tool_cutting_type = fields.Char(string='功能刀具切削类型')
|
||
|
||
tool_name = fields.Char(string='刀具名称')
|
||
tool_brand = fields.Char(string='品牌')
|
||
tool_type = fields.Char(string='型号')
|
||
knife_handle_name = fields.Char(string='刀柄名称')
|
||
knife_handle_brand = fields.Char(string='品牌')
|
||
knife_handle_type = fields.Char(string='型号')
|
||
|
||
coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')], string='粗/中/精')
|
||
tool_loading_length = fields.Char(string='装刀长')
|
||
new_former = fields.Selection([('0', '新'), ('1', '旧')], string='新/旧')
|
||
reference_length = fields.Char(string='参考伸出长')
|
||
cut_time = fields.Char(string='已切削时间')
|
||
cut_length = fields.Char(string='已切削长度')
|
||
cut_number = fields.Char(string='已切削次数')
|
||
|
||
loading_task_source = fields.Selection([('0', 'CAM装刀'), ('1', '机台换刀')], string='装刀任务来源')
|
||
applicant = fields.Char(string='申请人')
|
||
reason_for_applying = fields.Char(string='申请原因')
|
||
apply_time = fields.Datetime(string='申请时间', default=fields.Datetime.now())
|
||
|
||
assemble_status = fields.Selection([('0', '待组装'), ('1', '已组装'), ('2', '已出库')],string='组装状态', default='0')
|
||
use_tool_time = fields.Datetime(string='用刀时间')
|
||
production_line_name = fields.Char(string='产线名称')
|
||
machine_tool_name = fields.Char(string='机床名称')
|
||
machine_tool_code = fields.Char(string='机台号')
|
||
cutter_spacing_code = fields.Char(string='刀位号')
|
||
tool_loading_person = fields.Char(string='装刀人')
|
||
tool_loading_time = fields.Datetime(string='装刀时间')
|
||
receive_person = fields.Char(string='领用人')
|
||
receive_time = fields.Datetime(string='领用出库时间')
|
||
remark = fields.Char(string='备注说明')
|