fix: show phone and mobile in sag v3 add-contact search results

This commit is contained in:
Christian 2026-05-05 07:03:03 +02:00
parent 0dcc6c4fdb
commit 1fe0611453
3 changed files with 31 additions and 11 deletions

View File

@ -1 +1 @@
2.2.91 2.2.92

View File

@ -5267,6 +5267,12 @@
onclick="addContact(${caseId}, ${c.id}, '${(c.first_name + ' ' + c.last_name).replace(/'/g, "\\'")}')"> onclick="addContact(${caseId}, ${c.id}, '${(c.first_name + ' ' + c.last_name).replace(/'/g, "\\'")}')">
<strong>${c.first_name} ${c.last_name}</strong> <strong>${c.first_name} ${c.last_name}</strong>
<div class="small text-muted">${c.email || ''} ${c.user_company ? '(' + c.user_company + ')' : ''}</div> <div class="small text-muted">${c.email || ''} ${c.user_company ? '(' + c.user_company + ')' : ''}</div>
<div class="small mt-1">
${Array.from(new Set([
c.mobile ? `Mobil: ${c.mobile}` : '',
c.phone ? `Telefon: ${c.phone}` : ''
].filter(Boolean))).join(' · ') || '<span class="text-muted">Intet telefonnummer</span>'}
</div>
</div> </div>
`).join(''); `).join('');
} }

View File

@ -26,20 +26,34 @@ async def search_customers(q: str = Query(..., min_length=2)):
async def search_contacts(q: str = Query(..., min_length=2)): async def search_contacts(q: str = Query(..., min_length=2)):
""" """
Autocomplete search for contacts. Autocomplete search for contacts.
Returns list of {id, first_name, last_name, email} Returns list of {id, first_name, last_name, email, phone, mobile, user_company}
Supports: first name, last name, email, combined "Fornavn Efternavn", phone, mobile. Supports: first name, last name, email, combined "Fornavn Efternavn", phone, mobile.
""" """
sql = """ sql = """
SELECT id, first_name, last_name, email SELECT
FROM contacts c.id,
c.first_name,
c.last_name,
c.email,
c.phone,
c.mobile,
(
SELECT cu.name
FROM contact_companies cc
JOIN customers cu ON cu.id = cc.customer_id
WHERE cc.contact_id = c.id
ORDER BY cc.is_primary DESC NULLS LAST, cc.id ASC
LIMIT 1
) AS user_company
FROM contacts c
WHERE WHERE
first_name ILIKE %s c.first_name ILIKE %s
OR last_name ILIKE %s OR c.last_name ILIKE %s
OR email ILIKE %s OR c.email ILIKE %s
OR CONCAT(first_name, ' ', last_name) ILIKE %s OR CONCAT(c.first_name, ' ', c.last_name) ILIKE %s
OR phone ILIKE %s OR c.phone ILIKE %s
OR mobile ILIKE %s OR c.mobile ILIKE %s
ORDER BY first_name ASC, last_name ASC ORDER BY c.first_name ASC, c.last_name ASC
LIMIT 20 LIMIT 20
""" """
term = f"%{q}%" term = f"%{q}%"