Mechanic's work place
Some checks failed
ci / test (push) Has been cancelled

This commit is contained in:
VPN SaaS Dev
2026-05-16 10:04:56 +09:00
parent fec9635079
commit 83ad880b9d
39 changed files with 2951 additions and 74 deletions

View File

@@ -21,7 +21,7 @@ from app.models.expense import ServiceEntry
from app.models.user import User
from app.services.notifications import notify_user
ACTIVE_APPOINTMENT_STATUSES = {"requested", "confirmed", "proposed_new_time"}
ACTIVE_APPOINTMENT_STATUSES = {"requested", "confirmed", "confirmed_by_sto", "proposed_new_time"}
DEFAULT_SERVICE_DURATIONS = {
"oil_change": 60,
"diagnostics": 60,
@@ -190,7 +190,16 @@ async def create_service_notification(
service_center_id: int | None = None,
appointment_id: int | None = None,
send_telegram: bool = True,
idempotency_key: str | None = None,
) -> ServiceNotification:
if idempotency_key:
existing = (
await session.execute(
select(ServiceNotification).where(ServiceNotification.idempotency_key == idempotency_key)
)
).scalar_one_or_none()
if existing is not None:
return existing
notification = ServiceNotification(
recipient_user_id=recipient_user_id,
service_center_id=service_center_id,
@@ -198,12 +207,21 @@ async def create_service_notification(
notification_type=notification_type,
title=title,
body=body,
idempotency_key=idempotency_key,
)
session.add(notification)
if send_telegram:
user = await session.get(User, recipient_user_id)
if user is not None:
await notify_user(user, f"{title}\n{body}" if body else title)
notification.status = "processing"
delivered = await notify_user(user, f"{title}\n{body}" if body else title)
if delivered:
notification.status = "sent"
notification.sent_at = datetime.now(UTC)
else:
notification.status = "retrying"
notification.retry_count = 1
notification.last_error = "telegram_delivery_failed"
return notification