diff --git a/AGENTS.md b/AGENTS.md index cf8e82e..b1054ab 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -72,13 +72,12 @@ TEST_PLAN_MAP.md # Map test plan |---------|-------------| | `canteen-admin-server` | Admin CRUD API, shares same SQLite DB | | `canteen-seed-import` | Seed data import from Cantaloupe CSVs | -| `photo-geotagger` | Batch GPS updater using same `assets.db` | | `exif-test` | EXIF/OCR validation against this DB | | `cantaloupe-downloader` | CLI to export machine data from Cantaloupe | ## Pitfalls - **Single-file backend** — server.py is ~2.5K lines; routes, DB, and OCR all in one file -- **DB shared** across canteen-admin-server, photo-geotagger, seed-import, exif-test — schema changes must be coordinated +- **DB shared** across canteen-admin-server, seed-import, exif-test — schema changes must be coordinated - **HTTPS** — start.sh generates self-signed cert every restart; ports 8901 (production) vs 8904 (dev) - **OCR** requires Tesseract installed system-wide (`apt install tesseract-ocr`) diff --git a/assets.db.backup.20260526125207 b/assets.db.backup.20260526125207 new file mode 100644 index 0000000..a0b0cd3 Binary files /dev/null and b/assets.db.backup.20260526125207 differ diff --git a/assets.db.backup.20260526_125213 b/assets.db.backup.20260526_125213 new file mode 100644 index 0000000..3861f34 Binary files /dev/null and b/assets.db.backup.20260526_125213 differ diff --git a/server.py b/server.py index 9ece980..ddafa15 100644 --- a/server.py +++ b/server.py @@ -1052,23 +1052,24 @@ def list_assets( conditions.append("assigned_to = ?") params.append(assigned_to) if q: - conditions.append("(name LIKE ? OR machine_id LIKE ? OR serial_number LIKE ? OR description LIKE ?)") + conditions.append("(a.name LIKE ? OR a.machine_id LIKE ? OR a.serial_number LIKE ? OR a.description LIKE ? OR a.company LIKE ?)") like = f"%{q}%" - params.extend([like, like, like, like]) + params.extend([like, like, like, like, like]) if no_dex_days is not None: conditions.append("(dex_report_date IS NULL OR REPLACE(dex_report_date, 'T', ' ') < datetime('now', '-' || ? || ' days'))") params.append(no_dex_days) where = " AND ".join(conditions) - sql = "SELECT * FROM assets" + from_clause = "FROM assets a LEFT JOIN customers c ON a.customer_id = c.id" + sql = f"SELECT a.*, c.name AS customer_name {from_clause}" if where: sql += f" WHERE {where}" - sql += " ORDER BY created_at DESC LIMIT ? OFFSET ?" + sql += " ORDER BY a.created_at DESC LIMIT ? OFFSET ?" params.extend([limit, offset]) rows = conn.execute(sql, params).fetchall() - # Get total count for pagination - count_sql = "SELECT COUNT(*) FROM assets" + # Get total count for pagination (use same FROM with alias for unambiguous conditions) + count_sql = f"SELECT COUNT(a.id) {from_clause}" if where: count_sql += f" WHERE {where}" total = conn.execute(count_sql, params[:len(params)-2]).fetchone()[0]