Fix email routing and contact search

This commit is contained in:
Christian 2026-06-11 01:12:25 +02:00
parent 592ed8640d
commit 5f2452f222
4 changed files with 50 additions and 10 deletions

View File

@ -88,8 +88,26 @@ async def get_contacts(
params = []
if search:
where_clauses.append("(c.first_name ILIKE %s OR c.last_name ILIKE %s OR c.email ILIKE %s)")
params.extend([f"%{search}%", f"%{search}%", f"%{search}%"])
where_clauses.append(
"""
(
c.first_name ILIKE %s
OR c.last_name ILIKE %s
OR c.email ILIKE %s
OR c.phone ILIKE %s
OR c.mobile ILIKE %s
OR EXISTS (
SELECT 1
FROM contact_companies cc2
JOIN customers cu2 ON cu2.id = cc2.customer_id
WHERE cc2.contact_id = c.id
AND cu2.name ILIKE %s
)
)
"""
)
like = f"%{search}%"
params.extend([like, like, like, like, like, like])
if is_active is not None:
where_clauses.append("c.is_active = %s")

View File

@ -113,8 +113,27 @@ async def get_contacts(
params = []
if search:
where_clauses.append("(c.first_name ILIKE %s OR c.last_name ILIKE %s OR c.email ILIKE %s)")
params.extend([f"%{search}%", f"%{search}%", f"%{search}%"])
where_clauses.append(
"""
(
c.first_name ILIKE %s
OR c.last_name ILIKE %s
OR c.email ILIKE %s
OR c.phone ILIKE %s
OR c.mobile ILIKE %s
OR c.user_company ILIKE %s
OR EXISTS (
SELECT 1
FROM contact_companies cc2
JOIN customers cu2 ON cu2.id = cc2.customer_id
WHERE cc2.contact_id = c.id
AND cu2.name ILIKE %s
)
)
"""
)
like = f"%{search}%"
params.extend([like, like, like, like, like, like, like])
if is_active is not None:
where_clauses.append("c.is_active = %s")

View File

@ -953,7 +953,7 @@ async function loadContacts() {
totalContacts = data.total;
currentContactsData = Array.isArray(data.contacts) ? data.contacts : [];
displayContacts(currentContactsData);
updatePagination(data.total);
updatePagination(data.total, currentContactsData.length);
} catch (error) {
if (error.name === 'AbortError') {
@ -1182,11 +1182,12 @@ function persistTablePreferences() {
}
}
function updatePagination(total) {
const start = currentPage * pageSize + 1;
const end = Math.min((currentPage + 1) * pageSize, total);
function updatePagination(total, rowsOnPage = 0) {
const safeRowsOnPage = Number.isFinite(Number(rowsOnPage)) ? Math.max(0, Number(rowsOnPage)) : 0;
const start = total > 0 ? (currentPage * pageSize + 1) : 0;
const end = total > 0 ? Math.min(currentPage * pageSize + safeRowsOnPage, total) : 0;
document.getElementById('showingStart').textContent = total > 0 ? start : 0;
document.getElementById('showingStart').textContent = start;
document.getElementById('showingEnd').textContent = end;
document.getElementById('totalCount').textContent = total;

View File

@ -1156,11 +1156,13 @@ class EmailWorkflowService:
if sag_id_from_tag:
if sag_id and sag_id != sag_id_from_tag:
logger.warning(
"⚠️ Email %s contains conflicting case hints (thread: SAG-%s, tag: SAG-%s). Using thread match.",
"⚠️ Email %s contains conflicting case hints (thread: SAG-%s, tag: SAG-%s). Using SAG tag.",
email_id,
sag_id,
sag_id_from_tag
)
sag_id = sag_id_from_tag
routing_source = 'sag_tag'
elif not sag_id:
sag_id = sag_id_from_tag
routing_source = 'sag_tag'