diff --git a/src/maximo/service.py b/src/maximo/service.py index b5192de..4c4d97f 100644 --- a/src/maximo/service.py +++ b/src/maximo/service.py @@ -11,8 +11,8 @@ async def get_cm_cost_summary(collector_db: CollectorDbSession, last_oh_date:dat query = text("""WITH part_costs AS ( SELECT mu.wonum, - SUM(COALESCE(inv.avgcost, po.unit_cost, 0)) AS parts_total_cost - FROM maximo_material_use_transactions mu + SUM(mu.itemqty * COALESCE(inv.avgcost, po.unit_cost, 0)) AS parts_total_cost + FROM maximo_workorder_materials mu LEFT JOIN maximo_inventory inv ON mu.itemnum = inv.itemnum LEFT JOIN ( @@ -91,8 +91,8 @@ async def get_oh_cost_summary(collector_db: CollectorDbSession, last_oh_date:dat WITH part_costs AS ( SELECT mu.wonum, - SUM(COALESCE(inv.avgcost, po.unit_cost, 0)) AS parts_total_cost - FROM maximo_material_use_transactions mu + SUM(mu.itemqty * COALESCE(inv.avgcost, po.unit_cost, 0)) AS parts_total_cost + FROM maximo_workorder_materials mu LEFT JOIN maximo_inventory inv ON mu.itemnum = inv.itemnum LEFT JOIN ( @@ -102,8 +102,8 @@ async def get_oh_cost_summary(collector_db: CollectorDbSession, last_oh_date:dat ) po ON mu.itemnum = po.item_num GROUP BY mu.wonum -) -, wo_costs AS ( +), +wo_costs AS ( SELECT w.wonum, w.asset_location,