435 lines
22 KiB
Python
435 lines
22 KiB
Python
from odoo import fields, models, api
|
||
from odoo.exceptions import ValidationError
|
||
|
||
|
||
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('maintenance.equipment', 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)
|
||
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号', readonly=True)
|
||
functional_tool_name_id = fields.Many2one('product.product', string='功能刀具名称', readonly=True)
|
||
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', readonly=True)
|
||
|
||
# replacement_tool_code = fields.Char(string='待换功能刀具编码', readonly=True)
|
||
replacement_tool_name_id = fields.Many2one('product.product', 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:
|
||
"""
|
||
# 将数据更新到机台换刀申请界面
|
||
print('已运行')
|
||
record = self.env['sf.machine.table.tool.changing.apply'].search(
|
||
[('name', '=', self.name.id),
|
||
('machine_tool_code', '=', self.machine_tool_code),
|
||
('cutter_spacing_code', '=', self.cutter_spacing_code),
|
||
])
|
||
print('运行record_1')
|
||
# 功能刀具组装创建新任务(new_assembly_task)
|
||
record_1 = self.env['sf.functional.tool.assembly'].sudo().create({
|
||
'functional_tool_name_id': 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,
|
||
'sf_machine_table_tool_changing_apply_id': record.id,
|
||
})
|
||
print('record_1:', record_1)
|
||
# 封装数据
|
||
desc = {
|
||
'name': self.name.id,
|
||
'assembly_order_code': record_1.assembly_order_code,
|
||
'machine_tool_code': self.machine_tool_code,
|
||
'cutter_spacing_code': self.cutter_spacing_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',
|
||
'sf_functional_tool_assembly_id': record_1.id,
|
||
}
|
||
print('运行record.write(desc):')
|
||
record.write(desc)
|
||
print('运行成功')
|
||
|
||
# 关闭弹出窗口
|
||
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)
|
||
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号', readonly=True)
|
||
functional_tool_name_id = fields.Many2one('product.product', string='功能刀具名称', readonly=True)
|
||
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'
|
||
_inherit = ["barcodes.barcode_events_mixin"]
|
||
_description = '功能刀具组装单'
|
||
|
||
# 功能刀具申请信息
|
||
machine_tool_name_id = fields.Many2one('maintenance.equipment', string='机床名称', readonly=True)
|
||
machine_tool_code = fields.Char(string='机台号', readonly=True)
|
||
cutter_spacing_code = fields.Char(string='刀位号', readonly=True)
|
||
# code = fields.Char(string='功能刀具编码', readonly=True)
|
||
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号', readonly=True)
|
||
functional_tool_name_id = fields.Many2one('product.product', string='功能刀具名称', readonly=True)
|
||
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', readonly=True)
|
||
functional_tool_length = fields.Char(string='功能刀具伸出长(mm)', readonly=True)
|
||
effective_length = fields.Char(string='有效长(mm)', readonly=True)
|
||
functional_tool_diameter = fields.Char(string='功能刀具直径(mm)', 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)
|
||
|
||
# 功能刀具组装信息
|
||
# 整体式刀具型号
|
||
integral_code_id = fields.Many2one('stock.lot', string='整体式刀具序列号',
|
||
domain=[('product_id.cutting_tool_material_id.name', '=', '整体式刀具')])
|
||
cutting_tool_integral_model_id = fields.Many2one('sf.cutting.tool.material', string='整体式刀具型号', readonly=True)
|
||
integral_name = fields.Char('整体式刀具名称', readonly=True)
|
||
sf_tool_brand_id_1 = fields.Many2one('sf.machine.brand', string='整体式刀具品牌', readonly=True)
|
||
|
||
# 刀片型号
|
||
blade_code_id = fields.Many2one('stock.lot', '刀片序列号',
|
||
domain=[('product_id.cutting_tool_material_id.name', '=', '刀片')])
|
||
cutting_tool_blade_model_id = fields.Many2one('sf.cutting.tool.material', string='刀片型号', readonly=True)
|
||
blade_name = fields.Char('刀片名称', readonly=True)
|
||
sf_tool_brand_id_2 = fields.Many2one('sf.machine.brand', '刀片品牌', readonly=True)
|
||
|
||
# 刀杆型号
|
||
bar_code_id = fields.Many2one('stock.lot', '刀杆序列号',
|
||
domain=[('product_id.cutting_tool_material_id.name', '=', '刀杆')])
|
||
cutting_tool_cutterbar_model_id = fields.Many2one('sf.cutting.tool.material', string='刀杆型号', readonly=True)
|
||
bar_name = fields.Char('刀杆名称', readonly=True)
|
||
sf_tool_brand_id_3 = fields.Many2one('sf.machine.brand', '刀杆品牌', readonly=True)
|
||
|
||
# 刀盘型号
|
||
pad_code_id = fields.Many2one('stock.lot', '刀盘序列号',
|
||
domain=[('product_id.cutting_tool_material_id.name', '=', '刀盘')])
|
||
cutting_tool_cutterpad_model_id = fields.Many2one('sf.cutting.tool.material', string='刀盘型号', readonly=True)
|
||
pad_name = fields.Char('刀盘名称', readonly=True)
|
||
sf_tool_brand_id_4 = fields.Many2one('sf.machine.brand', '刀盘品牌', readonly=True)
|
||
|
||
# 刀柄型号
|
||
handle_code_id = fields.Many2one('stock.lot', '刀柄序列号',
|
||
domain=[('product_id.cutting_tool_material_id.name', '=', '刀柄')])
|
||
cutting_tool_cutterhandle_model_id = fields.Many2one('sf.cutting.tool.material', string='刀柄型号', readonly=True)
|
||
handle_name = fields.Char('刀柄名称', readonly=True)
|
||
sf_tool_brand_id_5 = fields.Many2one('sf.machine.brand', '刀柄品牌', readonly=True)
|
||
|
||
# 夹头型号
|
||
chuck_code_id = fields.Many2one('stock.lot', '夹头序列号',
|
||
domain=[('product_id.cutting_tool_material_id.name', '=', '夹头')])
|
||
cutting_tool_cutterhead_model_id = fields.Many2one('sf.cutting.tool.material', string='夹头型号', readonly=True)
|
||
chuck_name = fields.Char('夹头名称', readonly=True, compute='_compute_auto_fill')
|
||
sf_tool_brand_id_6 = fields.Many2one('sf.machine.brand', '夹头品牌', readonly=True)
|
||
|
||
def on_barcode_scanned(self, barcode):
|
||
"""
|
||
智能工厂组装单处扫码绑定刀具物料')
|
||
"""
|
||
for record in self:
|
||
records = record.env['stock.lot'].search([('name', '=', barcode)])
|
||
if not records:
|
||
raise ValidationError('扫描的条形码数据不存在,请重新扫描!')
|
||
for record_stock_lot in records:
|
||
tool_material_name = record_stock_lot.product_id.cutting_tool_material_id.name
|
||
if tool_material_name == '整体式刀具':
|
||
record.integral_code_id = record_stock_lot.id
|
||
elif tool_material_name == '刀片':
|
||
record.blade_code_id = record_stock_lot.id
|
||
elif tool_material_name == '刀杆':
|
||
record.bar_code_id = record_stock_lot.id
|
||
elif tool_material_name == '刀盘':
|
||
record.pad_code_id = record_stock_lot.id
|
||
elif tool_material_name == '刀柄':
|
||
record.handle_code_id = record_stock_lot.id
|
||
elif tool_material_name == '夹头':
|
||
record.chuck_code_id = record_stock_lot.id
|
||
else:
|
||
raise ValidationError('扫描的刀具物料不存在,请重新扫描!')
|
||
|
||
@api.depends('integral_code_id', 'blade_code_id', 'bar_code_id', 'pad_code_id', 'handle_code_id', 'chuck_code_id')
|
||
def _compute_auto_fill(self):
|
||
for record in self:
|
||
if record.integral_code_id:
|
||
record.cutting_tool_integral_model_id = record.integral_code_id.product_id.cutting_tool_material_id.id
|
||
record.integral_name = record.integral_code_id.product_id.name
|
||
record.sf_tool_brand_id_1 = record.integral_code_id.product_id.brand_id.id
|
||
else:
|
||
record.cutting_tool_integral_model_id = None
|
||
record.integral_name = None
|
||
record.sf_tool_brand_id_1 = None
|
||
if record.blade_code_id:
|
||
record.cutting_tool_blade_model_id = record.blade_code_id.product_id.cutting_tool_material_id.id
|
||
record.blade_name = record.blade_code_id.product_id.name
|
||
record.sf_tool_brand_id_2 = record.blade_code_id.product_id.brand_id.id
|
||
else:
|
||
record.cutting_tool_blade_model_id = None
|
||
record.blade_name = None
|
||
record.sf_tool_brand_id_2 = None
|
||
if record.bar_code_id:
|
||
record.cutting_tool_cutterbar_model_id = record.bar_code_id.product_id.cutting_tool_material_id.id
|
||
record.bar_name = record.bar_code_id.product_id.name
|
||
record.sf_tool_brand_id_3 = record.bar_code_id.product_id.brand_id.id
|
||
else:
|
||
record.cutting_tool_cutterbar_model_id = None
|
||
record.bar_name = None
|
||
record.sf_tool_brand_id_3 = None
|
||
if record.pad_code_id:
|
||
record.cutting_tool_cutterpad_model_id = record.pad_code_id.product_id.cutting_tool_material_id.id
|
||
record.pad_name = record.pad_code_id.product_id.name
|
||
record.sf_tool_brand_id_4 = record.pad_code_id.product_id.brand_id.id
|
||
else:
|
||
record.cutting_tool_cutterpad_model_id = None
|
||
record.pad_name = None
|
||
record.sf_tool_brand_id_4 = None
|
||
if record.handle_code_id:
|
||
record.cutting_tool_cutterhandle_model_id = record.handle_code_id.product_id.cutting_tool_material_id.id
|
||
record.handle_name = record.handle_code_id.product_id.name
|
||
record.sf_tool_brand_id_5 = record.handle_code_id.product_id.brand_id.id
|
||
else:
|
||
record.cutting_tool_cutterhandle_model_id = None
|
||
record.handle_name = None
|
||
record.sf_tool_brand_id_5 = None
|
||
if record.chuck_code_id:
|
||
record.cutting_tool_cutterhead_model_id = record.chuck_code_id.product_id.cutting_tool_material_id.id
|
||
record.chuck_name = record.chuck_code_id.product_id.name
|
||
record.sf_tool_brand_id_6 = record.chuck_code_id.product_id.brand_id.id
|
||
else:
|
||
record.cutting_tool_cutterhead_model_id = None
|
||
record.chuck_name = None
|
||
record.sf_tool_brand_id_6 = None
|
||
|
||
coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')], string='粗/中/精', default='1')
|
||
tool_loading_length = fields.Char(string='装刀长')
|
||
new_former = fields.Selection([('0', '新'), ('1', '旧')], string='新/旧', required=True, default='0')
|
||
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:
|
||
"""
|
||
# 创建组装入库单
|
||
# 创建功能刀具批次/序列号记录
|
||
stock_lot = self.create_assemble_warehouse_receipt()
|
||
# 创建刀具组装入库单
|
||
self.create_stocking_picking(stock_lot)
|
||
desc_1 = {
|
||
'barcode_id': stock_lot.id,
|
||
'integral_code_id': self.integral_code_id.id,
|
||
'blade_code_id': self.blade_code_id.id,
|
||
'bar_code_id': self.bar_code_id.id,
|
||
'pad_code_id': self.pad_code_id.id,
|
||
'handle_code_id': self.handle_code_id.id,
|
||
'chuck_code_id': self.chuck_code_id.id,
|
||
'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()
|
||
}
|
||
functional_tool_assembly = self.env['sf.functional.tool.assembly'].search([
|
||
('machine_tool_name_id', '=', self.machine_tool_name_id.id),
|
||
('cutter_spacing_code', '=', self.cutter_spacing_code),
|
||
('assemble_status', '=', '0'),
|
||
])
|
||
# 封装功能刀具数据
|
||
desc_2 = {
|
||
'barcode_id': stock_lot.id,
|
||
'functional_tool_name_id': self.functional_tool_name_id.id,
|
||
'mrs_cutting_tool_type_id': self.functional_tool_type_id.id,
|
||
'cutting_tool_integral_model_id': self.cutting_tool_integral_model_id.id,
|
||
'cutting_tool_blade_model_id': self.cutting_tool_blade_model_id.id,
|
||
'cutting_tool_cutterbar_model_id': self.cutting_tool_cutterbar_model_id.id,
|
||
'cutting_tool_cutterpad_model_id': self.cutting_tool_cutterpad_model_id.id,
|
||
'cutting_tool_cutterhandle_model_id': self.cutting_tool_cutterhandle_model_id.id,
|
||
'cutting_tool_cutterhead_model_id': self.cutting_tool_cutterhead_model_id.id,
|
||
'diameter': self.functional_tool_diameter,
|
||
'tool_grade': None,
|
||
'machining_accuracy': None,
|
||
'tool_length': self.tool_loading_length,
|
||
'blade_number': None,
|
||
'integral_blade_length': None,
|
||
'effective_blade_length': self.effective_length,
|
||
'max_life': None,
|
||
'is_standard': self.whether_standard_tool,
|
||
'applicable_range': None,
|
||
'image': None,
|
||
}
|
||
# 创建功能刀具列表、功能刀具预警、功能刀具实时分布、功能刀具出入库记录
|
||
record_1 = self.env['sf.functional.cutting.tool.entity'].create(desc_2)
|
||
self.env['sf.functional.tool.warning'].create({
|
||
'functional_cutting_tool_id': record_1.id,
|
||
'functional_tool_assembly_id': functional_tool_assembly.id,
|
||
'machine_table_name_id': self.machine_tool_name_id.id,
|
||
})
|
||
self.env['sf.real.time.distribution.of.functional.tools'].create({
|
||
'functional_cutting_tool_id': record_1.id
|
||
})
|
||
self.env['sf.inbound.and.outbound.records.of.functional.tools'].create({
|
||
'functional_cutting_tool_id': record_1.id
|
||
})
|
||
|
||
# 修改功能刀具组装信息
|
||
functional_tool_assembly.write(desc_1)
|
||
|
||
if functional_tool_assembly.sf_machine_table_tool_changing_apply_id:
|
||
# 修改机床换刀申请的状态
|
||
self.env['sf.machine.table.tool.changing.apply'].sudo().search([
|
||
('id', '=', functional_tool_assembly.sf_machine_table_tool_changing_apply_id.id)
|
||
]).write({'status': '3'})
|
||
elif functional_tool_assembly.sf_cam_work_order_program_knife_plan_id:
|
||
# 修改CAM工单程序用刀计划状态
|
||
self.env['sf.cam.work.order.program.knife.plan'].sudo().search([
|
||
('id', '=', functional_tool_assembly.sf_cam_work_order_program_knife_plan_id.id)
|
||
]).write({'plan_execute_status': '2'})
|
||
|
||
# 关闭弹出窗口
|
||
return {'type': 'ir.actions.act_window_close'}
|
||
|
||
def create_stocking_picking(self, stock_lot):
|
||
"""
|
||
创建刀具组装入库单
|
||
"""
|
||
# 获取名称为刀具组装入库的作业类型
|
||
picking_type_id = self.env['stock.picking.type'].sudo().search([('name', '=', '刀具组装入库')])
|
||
# 创建刀具组装入库单
|
||
picking_id = self.env['stock.picking'].create({
|
||
'picking_type_id': picking_type_id.id
|
||
})
|
||
# 创建作业详情对象记录,并绑定到刀具组装入库单
|
||
self.env['stock.move.line'].create({
|
||
'picking_id': picking_id.id,
|
||
'product_id': stock_lot.product_id.id,
|
||
'lot_id': stock_lot.id
|
||
})
|
||
# 将刀具组装入库单的状态更改为就绪
|
||
picking_id.action_confirm()
|
||
|
||
def create_assemble_warehouse_receipt(self):
|
||
"""
|
||
创建功能刀具批次/序列号记录
|
||
"""
|
||
product_id = self.env['product.product'].search([('name', '=', '功能刀具')])
|
||
|
||
stock_lot = self.env['stock.lot'].create({
|
||
'name': self.get_stock_lot_name(),
|
||
'product_id': product_id.id,
|
||
'company_id': self.env.company.id
|
||
})
|
||
# 创建功能刀具该批次/序列号 库存移动和移动历史
|
||
self.create_stock_quant(product_id, stock_lot)
|
||
|
||
return stock_lot
|
||
|
||
def create_stock_quant(self, product_id, stock_lot):
|
||
"""
|
||
创建功能刀具该批次/序列号 库存移动和移动历史
|
||
"""
|
||
# 获取位置对象
|
||
stock_location_id = self.env['stock.location'].search([('name', '=', '组装后')])
|
||
location_inventory_id = self.env['stock.location'].search([('name', '=', 'Inventory adjustment')])
|
||
|
||
# 创建库存移动
|
||
stock_move_id = self.env['stock.move'].create({
|
||
'name': '更新的产品数量',
|
||
'product_id': product_id.id,
|
||
'location_id': location_inventory_id.id,
|
||
'location_dest_id': stock_location_id.id,
|
||
'product_uom_qty': 1.00,
|
||
'state': 'done'
|
||
})
|
||
|
||
# 创建移动历史
|
||
stock_move_line_id = self.env['stock.move.line'].create({
|
||
'product_id': product_id.id,
|
||
'lot_id': stock_lot.id,
|
||
'move_id': stock_move_id.id,
|
||
'qty_done': 1.0,
|
||
'state': 'done'
|
||
})
|
||
|
||
return stock_move_id, stock_move_line_id
|
||
|
||
def get_stock_lot_name(self):
|
||
"""
|
||
生成功能刀具序列号
|
||
"""
|
||
code = 'JKM-T-' + str(self.functional_tool_type_id.code) + '-' + str(self.functional_tool_diameter) + '-'
|
||
new_time = fields.Date.today()
|
||
code += str(new_time) + '-'
|
||
stock_lot_id = self.env['stock.lot'].sudo().search(
|
||
[('name', 'like', new_time), ('product_id.name', '=', '功能刀具')],
|
||
limit=1,
|
||
order="id desc"
|
||
)
|
||
if not stock_lot_id:
|
||
num = "%03d" % 1
|
||
else:
|
||
m = int(stock_lot_id.name[-3:]) + 1
|
||
num = "%03d" % m
|
||
return code + str(num) |