diff --git a/src/equipment_sparepart/service.py b/src/equipment_sparepart/service.py index 0248b47..1ec2ab4 100644 --- a/src/equipment_sparepart/service.py +++ b/src/equipment_sparepart/service.py @@ -156,11 +156,9 @@ async def get_all( # Build query dynamically query_str = """ WITH filtered_wo AS ( - SELECT - wonum, - asset_location - FROM public.wo_staging_maximo_2 - WHERE worktype = 'OH' + SELECT DISTINCT wonum, asset_location, asset_unit + FROM public.wo_maximo ma + WHERE ma.xx_parent IN ('155026', '155027', '155029', '155030') """ params = {} @@ -177,11 +175,9 @@ async def get_all( mat.wonum, mat.itemnum, mat.itemqty, - inv.curbaltotal AS inv_curbaltotal, - inv.avgcost AS inv_avgcost - FROM public.maximo_workorder_materials AS mat - LEFT JOIN public.maximo_inventory AS inv - ON inv.itemnum = mat.itemnum + mat.inv_curbaltotal AS inv_curbaltotal, + mat.inv_avgcost AS inv_avgcost + FROM public.wo_maximo_material AS mat WHERE mat.wonum IN (SELECT wonum FROM filtered_wo) ) SELECT diff --git a/src/sparepart/service.py b/src/sparepart/service.py index f5c164b..a58c84d 100644 --- a/src/sparepart/service.py +++ b/src/sparepart/service.py @@ -234,24 +234,19 @@ async def get_spareparts_paginated(*, db_session, collector_db_session): data_query = text(""" WITH oh_workorders AS ( SELECT DISTINCT wonum, asset_location, asset_unit - FROM public.wo_staging_maximo_2 - WHERE worktype = 'OH' - AND asset_location IS NOT NULL - AND EXTRACT(YEAR FROM reportdate) >= 2019 - AND asset_unit IN ('3', '00') - ), + FROM public.wo_maximo ma + WHERE ma.xx_parent IN ('155026', '155027', '155029', '155030') + ), wo_materials AS ( SELECT wm.wonum, wm.itemnum, wm.itemqty, - inv.itemnum AS inv_itemnum, - inv.location AS inv_location, - inv.curbaltotal AS inv_curbaltotal, - inv.avgcost AS inv_avgcost, + wm.inv_location AS inv_location, + wm.inv_curbaltotal AS inv_curbaltotal, + wm.inv_avgcost AS inv_avgcost, sw.asset_location as location_tag - FROM public.maximo_workorder_materials wm - JOIN maximo_inventory inv ON inv.itemnum = wm.itemnum + FROM public.wo_maximo_material wm JOIN oh_workorders sw ON wm.wonum = sw.wonum ), location_sparepart_stats AS (