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