修改大屏数据接口,日完成量统计,获取产线产量相关,获取工单明细

This commit is contained in:
胡尧
2025-06-19 15:02:55 +08:00
parent d21e0c7fd9
commit 55cc4906ef

View File

@@ -635,6 +635,8 @@ class Sf_Dashboard_Connect(http.Controller):
return date_list return date_list
if time_unit == 'hour':
for line in line_list: for line in line_list:
date_field_name = 'date_finished' # 替换为你模型中的实际字段名 date_field_name = 'date_finished' # 替换为你模型中的实际字段名
order_counts = [] order_counts = []
@@ -648,12 +650,17 @@ class Sf_Dashboard_Connect(http.Controller):
('production_line_id.name', '=', line), ('production_line_id.name', '=', line),
('routing_type', '=', 'CNC加工') ('routing_type', '=', 'CNC加工')
] ]
if time_unit == 'hour':
time_intervals = get_time_intervals(begin_time, end_time, time_unit) time_intervals = get_time_intervals(begin_time, end_time, time_unit)
print('============================= %s' % time_intervals) print('============================= %s' % time_intervals)
time_count_dict = {} time_count_dict = {}
plan_count_dict = {}
orders = request.env['mrp.workorder'].sudo().search(work_order_domain + [
('state', 'in', ['done']),
(date_field_name, '>=', begin_time.strftime('%Y-%m-%d %H:%M:%S')),
(date_field_name, '<=', end_time.strftime('%Y-%m-%d %H:%M:%S'))
])
for time_interval in time_intervals: for time_interval in time_intervals:
start_time, end_time = time_interval start_time, end_time = time_interval
@@ -665,22 +672,73 @@ class Sf_Dashboard_Connect(http.Controller):
# (date_field_name, '<=', end_time.strftime('%Y-%m-%d %H:%M:%S')) # 包括结束时间 # (date_field_name, '<=', end_time.strftime('%Y-%m-%d %H:%M:%S')) # 包括结束时间
# ]) # ])
orders = request.env['mrp.workorder'].sudo().search(work_order_domain + [ interval_orders = orders.filtered(
('state', 'in', ['done']), lambda o: o[date_field_name] >= start_time
(date_field_name, '>=', start_time.strftime('%Y-%m-%d %H:%M:%S')), and o[date_field_name] <= end_time
(date_field_name, '<=', end_time.strftime('%Y-%m-%d %H:%M:%S')) )
])
# 使用小时和分钟作为键,确保每个小时的数据有独立的键 # 使用小时和分钟作为键,确保每个小时的数据有独立的键
key = start_time.strftime('%H:%M:%S') # 只取小时:分钟:秒作为键 key = start_time.strftime('%H:%M:%S') # 只取小时:分钟:秒作为键
# time_count_dict[key] = len(orders) # time_count_dict[key] = len(orders)
time_count_dict[key] = sum(orders.mapped('qty_produced')) time_count_dict[key] = sum(interval_orders.mapped('qty_produced'))
# 计划量目前只能从mail.message中筛选出
plan_order_messages = request.env['mail.message'].sudo().search([
('model', '=', 'mrp.workorder'),
('create_date', '>=', begin_time.strftime('%Y-%m-%d %H:%M:%S')),
('create_date', '<=', end_time.strftime('%Y-%m-%d %H:%M:%S')),
('tracking_value_ids.field_desc', '=', '状态'),
('tracking_value_ids.new_value_char', '=', '就绪')
])
for time_interval in time_intervals:
start_time, end_time = time_interval
# orders = plan_obj.search([
# ('production_line_id.name', '=', line),
# ('state', 'in', ['done']),
# (date_field_name, '>=', start_time.strftime('%Y-%m-%d %H:%M:%S')),
# (date_field_name, '<=', end_time.strftime('%Y-%m-%d %H:%M:%S')) # 包括结束时间
# ])
interval_plan_orders = plan_order_messages.filtered(
lambda o: o.create_date >= start_time
and o.create_date <= end_time
)
interval_orders = request.env['mrp.workorder'].sudo().browse(interval_plan_orders.mapped('res_id'))
if line == '业绩总览':
interval_orders = interval_orders.filtered(lambda o: o.routing_type in ['人工线下加工', 'CNC加工'])
elif line == '人工线下加工中心':
interval_orders = interval_orders.filtered(lambda o: o.routing_type == '人工线下加工')
else:
interval_orders = interval_orders.filtered(lambda o: o.routing_type == 'CNC加工' and o.production_line_id.name == line)
# 使用小时和分钟作为键,确保每个小时的数据有独立的键
key = start_time.strftime('%H:%M:%S') # 只取小时:分钟:秒作为键
# time_count_dict[key] = len(orders)
plan_count_dict[key] = sum(interval_orders.mapped('qty_produced'))
# order_counts.append() # order_counts.append()
res['data'][line] = { res['data'][line] = {
'finish_order_nums': time_count_dict, 'finish_order_nums': time_count_dict,
'plan_order_nums': 28 'plan_order_nums': plan_count_dict
} }
return json.dumps(res) else:
for line in line_list:
date_field_name = 'date_finished' # 替换为你模型中的实际字段名
order_counts = []
if line == '业绩总览':
work_order_domain = [('routing_type', 'in', ['人工线下加工', 'CNC加工'])]
elif line == '人工线下加工中心':
work_order_domain = [('routing_type', '=', '人工线下加工')]
else:
work_order_domain = [
('production_line_id.name', '=', line),
('routing_type', '=', 'CNC加工')
]
date_list = get_date_list(begin_time, end_time) date_list = get_date_list(begin_time, end_time)
@@ -799,7 +857,7 @@ class Sf_Dashboard_Connect(http.Controller):
:param kw: :param kw:
:return: :return:
""" """
request.env['stock.warehouse'].browse(request.env.company.id).pbm_loc_id
# res = {'status': 1, 'message': '成功', 'not_done_data': [], 'done_data': []} # res = {'status': 1, 'message': '成功', 'not_done_data': [], 'done_data': []}
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()