From b5afa13f9d437348b931cf4de907e12144d9c216 Mon Sep 17 00:00:00 2001 From: jacob-a-brown Date: Mon, 15 Dec 2025 16:36:27 -0700 Subject: [PATCH 1/5] feat: add open and datalogger suitability status to well inventory and add_thing These fields now go into the StatusHistory table, not as fields in the Thing table --- api/well_inventory.py | 1 + schemas/thing.py | 1 + schemas/well_inventory.py | 2 +- services/thing_helper.py | 37 +++++++++++++++++++++++++++++++++++ tests/features/environment.py | 2 +- 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/api/well_inventory.py b/api/well_inventory.py index 90c6e0300..6f24009b8 100644 --- a/api/well_inventory.py +++ b/api/well_inventory.py @@ -558,6 +558,7 @@ def _add_csv_row(session: Session, group: Group, model: WellInventoryRow, user) well_pump_type=model.well_pump_type, well_pump_depth=model.well_pump_depth_ft, is_suitable_for_datalogger=model.datalogger_possible, + is_open=model.is_open, notes=well_notes, well_purposes=well_purposes, ) diff --git a/schemas/thing.py b/schemas/thing.py index bdf4323c0..9e34b6487 100644 --- a/schemas/thing.py +++ b/schemas/thing.py @@ -162,6 +162,7 @@ class CreateWell(CreateBaseThing, ValidateWell): well_pump_type: WellPumpType | None = None well_pump_depth: float | None = None is_suitable_for_datalogger: bool | None + is_open: bool | None = None formation_completion_code: FormationCode | None = None diff --git a/schemas/well_inventory.py b/schemas/well_inventory.py index 159d6e268..f5dc8dba5 100644 --- a/schemas/well_inventory.py +++ b/schemas/well_inventory.py @@ -240,7 +240,7 @@ class WellInventoryRow(BaseModel): depth_source: Optional[str] = None well_pump_type: Optional[str] = None well_pump_depth_ft: OptionalFloat = None - is_open: OptionalBool = None # TODO: needs a home + is_open: OptionalBool = None datalogger_possible: OptionalBool = None casing_diameter_ft: OptionalFloat = None measuring_point_description: Optional[str] = None diff --git a/services/thing_helper.py b/services/thing_helper.py index d6b563f23..848c66e2f 100644 --- a/services/thing_helper.py +++ b/services/thing_helper.py @@ -38,6 +38,7 @@ DataProvenance, ThingIdLink, MonitoringFrequencyHistory, + StatusHistory, ) from services.audit_helper import audit_add @@ -201,6 +202,8 @@ def add_thing( effective_start = data.get("first_visit_date") group_id = data.pop("group_id", None) monitoring_frequencies = data.pop("monitoring_frequencies", None) + datalogger_suitability_status = data.pop("is_suitable_for_datalogger", None) + open_status = data.pop("is_open", None) # ---------- # END UNIVERSAL THING RELATED TABLES @@ -297,6 +300,38 @@ def add_thing( audit_add(user, wcm) session.add(wcm) + if datalogger_suitability_status is not None: + if datalogger_suitability_status is True: + status_value = "Datalogger can be installed" + else: + status_value = "Datalogger cannot be installed" + dlss = StatusHistory( + target_id=thing.id, + target_table="thing", + status_value=status_value, + status_type="Datalogger Suitability Status", + start_date=effective_start, + end_date=None, + ) + audit_add(user, dlss) + session.add(dlss) + + if open_status is not None: + if open_status is True: + status_value = "Open" + else: + status_value = "Closed" + os_status = StatusHistory( + target_id=thing.id, + target_table="thing", + status_value=status_value, + status_type="Open Status", + start_date=effective_start, + end_date=None, + ) + audit_add(user, os_status) + session.add(os_status) + # ---------- # END WATER WELL SPECIFIC LOGIC # ---------- @@ -359,9 +394,11 @@ def add_thing( session.refresh(note) except Exception as e: + print(e) session.rollback() raise e + print("returning thing") return thing diff --git a/tests/features/environment.py b/tests/features/environment.py index 5383a8767..b36e2c429 100644 --- a/tests/features/environment.py +++ b/tests/features/environment.py @@ -504,7 +504,7 @@ def before_all(context): rebuild = True # rebuild = True - erase_data = False + erase_data = True if rebuild: erase_and_rebuild_db() elif get_bool_env("ERASE_DATA", False): From 7ad83e8eaed0c5b8252ca69655f8b1c362f96737 Mon Sep 17 00:00:00 2001 From: jacob-a-brown Date: Tue, 16 Dec 2025 10:28:14 -0700 Subject: [PATCH 2/5] fix: remove debugging print statement --- services/thing_helper.py | 1 - 1 file changed, 1 deletion(-) diff --git a/services/thing_helper.py b/services/thing_helper.py index 848c66e2f..b0fa905fa 100644 --- a/services/thing_helper.py +++ b/services/thing_helper.py @@ -394,7 +394,6 @@ def add_thing( session.refresh(note) except Exception as e: - print(e) session.rollback() raise e From 4bd9b99e8a21cc4b9802debfd86f2155013438bf Mon Sep 17 00:00:00 2001 From: jacob-a-brown Date: Tue, 16 Dec 2025 10:54:29 -0700 Subject: [PATCH 3/5] fix: remove print debugging statement --- services/thing_helper.py | 1 - 1 file changed, 1 deletion(-) diff --git a/services/thing_helper.py b/services/thing_helper.py index b0fa905fa..456bf2a70 100644 --- a/services/thing_helper.py +++ b/services/thing_helper.py @@ -397,7 +397,6 @@ def add_thing( session.rollback() raise e - print("returning thing") return thing From d4fcfb5ee409c5481ca9e1d76783ee3cd1bd2c97 Mon Sep 17 00:00:00 2001 From: jacob-a-brown Date: Tue, 16 Dec 2025 11:33:18 -0700 Subject: [PATCH 4/5] fix: remove outdated variable from testing env --- tests/features/environment.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/features/environment.py b/tests/features/environment.py index b36e2c429..59b6d6aa1 100644 --- a/tests/features/environment.py +++ b/tests/features/environment.py @@ -503,8 +503,6 @@ def before_all(context): context.objects = {} rebuild = True - # rebuild = True - erase_data = True if rebuild: erase_and_rebuild_db() elif get_bool_env("ERASE_DATA", False): From 9e55601ab4f9d88bdbffe42fc14cf44549451810 Mon Sep 17 00:00:00 2001 From: jacob-a-brown Date: Tue, 16 Dec 2025 11:40:35 -0700 Subject: [PATCH 5/5] fix: don't erase testing data by default --- tests/features/environment.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/features/environment.py b/tests/features/environment.py index 4a0d9b8e4..5ce9c01cc 100644 --- a/tests/features/environment.py +++ b/tests/features/environment.py @@ -502,6 +502,7 @@ def before_all(context): context.objects = {} rebuild = True + erase_data = False if rebuild: erase_and_rebuild_db() elif erase_data: