From 4b4601ae8529407970ea3e4b8e68fa31229faaa2 Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Wed, 16 Oct 2024 17:29:25 +0800 Subject: [PATCH] =?UTF-8?q?CNC=E8=87=AA=E5=8A=A8=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E7=BA=BF=E7=94=9F=E4=BA=A7=E4=B8=9A=E7=BB=A9=E7=9C=8B=E6=9D=BF?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=9C=80=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_machine_connect/controllers/controllers.py | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index a65e97ef..ada159ec 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -402,20 +402,45 @@ class Sf_Dashboard_Connect(http.Controller): try: plan_obj = request.env['sf.production.plan'].sudo() production_obj = request.env['mrp.production'].sudo() + work_order_obj = request.env['mrp.workorder'].sudo() line_list = ast.literal_eval(kw['line_list']) # print('line_list: %s' % line_list) for line in line_list: - # 工单计划量 - plan_data_total_counts = production_obj.search_count( - [('production_line_id.name', '=', line), ('state', 'not in', ['cancel']), - ('active', '=', True)]) - # 工单完成量 - plan_data_finish_counts = plan_obj.search_count( - [('production_line_id.name', '=', line), ('state', 'in', ['finished'])]) # # 工单计划量 - # plan_data_plan_counts = plan_obj.search_count( - # [('production_line_id.name', '=', line), ('state', 'not in', ['finished'])]) + # plan_data_total_counts = production_obj.search_count( + # [('production_line_id.name', '=', line), ('state', 'not in', ['cancel']), + # ('active', '=', True)]) + + # 工单计划量切换为CNC工单 + plan_data_total_counts = work_order_obj.search_count( + [('production_id.production_line_id.name', '=', line), + ('state', 'in', ['ready', 'progress', 'done']), ('routing_type', '=', 'CNC加工')]) + + # # 工单完成量 + # plan_data_finish_counts = plan_obj.search_count( + # [('production_line_id.name', '=', line), ('state', 'in', ['finished'])]) + + # 工单完成量切换为CNC工单 + plan_data_finish_counts = work_order_obj.search_count( + [('production_id.production_line_id.name', '=', line), + ('state', 'in', ['done']), ('routing_type', '=', 'CNC加工')]) + + # 超期完成量 + # 搜索所有已经完成的工单 + plan_data_overtime = work_order_obj.search([ + ('production_id.production_line_id.name', '=', line), + ('state', 'in', ['done']), + ('routing_type', '=', 'CNC加工') + ]) + + # 使用 filtered 进行字段比较 + plan_data_overtime_counts = plan_data_overtime.filtered( + lambda order: order.date_finished > order.date_planned_finished + ) + + # 获取数量 + plan_data_overtime_counts = len(plan_data_overtime_counts) # 查找符合条件的生产计划记录 plan_data = plan_obj.search([ @@ -517,7 +542,10 @@ class Sf_Dashboard_Connect(http.Controller): 'on_time_rate': on_time_rate, # 'detection_data': detection_data, 'detection_data': plan_data_finish_counts, - 'pass_rate': (plan_data_finish_counts - plan_data_fault_counts) / plan_data_finish_counts + 'pass_rate': (plan_data_finish_counts - plan_data_fault_counts) / plan_data_finish_counts, + 'plan_data_overtime_counts': plan_data_overtime_counts, + 'overtime_rate': plan_data_overtime_counts / plan_data_finish_counts + if plan_data_finish_counts > 0 else 0, } res['data'][line] = data