210 lines
10 KiB
Python
210 lines
10 KiB
Python
from odoo import fields, models
|
||
|
||
|
||
class ToolChangeRequirementInformation(models.TransientModel):
|
||
_name = 'sf.tool.change.requirement.information'
|
||
_description = '换刀需求信息'
|
||
|
||
# tool_change_to_apply_id = fields.Many2one('sf.machine.table.tool.changing.apply', string='机床换刀申请')
|
||
|
||
name = fields.Many2one('sf.machine_tool', string='CNC机床', readonly=True)
|
||
machine_tool_code = fields.Char(string='机台号', readonly=True)
|
||
cutter_spacing_code = fields.Char(string='刀位号', readonly=True)
|
||
|
||
replacement_tool_code = fields.Char(string='待换刀具编码')
|
||
replacement_tool_name_id = fields.Many2one('sf.functional.cutting.tool', string='待换刀具名称')
|
||
replacement_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='待换刀具类型')
|
||
replacement_tool_coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')],
|
||
string='粗/中/精')
|
||
new_former = fields.Selection([('0', '新'), ('1', '旧')], string='新/旧')
|
||
applicant = fields.Char(string='申请人', default=lambda self: self.env.user.name, readonly=True)
|
||
used_tool_time = fields.Datetime(string='用刀时间')
|
||
reason_for_applying = fields.Char(string='申请原因')
|
||
remark = fields.Char(string='备注说明')
|
||
|
||
def tool_changing_apply(self):
|
||
"""
|
||
确认换刀申请(按键)
|
||
:return:
|
||
"""
|
||
# 封装数据
|
||
desc = {
|
||
'name': self.name.id,
|
||
'machine_tool_code': self.machine_tool_code,
|
||
'cutter_spacing_code': self.cutter_spacing_code,
|
||
'replacement_tool_code': self.replacement_tool_code,
|
||
'replacement_tool_name_id': self.replacement_tool_name_id.id,
|
||
'replacement_tool_type_id': self.replacement_tool_type_id.id,
|
||
'replacement_tool_coarse_middle_thin': self.replacement_tool_coarse_middle_thin,
|
||
'new_former': self.new_former,
|
||
'applicant': self.applicant,
|
||
'used_tool_time': self.used_tool_time,
|
||
'reason_for_applying': self.reason_for_applying,
|
||
'remark': self.new_former,
|
||
'status': '1'
|
||
}
|
||
print('desc:', desc)
|
||
# 将数据更新到机台换刀申请界面
|
||
self.env['sf.machine.table.tool.changing.apply'].search(
|
||
[('name', '=', desc.get('name'))]).write(desc)
|
||
|
||
# 功能刀具组装创建新任务
|
||
self.env['sf.machine.table.tool.changing.apply'].new_assembly_task({
|
||
'functional_tool_code': self.replacement_tool_code,
|
||
'name': self.replacement_tool_name_id.id,
|
||
'functional_tool_type_id': self.replacement_tool_type_id.id,
|
||
'loading_task_source': '1',
|
||
'applicant': self.applicant,
|
||
'reason_for_applying': self.reason_for_applying,
|
||
'use_tool_time': self.used_tool_time,
|
||
'machine_tool_name_id': self.name.id,
|
||
'machine_tool_code': self.machine_tool_code,
|
||
'cutter_spacing_code': self.cutter_spacing_code
|
||
})
|
||
|
||
# 关闭弹出窗口
|
||
return {'type': 'ir.actions.act_window_close'}
|
||
|
||
|
||
class ToolTransferRequestInformation(models.TransientModel):
|
||
_name = 'sf.tool.transfer.request.information'
|
||
_description = '刀具转移申请信息'
|
||
|
||
CNC_machine_table_id = fields.Many2one('sf.machine_tool', string='CNC机床', readonly=True)
|
||
machine_tool_code = fields.Char(string='机台号', readonly=True)
|
||
cutter_spacing_code = fields.Char(string='刀位号', readonly=True)
|
||
functional_tool_code = fields.Char(string='功能刀具编码', readonly=True)
|
||
functional_tool_name_id = fields.Many2one('sf.functional.cutting.tool', string='功能刀具名称', readonly=True)
|
||
# todo 功能刀具类型为 Many2one
|
||
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', readonly=True)
|
||
transfer_target = fields.Selection([('机台', '机台'),
|
||
('线边刀库', '线边刀库'),
|
||
('刀具房', '刀具房')], string='转移到:', default='线边刀库')
|
||
|
||
new_cnc_machine_table_id = fields.Many2one('sf.machine_tool', string='机床名称')
|
||
new_machine_tool_code = fields.Char(string='机床号')
|
||
new_cutter_spacing_code = fields.Char(string='刀位号')
|
||
|
||
magazine_tool_warehouse_district = fields.Char(string='库区')
|
||
magazine_tool_warehouse_position = fields.Char(string='库位')
|
||
|
||
tool_room_warehouse_district = fields.Char(string='库区')
|
||
tool_room_warehouse_position = fields.Char(string='库位')
|
||
|
||
def tool_transfer_apply(self):
|
||
"""
|
||
todo 刀具转移申请信息确定按钮
|
||
:return:
|
||
"""
|
||
self.env['sf.machine.table.tool.changing.apply'].search(
|
||
[('name', '=', self.CNC_machine_table_id.id)]).write({'status': '2'})
|
||
|
||
|
||
class FunctionalToolAssemblyOrder(models.TransientModel):
|
||
_name = 'sf.functional.tool.assembly.order'
|
||
_description = '功能刀具组装单'
|
||
|
||
# 功能刀具申请信息
|
||
machine_tool_name_id = fields.Many2one('sf.machine_tool', string='机床名称', readonly=True)
|
||
cutter_spacing_code = fields.Char(string='刀位号', readonly=True)
|
||
functional_tool_name_id = fields.Many2one('sf.functional.cutting.tool', string='功能刀具名称', readonly=True)
|
||
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', readonly=True)
|
||
functional_tool_length = fields.Char(string='功能刀具伸出长', readonly=True)
|
||
effective_length = fields.Char(string='有效长', readonly=True)
|
||
functional_tool_diameter = fields.Char(string='功能刀具直径', readonly=True)
|
||
tool_included_angle = fields.Char(string='刀尖角(R角)', readonly=True)
|
||
functional_tool_cutting_type = fields.Char(string='功能刀具切削类型', readonly=True)
|
||
required_cutting_time = fields.Char(string='需要切割时间', readonly=True)
|
||
whether_standard_tool = fields.Boolean(string='是否标准刀', readonly=True)
|
||
|
||
# 功能刀具组装信息
|
||
tool_name = fields.Char(string='刀具名称')
|
||
tool_code = fields.Char(string='刀具编码')
|
||
tool_brand = fields.Char(string='品牌')
|
||
tool_type = fields.Char(string='型号')
|
||
knife_handle_name = fields.Char(string='刀柄名称')
|
||
knife_handle_code = 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='已切削次数')
|
||
|
||
def functional_tool_assembly(self):
|
||
"""
|
||
功能刀具组装
|
||
:return:
|
||
"""
|
||
self.env['sf.functional.tool.assembly'].search([
|
||
('machine_tool_name_id', '=', self.machine_tool_name_id.id),
|
||
('cutter_spacing_code', '=', self.cutter_spacing_code)
|
||
]).write({
|
||
'tool_name': self.tool_name,
|
||
'tool_brand': self.tool_brand,
|
||
'tool_type': self.tool_type,
|
||
'knife_handle_name': self.knife_handle_name,
|
||
'knife_handle_brand': self.knife_handle_brand,
|
||
'knife_handle_type': self.knife_handle_type,
|
||
'coarse_middle_thin': self.coarse_middle_thin,
|
||
'tool_loading_length': self.tool_loading_length,
|
||
'new_former': self.new_former,
|
||
'reference_length': self.reference_length,
|
||
'cut_time': self.cut_time,
|
||
'cut_length': self.cut_length,
|
||
'cut_number': self.cut_number,
|
||
'assemble_status': '1',
|
||
'tool_loading_person': self.env.user.name,
|
||
'tool_loading_time': fields.Datetime.now()
|
||
})
|
||
|
||
# 关闭弹出窗口
|
||
return {'type': 'ir.actions.act_window_close'}
|
||
|
||
|
||
class DeliveryOfCargoFromStorage(models.TransientModel):
|
||
_name = 'sf.delivery.of.cargo.from.storage'
|
||
_description = '出库'
|
||
|
||
order = fields.Integer(string='序')
|
||
functional_tool_code = fields.Char(string='功能刀具编码')
|
||
name = fields.Many2one('sf.functional.cutting.tool', string='功能刀具名称')
|
||
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型')
|
||
production_line_name = fields.Char(string='产线名称')
|
||
machine_tool_code = fields.Char(string='机台号')
|
||
receive_person = fields.Char(string='领用人')
|
||
receive_time = fields.Datetime(string='领用出库时间')
|
||
|
||
def stock_removal(self):
|
||
"""
|
||
出库
|
||
:return:
|
||
"""
|
||
vals = self.env['sf.delivery.of.cargo.from.storage'].search([])
|
||
if vals:
|
||
for val in vals:
|
||
self.env['sf.functional.tool.assembly'].search([
|
||
('functional_tool_code', '=', val.functional_tool_code),
|
||
('name', '=', val.name.id)
|
||
]).write({
|
||
'assemble_status': '2',
|
||
'receive_person': self.env.user.name,
|
||
'receive_time': fields.Datetime.now()
|
||
})
|
||
|
||
tool_assembly = self.env['sf.functional.tool.assembly'].search([
|
||
('functional_tool_code', '=', val.functional_tool_code),
|
||
('name', '=', val.name.id)
|
||
])
|
||
# 判断装刀任务来源,如果来源于CAM装刀,则修改CAM装刀的计划执行状态
|
||
if tool_assembly.loading_task_source == '0':
|
||
self.env['sf.cam.work.order.program.knife.plan'].search([
|
||
('functional_tool_code', '=', val.functional_tool_code),
|
||
('functional_tool_name_id', '=', val.name.id)
|
||
]).write({
|
||
'plan_execute_status': '2'
|
||
})
|