fix spareparts

main
Cizz22 3 months ago
parent 681ab03438
commit 82e4a466f0

@ -84,12 +84,12 @@ async def get_calculation_parameters(
@router.get(
"/{calculation_id}", response_model=StandardResponse[CalculationTimeConstrainsRead]
)
async def get_calculation_results(db_session: DbSession, calculation_id, token:Token):
async def get_calculation_results(db_session: DbSession, calculation_id, collector_db_session:CollectorDbSession):
if calculation_id == 'default':
calculation_id = "3b9a73a2-bde6-418c-9e2f-19046f501a05"
results = await get_calculation_result(
db_session=db_session, calculation_id=calculation_id, token=token
db_session=db_session, calculation_id=calculation_id, collector_db_session=collector_db_session
)
return StandardResponse(

@ -15,7 +15,7 @@ from src.database.core import DbSession
from src.logging import setup_logging
from src.overhaul_activity.service import get_all as get_all_by_session_id
from src.overhaul_scope.service import get as get_scope, get_prev_oh
from src.sparepart.service import load_sparepart_data_from_db
from src.sparepart.service import get_spareparts_paginated, load_sparepart_data_from_db
from src.utils import get_latest_numOfFail
from src.workorder.model import MasterWorkOrder
from src.sparepart.model import MasterSparePart
@ -754,7 +754,7 @@ async def create_param_and_data(
return calculationData
async def get_calculation_result(db_session: DbSession, calculation_id: str, token):
async def get_calculation_result(db_session: DbSession, calculation_id: str, collector_db_session):
"""
Get calculation results with improved error handling, performance, and sparepart details
"""
@ -798,6 +798,7 @@ async def get_calculation_result(db_session: DbSession, calculation_id: str, tok
# Filter included equipment for performance
included_equipment = [eq for eq in scope_calculation.equipment_results if eq.is_included]
all_equipment = scope_calculation.equipment_results
all_spareparts = await get_spareparts_paginated(db_session=db_session, collector_db_session=collector_db_session )
# Pre-calculate aggregated statistics
calculation_results = []
@ -807,7 +808,8 @@ async def get_calculation_result(db_session: DbSession, calculation_id: str, tok
'excluded_equipment': len(all_equipment) - len(included_equipment),
'equipment_with_sparepart_constraints': 0,
'total_procurement_items': 0,
'critical_procurement_items': 0
'critical_procurement_items': 0,
'total_spareparts': len(all_spareparts)
}
# The code `plant_monthly_metrics` is likely a function or a variable in Python. Without

@ -11,10 +11,10 @@ router = APIRouter()
@router.get("", response_model=StandardResponse[list])
async def get_sparepart(collector_db_session:CollectorDbSession):
async def get_sparepart(collector_db_session:CollectorDbSession, db_session: DbSession):
"""Get all scope activity pagination."""
# return
data = await get_spareparts_paginated(collector_db_session)
data = await get_spareparts_paginated(db_session=db_session, collector_db_session=collector_db_session)

@ -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:

Loading…
Cancel
Save