From bd6efc2a3a660ce865488770ca803025af7dda10 Mon Sep 17 00:00:00 2001 From: MrWaradana Date: Tue, 6 Jan 2026 11:20:13 +0700 Subject: [PATCH] feat: Add `get_where_query_sql_labour_cost` to filter out 'T' wonums and update `get_yearly_labour_cost_total_by_worktype` to use it. --- src/modules/equipment/insert_actual_data.py | 4 ++-- src/modules/equipment/where_query_sql.py | 24 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/modules/equipment/insert_actual_data.py b/src/modules/equipment/insert_actual_data.py index a2b16d5..de5314f 100644 --- a/src/modules/equipment/insert_actual_data.py +++ b/src/modules/equipment/insert_actual_data.py @@ -9,7 +9,7 @@ import sys import os import httpx from src.modules.config import get_connection, get_production_connection -from .where_query_sql import get_where_query_sql +from .where_query_sql import get_where_query_sql, get_where_query_sql_labour_cost async def fetch_api_data( assetnum: str, year: int, RELIABILITY_APP_URL: str, token: str @@ -133,7 +133,7 @@ def get_labour_cost_totals(cursor, assetnum: str, worktype: str) -> dict: """Return yearly labor cost totals for a worktype using the standardized query.""" if not assetnum or not worktype: return {} - where_query = get_where_query_sql(assetnum, worktype) + where_query = get_where_query_sql_labour_cost(assetnum, worktype) query = f""" SELECT EXTRACT(YEAR FROM x.reportdate)::int AS tahun, diff --git a/src/modules/equipment/where_query_sql.py b/src/modules/equipment/where_query_sql.py index d06d54d..6940518 100644 --- a/src/modules/equipment/where_query_sql.py +++ b/src/modules/equipment/where_query_sql.py @@ -14,9 +14,33 @@ def get_where_query_sql(assetnum, worktype): ) ) """ + # and a.wonum not like 'T%' # EM = Emergency Maintainance return where_query +def get_where_query_sql_labour_cost(assetnum, worktype): + """ + Return where query for labour cost using the standardized query. + The difference is on a.wonum not like T% + """ + where_query = f""" + where + (a.asset_unit = '3' OR a.asset_unit='00') + and a.status in ('COMP', 'CLOSE') + and a.wonum not like 'T%' + AND a.asset_assetnum = '{assetnum}' + {f"AND a.worktype = '{worktype}'" if worktype != 'CM' else "AND a.worktype in ('CM', 'PROACTIVE', 'EM')"} + {f"AND a.wojp8 != 'S1'" if worktype == 'CM' else ""} + AND ( + a.description NOT ILIKE '%U4%' + OR ( + a.description ILIKE '%U3%' + AND a.description ILIKE '%U4%' + ) + ) + """ + return where_query + def get_where_query_sql_all_worktype(assetnum): where_query = f""" WHERE