From fe4317b1b68fecf02fa1ef9fdcf1286924472cd5 Mon Sep 17 00:00:00 2001 From: MrWaradana Date: Tue, 30 Dec 2025 18:16:43 +0700 Subject: [PATCH] refactor: Remove wonum exclusion and add worktype CASE statement to equipment queries. --- src/modules/equipment/where_query_sql.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/modules/equipment/where_query_sql.py b/src/modules/equipment/where_query_sql.py index 5ccba25..fef457b 100644 --- a/src/modules/equipment/where_query_sql.py +++ b/src/modules/equipment/where_query_sql.py @@ -2,7 +2,6 @@ def get_where_query_sql(assetnum, worktype): where_query = f""" where (a.asset_unit = '3' OR a.asset_unit='00') - and a.wonum not like 'T%' and a.status in ('COMP', 'CLOSE') AND a.asset_assetnum = '{assetnum}' {f"AND a.worktype = '{worktype}'" if worktype != 'CM' else "AND a.worktype in ('CM', 'PROACTIVE', 'EM')"} @@ -20,21 +19,26 @@ def get_where_query_sql(assetnum, worktype): def get_where_query_sql_all_worktype(assetnum): where_query = f""" - where - (a.asset_unit = '3' OR a.asset_unit='00') - and a.wonum not like 'T%' - and a.status in ('COMP', 'CLOSE') + WHERE + (a.asset_unit = '3' OR a.asset_unit = '00') + AND a.status IN ('COMP', 'CLOSE') AND a.asset_assetnum = '{assetnum}' AND ( (a.worktype = 'CM' AND a.wojp8 != 'S1') OR (a.worktype <> 'CM') ) AND ( - a.description NOT ILIKE '%U4%' - OR ( - a.description ILIKE '%U3%' - AND a.description ILIKE '%U4%' + a.description NOT ILIKE '%U4%' + OR ( + a.description ILIKE '%U3%' + AND a.description ILIKE '%U4%' + ) ) + AND ( + CASE + WHEN '{worktype}' <> 'CM' THEN a.worktype = '{worktype}' + ELSE a.worktype IN ('CM', 'PROACTIVE', 'EM') + END ) """ return where_query \ No newline at end of file