|
|
|
|
@ -2,7 +2,7 @@ import os
|
|
|
|
|
import logging
|
|
|
|
|
from typing import Optional, TypedDict, Any
|
|
|
|
|
|
|
|
|
|
from sqlalchemy import Select, Delete, Float, func, cast, String, text, case
|
|
|
|
|
from sqlalchemy import Select, Delete, Float, func, cast, String, text, case, asc, desc
|
|
|
|
|
from sqlalchemy.orm import selectinload
|
|
|
|
|
from sqlalchemy.exc import SQLAlchemyError
|
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
|
@ -395,13 +395,17 @@ async def get_top_10_economic_life(*, db_session: DbSession, common) -> list[Equ
|
|
|
|
|
(current_year - Equipment.minimum_eac_year) >= 0,
|
|
|
|
|
(current_year - Equipment.minimum_eac_year),
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
(Equipment.minimum_eac_year - current_year) >= 0,
|
|
|
|
|
(Equipment.minimum_eac_year - current_year),
|
|
|
|
|
),
|
|
|
|
|
else_=0,
|
|
|
|
|
).label("remaining_life")
|
|
|
|
|
)
|
|
|
|
|
.filter(Equipment.minimum_eac_year != None)
|
|
|
|
|
.filter((Equipment.minimum_eac != None) & (Equipment.minimum_eac != 0))
|
|
|
|
|
# .filter((current_year - Equipment.minimum_eac_year) >= 0)
|
|
|
|
|
.order_by((current_year - Equipment.minimum_eac_year).desc())
|
|
|
|
|
.order_by(desc("remaining_life"))
|
|
|
|
|
.order_by(func.abs(Equipment.minimum_eac).desc())
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@ -427,13 +431,17 @@ async def get_top_10_replacement_priorities(*, db_session: DbSession, common) ->
|
|
|
|
|
(current_year - Equipment.minimum_eac_year) >= 0,
|
|
|
|
|
(current_year - Equipment.minimum_eac_year),
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
(Equipment.minimum_eac_year - current_year) >= 0,
|
|
|
|
|
(Equipment.minimum_eac_year - current_year),
|
|
|
|
|
),
|
|
|
|
|
else_=0,
|
|
|
|
|
).label("remaining_life")
|
|
|
|
|
)
|
|
|
|
|
.filter(Equipment.minimum_eac_year != None)
|
|
|
|
|
.filter((Equipment.minimum_eac != None) & (Equipment.minimum_eac != 0))
|
|
|
|
|
# .filter((current_year - Equipment.minimum_eac_year) >= 0)
|
|
|
|
|
.order_by((current_year - Equipment.minimum_eac_year).asc())
|
|
|
|
|
.order_by(asc("remaining_life"))
|
|
|
|
|
.order_by(func.abs(Equipment.minimum_eac).desc())
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|