1、重构工单cnc编程用刀校验方法;制造订单、工单、cnc编程单添加刀具状态字段,并且根据cnc编程单刀具状态自动计算制造订单、工单刀具状态字段的值;制造订单form页新增展示功能刀具状态字段;2、功能刀具拆解单刀具物料选择目标货位添加过滤添加为只选择所属货区是刀具房的货位;
This commit is contained in:
@@ -313,42 +313,27 @@ class CAMWorkOrderProgramKnifePlan(models.Model):
|
||||
'applicant': None,
|
||||
'sf_functional_tool_assembly_id': None})
|
||||
|
||||
def create_cam_work_plan(self, cnc_processing_ids):
|
||||
def create_cam_work_plan(self, cnc_processing):
|
||||
"""
|
||||
根据传入的工单信息,查询是否有需要的功能刀具,如果没有则生成CAM工单程序用刀计划
|
||||
"""
|
||||
for cnc_processing in cnc_processing_ids:
|
||||
status = False
|
||||
if cnc_processing.cutting_tool_name:
|
||||
functional_tools = self.env['sf.real.time.distribution.of.functional.tools'].sudo().search(
|
||||
[('name', '=', cnc_processing.cutting_tool_name)])
|
||||
if functional_tools:
|
||||
for functional_tool in functional_tools:
|
||||
if functional_tool.on_tool_stock_num == 0:
|
||||
if functional_tool.tool_stock_num == 0 and functional_tool.side_shelf_num == 0:
|
||||
status = True
|
||||
else:
|
||||
status = True
|
||||
if status:
|
||||
knife_plan = 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_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,
|
||||
})
|
||||
logging.info('CAM工单程序用刀计划创建成功!!!')
|
||||
# 创建装刀请求
|
||||
knife_plan.apply_for_tooling()
|
||||
else:
|
||||
logging.info('功能刀具【%s】满足CNC用刀需求!!!' % cnc_processing.cutting_tool_name)
|
||||
knife_plan = 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_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,
|
||||
})
|
||||
logging.info('CAM工单程序用刀计划创建成功!!!')
|
||||
# 创建装刀请求
|
||||
knife_plan.apply_for_tooling()
|
||||
|
||||
def unlink_cam_plan(self, production):
|
||||
for item in production:
|
||||
@@ -834,7 +819,7 @@ class FunctionalToolDismantle(models.Model):
|
||||
integral_lot_id = fields.Many2one('stock.lot', string='整体式刀具批次', compute='_compute_functional_tool_num',
|
||||
store=True)
|
||||
integral_freight_id = fields.Many2one('sf.shelf.location', '整体式刀具目标货位',
|
||||
domain="[('product_id', 'in', (integral_product_id, False))]")
|
||||
domain="[('product_id', 'in', (integral_product_id, False)),('location_id.name', '=', '刀具房')]")
|
||||
|
||||
# 刀片
|
||||
blade_product_id = fields.Many2one('product.product', string='刀片', compute='_compute_functional_tool_num',
|
||||
@@ -844,7 +829,7 @@ class FunctionalToolDismantle(models.Model):
|
||||
blade_brand_id = fields.Many2one('sf.machine.brand', string='刀片品牌', related='blade_product_id.brand_id')
|
||||
blade_lot_id = fields.Many2one('stock.lot', string='刀片批次', compute='_compute_functional_tool_num', store=True)
|
||||
blade_freight_id = fields.Many2one('sf.shelf.location', '刀片目标货位',
|
||||
domain="[('product_id', 'in', (blade_product_id, False))]")
|
||||
domain="[('product_id', 'in', (blade_product_id, False)),('location_id.name', '=', '刀具房')]")
|
||||
|
||||
# 刀杆
|
||||
bar_product_id = fields.Many2one('product.product', string='刀杆', compute='_compute_functional_tool_num',
|
||||
@@ -854,7 +839,7 @@ class FunctionalToolDismantle(models.Model):
|
||||
bar_brand_id = fields.Many2one('sf.machine.brand', string='刀杆品牌', related='bar_product_id.brand_id')
|
||||
bar_lot_id = fields.Many2one('stock.lot', string='刀杆批次', compute='_compute_functional_tool_num', store=True)
|
||||
bar_freight_id = fields.Many2one('sf.shelf.location', '刀杆目标货位',
|
||||
domain="[('product_id', 'in', (bar_product_id, False))]")
|
||||
domain="[('product_id', 'in', (bar_product_id, False)),('location_id.name', '=', '刀具房')]")
|
||||
|
||||
# 刀盘
|
||||
pad_product_id = fields.Many2one('product.product', string='刀盘', compute='_compute_functional_tool_num',
|
||||
@@ -864,7 +849,7 @@ class FunctionalToolDismantle(models.Model):
|
||||
pad_brand_id = fields.Many2one('sf.machine.brand', string='刀盘品牌', related='pad_product_id.brand_id')
|
||||
pad_lot_id = fields.Many2one('stock.lot', string='刀盘批次', compute='_compute_functional_tool_num', store=True)
|
||||
pad_freight_id = fields.Many2one('sf.shelf.location', '刀盘目标货位',
|
||||
domain="[('product_id', 'in', (pad_product_id, False))]")
|
||||
domain="[('product_id', 'in', (pad_product_id, False)),('location_id.name', '=', '刀具房')]")
|
||||
|
||||
# 夹头
|
||||
chuck_product_id = fields.Many2one('product.product', string='夹头', compute='_compute_functional_tool_num',
|
||||
@@ -874,7 +859,7 @@ class FunctionalToolDismantle(models.Model):
|
||||
chuck_brand_id = fields.Many2one('sf.machine.brand', string='夹头品牌', related='chuck_product_id.brand_id')
|
||||
chuck_lot_id = fields.Many2one('stock.lot', string='夹头批次', compute='_compute_functional_tool_num', store=True)
|
||||
chuck_freight_id = fields.Many2one('sf.shelf.location', '夹头目标货位',
|
||||
domain="[('product_id', 'in', (chuck_product_id, False))]")
|
||||
domain="[('product_id', 'in', (chuck_product_id, False)),('location_id.name', '=', '刀具房')]")
|
||||
|
||||
@api.onchange('functional_tool_id')
|
||||
def _onchange_freight(self):
|
||||
|
||||
@@ -10,6 +10,8 @@ class CNCprocessing(models.Model):
|
||||
_inherit = 'sf.cnc.processing'
|
||||
_description = 'CNC加工用刀检测'
|
||||
|
||||
tool_state = fields.Selection([('0', '正常'), ('1', '缺刀'), ('2', '无效刀')], string='刀具状态', default='0')
|
||||
|
||||
# ==========MES装刀指令接口==========
|
||||
# def register_cnc_processing(self, knife_plan):
|
||||
# config = self.env['res.config.settings'].get_values()
|
||||
@@ -29,13 +31,66 @@ class CNCprocessing(models.Model):
|
||||
# else:
|
||||
# raise ValidationError("MES装刀指令发送失败")
|
||||
|
||||
def cnc_tool_checkout(self, cnc_processing_ids):
|
||||
"""
|
||||
根据传入的工单信息,查询是否有需要的功能刀具,如果没有则生成CAM工单程序用刀计划
|
||||
"""
|
||||
cam_id = self.env['sf.cam.work.order.program.knife.plan']
|
||||
production_ids = [] # 制造订单集
|
||||
datas = {} # 缺刀/无效刀集
|
||||
for cnc_processing in cnc_processing_ids:
|
||||
production_name = cnc_processing.production_id.name # 制造订单
|
||||
processing_panel = cnc_processing.workorder_id.processing_panel # 加工面
|
||||
if not datas.get(production_name):
|
||||
datas.update({production_name: {}})
|
||||
production_ids.append(cnc_processing.production_id)
|
||||
if not datas.get(production_name).get(processing_panel):
|
||||
datas.get(production_name).update({processing_panel: {'缺刀': [], '无效刀': []}})
|
||||
if cnc_processing.cutting_tool_name:
|
||||
tool_name = cnc_processing.cutting_tool_name
|
||||
# 检验CNC用刀是否是功能刀具清单中的刀具
|
||||
tool_inventory_id = self.env['sf.tool.inventory'].sudo().search([('name', '=', tool_name)])
|
||||
if not tool_inventory_id:
|
||||
datas[production_name][processing_panel]['无效刀'].append(cnc_processing.cutting_tool_name)
|
||||
cnc_processing.tool_state = '2'
|
||||
# todo 无效刀处理逻辑
|
||||
|
||||
# 跳过本次循环
|
||||
continue
|
||||
# 校验CNC用刀在系统是否存在
|
||||
functional_tools = self.env['sf.functional.cutting.tool.entity'].sudo().search(
|
||||
[('tool_name_id', '=', tool_inventory_id.id), ('functional_tool_status', '=', '正常')])
|
||||
# 判断线边、机内是否有满足条件的刀
|
||||
if not functional_tools.filtered(lambda p: p.current_location in ('线边刀库', '机内刀库')):
|
||||
datas[production_name][processing_panel]['缺刀'].append(cnc_processing.cutting_tool_name)
|
||||
cnc_processing.tool_state = '1'
|
||||
# 判断是否有满足条件的刀
|
||||
if not functional_tools:
|
||||
# 创建CAM申请装刀记录
|
||||
cam_id.create_cam_work_plan(cnc_processing)
|
||||
logging.info('成功调用CAM工单程序用刀计划创建方法!!!')
|
||||
for production_id in production_ids:
|
||||
if production_id:
|
||||
data = datas.get(production_id.name)
|
||||
tool_state_remark = ''
|
||||
# todo 对无效刀信息进行处理
|
||||
|
||||
# 对缺刀信息进行处理
|
||||
for key in data:
|
||||
if tool_state_remark != '':
|
||||
tool_state_remark = f'{tool_state_remark}\n{key}缺刀:{data.get(key).get("缺刀")}'
|
||||
else:
|
||||
tool_state_remark = f'{key}缺刀:{data.get(key).get("缺刀")}'
|
||||
if production_id.tool_state == '1':
|
||||
production_id.write({
|
||||
'tool_state_remark': tool_state_remark
|
||||
})
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals):
|
||||
obj = super(CNCprocessing, self).create(vals)
|
||||
for item in obj:
|
||||
# 调用CAM工单程序用刀计划创建方法
|
||||
self.env['sf.cam.work.order.program.knife.plan'].create_cam_work_plan(item)
|
||||
logging.info('成功调用CAM工单程序用刀计划创建方法!!!')
|
||||
# 调用CAM工单程序用刀计划创建方法
|
||||
self.cnc_tool_checkout(obj)
|
||||
return obj
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user