|
|
|
|
@ -121,9 +121,15 @@ async def get_top_10_economic_life(*, db_session: DbSession) -> list[Equipment]:
|
|
|
|
|
|
|
|
|
|
# Order by difference between current year and minimum_year
|
|
|
|
|
# Add absolute difference between current year and minimum_eac_year as a new column
|
|
|
|
|
query = query.add_columns(
|
|
|
|
|
# Filter out rows where minimum_eac_year is null and limit to 10 results
|
|
|
|
|
query = (
|
|
|
|
|
query.add_columns(
|
|
|
|
|
func.abs(current_year - Equipment.minimum_eac_year).label("economic_life")
|
|
|
|
|
).order_by(func.abs(current_year - Equipment.minimum_eac_year).desc())
|
|
|
|
|
)
|
|
|
|
|
.filter(Equipment.minimum_eac_year != None)
|
|
|
|
|
.order_by(func.abs(current_year - Equipment.minimum_eac_year).desc())
|
|
|
|
|
.limit(10)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
result = await db_session.execute(query)
|
|
|
|
|
|
|
|
|
|
|