|
|
|
|
@ -104,19 +104,15 @@ async def get_all(
|
|
|
|
|
).distinct()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
num_equipments = len((await common['db_session'].execute(query)).scalars().all())
|
|
|
|
|
equipments = (await common['db_session'].execute(query)).scalars().all()
|
|
|
|
|
|
|
|
|
|
material_cost = await get_cm_cost_summary(collector_db=collector_db, last_oh_date=prev_oh_scope.end_date, upcoming_oh_date=overhaul.start_date)
|
|
|
|
|
service_cost = get_service_cost(scope=overhaul.maintenance_type.name, total_equipment=num_equipments)
|
|
|
|
|
service_cost = get_service_cost(scope=overhaul.maintenance_type.name, total_equipment=len(equipments))
|
|
|
|
|
overhaul_cost = await get_oh_cost_summary(collector_db=collector_db, last_oh_date=prev_oh_scope.end_date, upcoming_oh_date=overhaul.start_date)
|
|
|
|
|
|
|
|
|
|
equipments = await search_filter_sort_paginate(model=query, **common)
|
|
|
|
|
data = equipments['items']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
results = []
|
|
|
|
|
|
|
|
|
|
for equipment in data:
|
|
|
|
|
for equipment in equipments:
|
|
|
|
|
if not equipment.master_equipment:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
@ -129,17 +125,35 @@ async def get_all(
|
|
|
|
|
service_cost=equipment.service_cost,
|
|
|
|
|
overhaul_cost=float(oh_cost),
|
|
|
|
|
location_tag=equipment.location_tag,
|
|
|
|
|
equipment_name=equipment.master_equipment.name if equipment.master_equipment else None,
|
|
|
|
|
equipment_name=equipment.master_equipment.name,
|
|
|
|
|
oh_scope=overhaul.maintenance_type.name,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
results.append(res)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Pagination parameters
|
|
|
|
|
page = common.get("page", 1)
|
|
|
|
|
items_per_page = common.get("items_per_page", 10)
|
|
|
|
|
|
|
|
|
|
# Sort by overhaul_cost descending
|
|
|
|
|
results.sort(key=lambda x: x.overhaul_cost, reverse=True)
|
|
|
|
|
|
|
|
|
|
equipments['items'] = results
|
|
|
|
|
# Apply pagination
|
|
|
|
|
start_index = (page - 1) * items_per_page
|
|
|
|
|
end_index = start_index + items_per_page
|
|
|
|
|
paginated_results = results[start_index:end_index]
|
|
|
|
|
|
|
|
|
|
# Build response data
|
|
|
|
|
data = {
|
|
|
|
|
"items": paginated_results,
|
|
|
|
|
"itemsPerPage": items_per_page,
|
|
|
|
|
"page": page,
|
|
|
|
|
"total": len(results),
|
|
|
|
|
"totalPages": (len(results) + items_per_page - 1) // items_per_page,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
return equipments
|
|
|
|
|
|
|
|
|
|
async def get_standard_scope_by_session_id(*, db_session: DbSession, overhaul_session_id: UUID, collector_db: CollectorDbSession):
|
|
|
|
|
overhaul = await get_session(db_session=db_session, overhaul_session_id=overhaul_session_id)
|
|
|
|
|
|