fix: GPS never from seed — only from real check-ins

GPS (latitude/longitude) and photo_path are now NEVER set by seed
import pipelines, even if empty. GPS comes only from field tech
check-ins via the main app.

- db_writer.py: FIELDS_NEVER_FROM_SEED set, GPS always None in
  _extract_row_values, skipped in update mode
- sync.py: latitude/longitude set to None in asset_data
- FIELD_MAP.md: updated policy table
This commit is contained in:
2026-06-02 22:56:04 -04:00
parent 186a9d03f3
commit 6fd9238f79
2 changed files with 12 additions and 3 deletions
+10 -1
View File
@@ -156,6 +156,10 @@ EXTRA_COLUMNS = ["created_at", "updated_at"]
EXTERNAL_PRESERVE_FIELDS = {"latitude", "longitude", "photo_path"} EXTERNAL_PRESERVE_FIELDS = {"latitude", "longitude", "photo_path"}
# Fields that are NEVER set from seed data — GPS comes only from real check-ins
FIELDS_NEVER_FROM_SEED = {"latitude", "longitude", "photo_path"}
def _serialize_value(val): def _serialize_value(val):
"""Convert a Python value to a SQLite-friendly value.""" """Convert a Python value to a SQLite-friendly value."""
if val is None: if val is None:
@@ -291,7 +295,8 @@ class DatabaseWriter:
elif col in ("yearly_sales", "monthly_sales", "weekly_sales"): elif col in ("yearly_sales", "monthly_sales", "weekly_sales"):
row[col] = _serialize_value(machine.get(col)) row[col] = _serialize_value(machine.get(col))
elif col in ("latitude", "longitude"): elif col in ("latitude", "longitude"):
row[col] = _serialize_value(machine.get(col)) # GPS comes only from real check-ins, never from seed
row[col] = None
else: else:
val = machine.get(col) val = machine.get(col)
if val is not None and not isinstance(val, (str, int, float, bool)): if val is not None and not isinstance(val, (str, int, float, bool)):
@@ -418,6 +423,10 @@ class DatabaseWriter:
for col in update_cols: for col in update_cols:
if col == "machine_id": if col == "machine_id":
continue # PK — never update continue # PK — never update
# GPS and photo come only from real check-ins, never from seed
if col in FIELDS_NEVER_FROM_SEED:
skipped_count += 1
continue
new_val = row.get(col) new_val = row.get(col)
old_val = existing_dict.get(col) old_val = existing_dict.get(col)
# Skip if existing value is non-null/empty (MSFS or user data wins) # Skip if existing value is non-null/empty (MSFS or user data wins)
+2 -2
View File
@@ -200,8 +200,8 @@ def push(source_db: str, target_db: str, dry_run: bool = False) -> dict:
"customer_id": customer_id, "customer_id": customer_id,
"location_id": location_id, "location_id": location_id,
"assigned_to": None, "assigned_to": None,
"latitude": _val(r, "latitude"), "latitude": None, # GPS comes only from real check-ins
"longitude": _val(r, "longitude"), "longitude": None, # GPS comes only from real check-ins
"geofence_radius_meters": 50, "geofence_radius_meters": 50,
"disney_park": _val(r, "disney_park"), "disney_park": _val(r, "disney_park"),
"is_disney": is_disney, "is_disney": is_disney,