diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py
index 59ce68ab..da54f77b 100644
--- a/sf_manufacturing/models/mrp_production.py
+++ b/sf_manufacturing/models/mrp_production.py
@@ -296,8 +296,13 @@ class MrpProduction(models.Model):
# 编程单更新
def update_programming_state(self):
try:
+ manufacturing_type = 'rework'
+ if self.is_scrap:
+ manufacturing_type = 'scrap'
+ elif self.tool_state == '2':
+ manufacturing_type = 'invalid_tool_rework'
res = {'programming_no': self.programming_no,
- 'manufacturing_type': 'rework' if self.is_scrap is False else 'scrap'}
+ 'manufacturing_type': manufacturing_type}
logging.info('res=%s:' % res)
configsettings = self.env['res.config.settings'].get_values()
config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key'])
diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py
index 7f3c3d83..cb56287a 100644
--- a/sf_mrs_connect/controllers/controllers.py
+++ b/sf_mrs_connect/controllers/controllers.py
@@ -25,7 +25,7 @@ class Sf_Mrs_Connect(http.Controller):
ret = json.loads(ret['result'])
logging.info('下发编程单:%s' % ret)
domain = [('programming_no', '=', ret['programming_no'])]
- if ret['manufacturing_type'] == 'scrap':
+ if ret['manufacturing_type'] in ('scrap', 'invalid_tool_rework'):
domain += [('state', 'not in', ['done', 'scrap', 'cancel'])]
productions = request.env['mrp.production'].with_user(
request.env.ref("base.user_admin")).search(domain)
@@ -96,6 +96,14 @@ class Sf_Mrs_Connect(http.Controller):
res.update({
'production_ids': productions.ids
})
+
+ # 对制造订单所以面的cnc工单的程序用刀进行校验
+ try:
+ productions.production_cnc_tool_checkout()
+ except Exception as e:
+ logging.info(f'对cnc工单的程序用刀进行校验报错:{e}')
+ return json.JSONEncoder().encode(res)
+
return json.JSONEncoder().encode(res)
else:
res = {'status': 0, 'message': '该制造订单暂未开始'}
diff --git a/sf_sale/views/sale_order_view.xml b/sf_sale/views/sale_order_view.xml
index 506f5b8d..a5c7a6fa 100644
--- a/sf_sale/views/sale_order_view.xml
+++ b/sf_sale/views/sale_order_view.xml
@@ -17,11 +17,6 @@
-
-
-
+
+
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+
+
+
+
+
+
+
+
1
diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py
index 33ab0790..c6a04196 100644
--- a/sf_tool_management/models/base.py
+++ b/sf_tool_management/models/base.py
@@ -314,37 +314,41 @@ class CAMWorkOrderProgramKnifePlan(models.Model):
'applicant': None,
'sf_functional_tool_assembly_id': None})
- def create_cam_work_plan(self, cnc_processing):
+ def create_cam_work_plan(self, cnc_ids):
"""
根据传入的工单信息,查询是否有需要的功能刀具,如果没有则生成CAM工单程序用刀计划
"""
# 获取编程单号
- programming_no = cnc_processing.workorder_id.production_id.programming_no
+ programming_no = cnc_ids[0].workorder_id.production_id.programming_no
logging.info(f'编程单号:{programming_no}')
- cam_id = self.env['sf.cam.work.order.program.knife.plan'].sudo().search(
- [('programming_no', '=', programming_no),
- ('functional_tool_name', '=', cnc_processing.cutting_tool_name)])
- logging.info(f'CAM装刀计划:{cam_id}')
- if not cam_id:
- knife_plan = self.env['sf.cam.work.order.program.knife.plan'].sudo().create({
- 'name': cnc_processing.workorder_id.production_id.name,
- 'programming_no': programming_no,
- '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()
+ for cnc_processing in cnc_ids:
+ tool_name = cnc_processing.cutting_tool_name
+ cam_id = self.env['sf.cam.work.order.program.knife.plan'].sudo().search(
+ [('programming_no', '=', programming_no),
+ ('functional_tool_name', '=', tool_name)])
+ if cam_id:
+ logging.info(f'编程单号{programming_no}功能刀具名称{tool_name}已存在CAM装刀计划:{cam_id}')
+ else:
+ knife_plan = self.env['sf.cam.work.order.program.knife.plan'].sudo().create({
+ 'name': cnc_processing.workorder_id.production_id.name,
+ 'programming_no': programming_no,
+ 'cam_procedure_code': cnc_processing.program_name,
+ 'filename': cnc_processing.cnc_id.name,
+ 'functional_tool_name': 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(f'创建CAM工单程序用刀计划:{knife_plan}')
+ # 创建装刀请求
+ knife_plan.apply_for_tooling()
+ logging.info('CAM工单程序用刀计划创建已完成!!!')
def unlink_cam_plan(self, production):
for item in production:
diff --git a/sf_tool_management/models/mrp_workorder.py b/sf_tool_management/models/mrp_workorder.py
index ce63c25d..96198cbb 100644
--- a/sf_tool_management/models/mrp_workorder.py
+++ b/sf_tool_management/models/mrp_workorder.py
@@ -29,7 +29,7 @@ class CNCprocessing(models.Model):
# else:
# raise ValidationError("MES装刀指令发送失败")
- def cnc_tool_checkout(self, cnc_processing_ids):
+ def cnc_tool_checkout_1(self, cnc_processing_ids):
"""
根据传入的工单信息,查询是否有需要的功能刀具,如果没有则生成CAM工单程序用刀计划
"""
@@ -128,13 +128,6 @@ class CNCprocessing(models.Model):
})
logging.info('工单cnc程序用刀校验已完成!')
- @api.model_create_multi
- def create(self, vals):
- obj = super(CNCprocessing, self).create(vals)
- # 调用CAM工单程序用刀计划创建方法
- self.cnc_tool_checkout(obj)
- return obj
-
class MrpWorkCenter(models.Model):
_inherit = 'mrp.workcenter'
@@ -143,3 +136,78 @@ class MrpWorkCenter(models.Model):
action = self.env.ref('sf_tool_management.sf_functional_tool_assembly_view_act')
result = action.read()[0]
return result
+
+
+class MrpProduction(models.Model):
+ _inherit = 'mrp.production'
+
+ def production_cnc_tool_checkout(self):
+ logging.info('开始进行工单cnc程序用刀校验!!!')
+ invalid_tool = [] # 无效刀
+ invalid_tool_processing_panel = [] # 无效刀加工面
+ missing_tool_1 = [] # 缺刀(机内、线边)
+ missing_tool_2 = [] # 缺刀(库存)
+ for item in self:
+ workorder_ids = item.workorder_ids.filtered(lambda a: a.state not in ['rework', 'cancel'])
+ for workorder_id in workorder_ids:
+ if workorder_id.cnc_ids:
+ for cnc_id in workorder_id.cnc_ids:
+ tool_name = cnc_id.cutting_tool_name
+ # 查询功能刀具在清单中是否存在
+ tool_inventory_id = self.env['sf.tool.inventory'].sudo().search([('name', '=', tool_name)])
+ if not tool_inventory_id:
+ invalid_tool.append(tool_name)
+ invalid_tool_processing_panel.append(workorder_id.processing_panel)
+ continue
+ # 查询功能刀具是否存在库存
+ 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 ('线边刀库', '机内刀库')):
+ missing_tool_1.append(tool_name) # 判断为 ('线边刀库', '机内刀库') 缺刀
+ if not functional_tools:
+ missing_tool_2.append(tool_name) # 判断为 库存缺刀
+ break
+ # 修改cnc程序的‘刀具状态’
+ workorder_ids = self.env['mrp.workorder'].sudo().search([('production_id', 'in', self.ids)])
+ if invalid_tool:
+ # 修改cnc程序的‘刀具状态’为 ‘无效刀’
+ cnc_ids = self.env['sf.cnc.processing'].sudo().search(
+ [('workorder_id', 'in', workorder_ids.ids), ('cutting_tool_name', 'in', invalid_tool)])
+ if cnc_ids:
+ cnc_ids.write({'tool_state': '2'})
+ # 创建制造订单无效刀检测结果记录
+ for production_id in self:
+ for processing_panel in list(set(invalid_tool_processing_panel)):
+ if not production_id.detection_result_ids.filtered(
+ lambda a: (a.processing_panel == processing_panel and a.detailed_reason == '无效功能刀具'
+ and a.handle_result == '待处理' and a.routing_type == 'CNC加工'
+ and a.rework_reason == 'programming' and a.test_results == '返工')):
+ production_id.detection_result_ids.create({
+ 'production_id': production_id.id,
+ 'processing_panel': processing_panel,
+ 'routing_type': 'CNC加工',
+ 'rework_reason': 'programming', # 原因:编程(programming)
+ 'detailed_reason': '无效功能刀具',
+ 'test_results': '返工',
+ 'handle_result': '待处理'
+ })
+ # 自动调用重新获取编程的方法
+ logging.info('cnc用刀校验到无效刀自动调用重新编程方法:update_programming_state()')
+ self[0].update_programming_state()
+ # 修改制造订单 编程状态变为“编程中”
+ self.write({'programming_state': '编程中', 'work_state': '编程中'})
+ if missing_tool_1:
+ # 修改 修改cnc程序的‘刀具状态’ 为 ‘缺刀’
+ cnc_ids = self.env['sf.cnc.processing'].sudo().search(
+ [('workorder_id', 'in', workorder_ids.ids), ('cutting_tool_name', 'in', missing_tool_1)])
+ if cnc_ids:
+ cnc_ids.write({'tool_state': '1'})
+ if missing_tool_2 and not invalid_tool:
+ # 调用CAM工单程序用刀计划创建方法
+ cnc_ids = self.env['sf.cnc.processing'].sudo().search(
+ [('workorder_id', 'in', workorder_ids.filtered(lambda a: a.production_id == self[0].id).ids),
+ ('cutting_tool_name', 'in', missing_tool_2)])
+ if cnc_ids:
+ logging.info('调用CAM工单程序用刀计划创建方法!!!')
+ self.env['sf.cam.work.order.program.knife.plan'].sudo().create_cam_work_plan(cnc_ids)
+ logging.info('工单cnc程序用刀校验完成!!!')
diff --git a/sf_tool_management/views/functional_tool_views.xml b/sf_tool_management/views/functional_tool_views.xml
index b2e71fb3..2b872053 100644
--- a/sf_tool_management/views/functional_tool_views.xml
+++ b/sf_tool_management/views/functional_tool_views.xml
@@ -10,7 +10,6 @@
-
diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py
index 97ef47e5..371e4a54 100644
--- a/sf_warehouse/models/model.py
+++ b/sf_warehouse/models/model.py
@@ -338,7 +338,7 @@ class ShelfLocation(models.Model):
_name = 'sf.shelf.location'
_inherit = ['printing.utils']
_description = '货位'
- _rec_name = 'barcode'
+ # _rec_name = 'barcode'
_order = 'id asc, create_date asc'
# current_location_id = fields.Many2one('sf.shelf.location', string='当前位置')