update
This commit is contained in:
@@ -440,29 +440,84 @@ def _sync_empfang_practice_from_license(
|
||||
|
||||
|
||||
def lookup_practice_id_for_license_email(email: str) -> Optional[str]:
|
||||
"""Liefert die serverseitig gespeicherte practice_id zur Kunden-E-Mail (Lizenz ↔ Praxis)."""
|
||||
"""Liefert die serverseitig gespeicherte practice_id zur Kunden-E-Mail (Lizenz ↔ Praxis).
|
||||
|
||||
Gibt bei mehreren passenden Zeilen die juengste (max updated_at) Praxis zuerst zurueck.
|
||||
"""
|
||||
lst = list_distinct_practice_ids_for_license_email(email)
|
||||
return lst[0] if lst else None
|
||||
|
||||
|
||||
def list_distinct_practice_ids_for_license_email(email: str) -> list[str]:
|
||||
"""Alle Mandanten-IDs, die in der Lizenz-Tabelle dieser Kunden-E-Mail zugeordnet sind."""
|
||||
_ensure_storage()
|
||||
e = (email or "").strip().lower()
|
||||
if not e:
|
||||
return None
|
||||
return []
|
||||
try:
|
||||
with sqlite3.connect(DB_PATH) as con:
|
||||
row = con.execute(
|
||||
rows = con.execute(
|
||||
"""
|
||||
SELECT practice_id FROM licenses
|
||||
WHERE lower(customer_email) = ?
|
||||
SELECT practice_id, MAX(updated_at) AS mu
|
||||
FROM licenses
|
||||
WHERE lower(trim(customer_email)) = ?
|
||||
AND practice_id IS NOT NULL
|
||||
AND trim(practice_id) != ''
|
||||
ORDER BY updated_at DESC
|
||||
LIMIT 1
|
||||
GROUP BY practice_id
|
||||
ORDER BY mu DESC
|
||||
""",
|
||||
(e,),
|
||||
).fetchone()
|
||||
if not row or not row[0]:
|
||||
return None
|
||||
return str(row[0]).strip()
|
||||
).fetchall()
|
||||
out: list[str] = []
|
||||
seen: set[str] = set()
|
||||
for r in rows:
|
||||
if not r or not r[0]:
|
||||
continue
|
||||
pid = str(r[0]).strip()
|
||||
if pid and pid not in seen:
|
||||
seen.add(pid)
|
||||
out.append(pid)
|
||||
return out
|
||||
except Exception:
|
||||
return None
|
||||
return []
|
||||
|
||||
|
||||
def list_distinct_practice_ids_for_license_key(license_key: str) -> list[str]:
|
||||
"""Alle Mandanten-IDs, die unter diesem Lizenzschluessel in der Lizenz-Tabelle stehen."""
|
||||
_ensure_storage()
|
||||
k = (license_key or "").strip()
|
||||
if not k:
|
||||
return []
|
||||
kl = k.lower()
|
||||
try:
|
||||
with sqlite3.connect(DB_PATH) as con:
|
||||
rows = con.execute(
|
||||
"""
|
||||
SELECT practice_id, MAX(updated_at) AS mu
|
||||
FROM licenses
|
||||
WHERE (
|
||||
trim(license_key) = ?
|
||||
OR lower(trim(license_key)) = ?
|
||||
)
|
||||
AND practice_id IS NOT NULL
|
||||
AND trim(practice_id) != ''
|
||||
GROUP BY practice_id
|
||||
ORDER BY mu DESC
|
||||
""",
|
||||
(k, kl),
|
||||
).fetchall()
|
||||
out: list[str] = []
|
||||
seen: set[str] = set()
|
||||
for r in rows:
|
||||
if not r or not r[0]:
|
||||
continue
|
||||
pid = str(r[0]).strip()
|
||||
if pid and pid not in seen:
|
||||
seen.add(pid)
|
||||
out.append(pid)
|
||||
return out
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
|
||||
def lookup_license_email_for_practice(practice_id: str) -> Optional[str]:
|
||||
|
||||
Reference in New Issue
Block a user