|
|
|
|
@ -16,7 +16,8 @@ from src.auth.service import CurrentUser
|
|
|
|
|
from src.database.core import DbSession
|
|
|
|
|
from src.database.service import CommonParameters, search_filter_sort_paginate
|
|
|
|
|
from src.logging import setup_logging
|
|
|
|
|
from src.overhaul_scope.service import get as get_scope
|
|
|
|
|
from src.overhaul_activity.service import get_standard_scope_by_session_id
|
|
|
|
|
from src.overhaul_scope.service import get as get_scope, get_overview_overhaul
|
|
|
|
|
from src.overhaul_scope.service import get_prev_oh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -26,7 +27,7 @@ setup_logging(logger=log)
|
|
|
|
|
from sqlalchemy import text
|
|
|
|
|
import math
|
|
|
|
|
|
|
|
|
|
async def get_spareparts_paginated(db_session):
|
|
|
|
|
async def get_spareparts_paginated(*, db_session, collector_db_session):
|
|
|
|
|
"""
|
|
|
|
|
Get paginated spare parts with usage, inventory, and PR/PO information.
|
|
|
|
|
Uses two queries: one for data, one for total count.
|
|
|
|
|
@ -51,6 +52,7 @@ async def get_spareparts_paginated(db_session):
|
|
|
|
|
AND asset_location IS NOT NULL
|
|
|
|
|
AND EXTRACT(YEAR FROM reportdate) >= 2019
|
|
|
|
|
AND asset_unit IN ('3', '00')
|
|
|
|
|
AND asset_location = ANY(:asset_locations)
|
|
|
|
|
),
|
|
|
|
|
sparepart_usage AS (
|
|
|
|
|
SELECT oh.asset_location, mwm.itemnum, mwm.itemqty, mwm.wonum
|
|
|
|
|
@ -169,8 +171,17 @@ async def get_spareparts_paginated(db_session):
|
|
|
|
|
LEFT JOIN pr_po_agg ap ON lss.itemnum = ap.item_num
|
|
|
|
|
ORDER BY lss.asset_location, lss.itemnum
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
overhaul = await get_overview_overhaul(db_session=db_session)
|
|
|
|
|
|
|
|
|
|
standard_overhaul = await get_standard_scope_by_session_id(db_session=db_session, collector_db=collector_db_session, overhaul_session_id=overhaul['overhaul']['id'])
|
|
|
|
|
|
|
|
|
|
asset_locations = [eq.location_tag for eq in standard_overhaul]
|
|
|
|
|
|
|
|
|
|
rows = await db_session.execute(data_query)
|
|
|
|
|
rows = await collector_db_session.execute(
|
|
|
|
|
data_query,
|
|
|
|
|
{"asset_locations": asset_locations}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
spare_parts = []
|
|
|
|
|
for row in rows:
|
|
|
|
|
|