Sync prod: customer_name JOIN, search debounce, parent company filter, asset detail card with map

This commit is contained in:
2026-05-26 15:54:07 -04:00
parent 6cb76d8a33
commit a1022b300e
4 changed files with 8 additions and 8 deletions
+7 -6
View File
@@ -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]