OSS-BSS-Field-Dispatch/scripts/fix_search_abbrev.py
louispaulb 5e6f20d871 Initial commit — dispatch app baseline before Quasar migration
Current state: custom CSS + vanilla Vue components
Architecture: modular with composables, provide/inject pattern
Ready for progressive migration to Quasar native components

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 13:35:49 -04:00

41 lines
1.4 KiB
Python

import frappe, os
os.chdir('/home/frappe/frappe-bench')
frappe.init('frontend', sites_path='/home/frappe/frappe-bench/sites')
frappe.connect()
ss = frappe.get_doc('Server Script', 'Address Autocomplete')
ss.script = """
query = frappe.form_dict.get("q", "")
if not query or len(query) < 3:
frappe.response["results"] = []
else:
q = query.strip().lower()
q = q.replace("ste-", "sainte-").replace("ste ", "sainte-")
q = q.replace("st-", "saint-").replace("st ", "saint-")
q = q.replace("boul ", "boulevard ").replace("boul.", "boulevard")
q = q.replace("ave ", "avenue ").replace("ave.", "avenue")
words = q.split()
conditions = []
for w in words:
escaped = frappe.db.escape("%" + w + "%")
conditions.append("search_text LIKE " + escaped)
where = " AND ".join(conditions)
sql = ("SELECT address_full, ville, code_postal, latitude, longitude "
"FROM rqa_addresses "
"WHERE " + where + " "
"ORDER BY "
"CASE WHEN code_postal LIKE 'J0L%' THEN 0 "
"WHEN code_postal LIKE 'J0S%' THEN 1 ELSE 2 END, "
"length(address_full) "
"LIMIT 10")
results = frappe.db.sql(sql, as_dict=True)
frappe.response["results"] = results
"""
ss.save(ignore_permissions=True)
frappe.db.commit()
print('Updated: query normalizes ste->sainte, st->saint, boul->boulevard')
frappe.destroy()