diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index 36a77191..35f4a257 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -349,67 +349,66 @@ class Sf_Dashboard_Connect(http.Controller): return json.dumps(res) # 日完成量统计 - class DailyFinishCount(http.Controller): - @http.route('/api/DailyFinishCount', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*") - def DailyFinishCount(self, **kw): - """ - 获取日完成量统计 - :param kw: - :return: - """ - res = {'status': 1, 'message': '成功', 'data': {}} - plan_obj = request.env['sf.production.plan'].sudo() - line_list = ast.literal_eval(kw['line_list']) - begin_time_str = kw['begin_time'].strip('"') - end_time_str = kw['end_time'].strip('"') - begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S') - end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S') - print('line_list: %s' % line_list) + @http.route('/api/DailyFinishCount', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*") + def DailyFinishCount(self, **kw): + """ + 获取日完成量统计 + :param kw: + :return: + """ + res = {'status': 1, 'message': '成功', 'data': {}} + plan_obj = request.env['sf.production.plan'].sudo() + line_list = ast.literal_eval(kw['line_list']) + begin_time_str = kw['begin_time'].strip('"') + end_time_str = kw['end_time'].strip('"') + begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S') + end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S') + print('line_list: %s' % line_list) - def get_date_list(start_date, end_date): - date_list = [] - current_date = start_date - while current_date <= end_date: - date_list.append(current_date) - current_date += timedelta(days=1) - return date_list + def get_date_list(start_date, end_date): + date_list = [] + current_date = start_date + while current_date <= end_date: + date_list.append(current_date) + current_date += timedelta(days=1) + return date_list - for line in line_list: - date_list = get_date_list(begin_time, end_time) - order_counts = [] + for line in line_list: + date_list = get_date_list(begin_time, end_time) + order_counts = [] - date_field_name = 'actual_end_time' # 替换为你模型中的实际字段名 + date_field_name = 'actual_end_time' # 替换为你模型中的实际字段名 - for date in date_list: - next_day = date + timedelta(days=1) - orders = plan_obj.search([('production_line_id.name', '=', line), ('state', 'not in', ['draft']), - (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')), - (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00')) - ]) + for date in date_list: + next_day = date + timedelta(days=1) + orders = plan_obj.search([('production_line_id.name', '=', line), ('state', 'in', ['finished']), + (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')), + (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00')) + ]) - rework_orders = plan_obj.search( - [('production_line_id.name', '=', line), ('state', 'in', ['rework']), - (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')), - (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00')) - ]) - not_passed_orders = plan_obj.search( - [('production_line_id.name', '=', line), ('state', 'in', ['scrap', 'cancel']), - (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')), - (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00')) - ]) - order_counts.append({ - 'date': date.strftime('%Y-%m-%d'), - 'order_count': len(orders), - 'rework_orders': len(rework_orders), - 'not_passed_orders': len(not_passed_orders) - }) - # 外面包一层,没什么是包一层不能解决的,包一层就能区分了,类似于包一层div - # 外面包一层的好处是,可以把多个数据结构打包在一起,方便前端处理 + rework_orders = plan_obj.search( + [('production_line_id.name', '=', line), ('production_id.state', 'in', ['rework']), + (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')), + (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00')) + ]) + not_passed_orders = plan_obj.search( + [('production_line_id.name', '=', line), ('production_id.state', 'in', ['scrap', 'cancel']), + (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')), + (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00')) + ]) + order_counts.append({ + 'date': date.strftime('%Y-%m-%d'), + 'order_count': len(orders), + 'rework_orders': len(rework_orders), + 'not_passed_orders': len(not_passed_orders) + }) + # 外面包一层,没什么是包一层不能解决的,包一层就能区分了,类似于包一层div + # 外面包一层的好处是,可以把多个数据结构打包在一起,方便前端处理 - # date_list_dict = {line: order_counts} + # date_list_dict = {line: order_counts} - res['data'][line] = order_counts - return json.dumps(res) + res['data'][line] = order_counts + return json.dumps(res) # 实时产量 @http.route('/api/RealTimeProduct', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*")