diff --git a/classify_makes.py b/classify_makes.py index ec586f2..b0dea0f 100644 --- a/classify_makes.py +++ b/classify_makes.py @@ -66,6 +66,12 @@ def find_asset_by_normalized_id(db_path: str, normalized: str) -> list: Search assets.db for any asset whose serial_number, machine_id, connect_id, equipment_id, or barcode matches the given normalized identifier. + Supports: + - Exact match: normalized string equals the DB field (after normalization) + - Suffix match: if the normalized value is all digits and >= 7 chars, + match against the last N digits of connect_id and equipment_id (for + partial OCR reads that capture only the numeric tail of a longer ID). + Returns a list of matching rows (dicts). """ if not normalized or len(normalized) < 3: @@ -74,7 +80,22 @@ def find_asset_by_normalized_id(db_path: str, normalized: str) -> list: import sqlite3 conn = sqlite3.connect(db_path) conn.row_factory = sqlite3.Row - rows = conn.execute(""" + + # Suffix matching: if the scanned text is purely numeric and >= 7 chars, + # search for assets whose connect_id or equipment_id ends with those digits. + # Connect IDs often look like VM-05064-0000099387; OCR might only read "0000099387". + suffix_conditions = '' + suffix_params = [] + if len(normalized) >= 7 and normalized.isdigit(): + # Match against the last N digits of connect_id and equipment_id. + # Use LIKE with rightmost-anchored pattern: % + suffix_conditions = """ + OR replace(replace(replace(replace(upper(connect_id), '-', ''), '.', ''), ' ', ''), '/', '') LIKE ? + OR replace(replace(replace(replace(upper(equipment_id), '-', ''), '.', ''), ' ', ''), '/', '') LIKE ? + """ + suffix_params = ['%' + normalized, '%' + normalized] + + rows = conn.execute(f""" SELECT id, machine_id, name, serial_number, connect_id, equipment_id, barcode, make, model, category FROM assets @@ -83,8 +104,8 @@ def find_asset_by_normalized_id(db_path: str, normalized: str) -> list: OR replace(replace(replace(replace(upper(equipment_id), '-', ''), '.', ''), ' ', ''), '/', '') = ? OR replace(replace(replace(replace(upper(machine_id), '-', ''), '.', ''), ' ', ''), '/', '') = ? OR replace(replace(replace(replace(upper(barcode), '-', ''), '.', ''), ' ', ''), '/', '') = ? - -- Connect-ID suffix match (last 7+ digits → equipment_id suffix) - """, (normalized, normalized, normalized, normalized, normalized)).fetchall() + {suffix_conditions} + """, (normalized, normalized, normalized, normalized, normalized, *suffix_params)).fetchall() conn.close() return [dict(r) for r in rows] diff --git a/static/sw.js b/static/sw.js index 776c7ef..6b15e44 100644 --- a/static/sw.js +++ b/static/sw.js @@ -3,7 +3,7 @@ // Caches app shell + CDN deps. Network-first for API, cache fallback for static. // ═══════════════════════════════════════════════════════════════════════════ -const CACHE_NAME = 'canteen-v9'; +const CACHE_NAME = 'canteen-v10'; // App shell — core resources needed to boot the PWA const APP_SHELL = [