- Add Cancelled as terminal status reachable from all active states; exclude
from SLA breach reporting and dashboard active counts; add to status pickers
- Persist customer phone on ticket create/update (was silently dropped);
add tickets.phone migration + legacy self-heal guard
- Add admin-only DELETE /api/tickets/{id} (removes timeline/photos/escalations)
- Add GET /api/auth/users for the assign-technician dropdown (was hardcoded)
- TicketOut now returns nested unit/category so the detail page stops showing
'—' for Unit/Property/Category
- Ticket numbering uses max+1 so deletions never re-issue a number
- New-issue form: require Category and (standard mode) Priority client-side
- Tests: 11 new cases covering cancellation, SLA exemption, phone, delete,
users endpoint, numbering
137 lines
4.0 KiB
Python
137 lines
4.0 KiB
Python
"""Pydantic schemas for ticket CRUD, timeline, photos, and SLA."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from decimal import Decimal
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
# ── Unit ─────────────────────────────────────────────────────────────
|
|
class UnitOut(BaseModel):
|
|
id: int
|
|
property: str
|
|
apartment_code: str
|
|
building: str | None = None
|
|
floor: int | None = None
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
# ── Category ─────────────────────────────────────────────────────────
|
|
class CategoryOut(BaseModel):
|
|
id: int
|
|
type: str
|
|
name: str
|
|
parent_id: int | None = None
|
|
sla_urgency: str | None = None
|
|
show_in_form: bool = True
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class CategoryTreeOut(CategoryOut):
|
|
children: list[CategoryTreeOut] = []
|
|
|
|
|
|
# ── Ticket ───────────────────────────────────────────────────────────
|
|
class TicketCreate(BaseModel):
|
|
unit_id: int | None = None
|
|
category_id: int | None = None
|
|
priority: str | None = None # urgent, high, medium, low
|
|
reporter: str | None = None
|
|
reported_via: str | None = None # whatsapp, phone, walk-in, qr, agent
|
|
description: str | None = None
|
|
assigned_to: int | None = None
|
|
customer_name: str | None = None
|
|
phone: str | None = None
|
|
|
|
|
|
class TicketUpdate(BaseModel):
|
|
status: str | None = None
|
|
unit_id: int | None = None
|
|
category_id: int | None = None
|
|
priority: str | None = None
|
|
reporter: str | None = None
|
|
reported_via: str | None = None
|
|
description: str | None = None
|
|
assigned_to: int | None = None
|
|
eta: datetime | None = None
|
|
cost: Decimal | None = None
|
|
parts_used: str | None = None
|
|
note: str | None = None
|
|
|
|
|
|
class TicketTimelineOut(BaseModel):
|
|
id: int
|
|
ticket_id: int
|
|
from_status: str | None = None
|
|
to_status: str | None = None
|
|
note: str | None = None
|
|
user_id: int | None = None
|
|
created_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class TicketPhotoOut(BaseModel):
|
|
id: int
|
|
ticket_id: int
|
|
photo_url: str
|
|
is_before: bool
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class TicketBrief(BaseModel):
|
|
"""Summary view for list endpoints."""
|
|
id: int
|
|
ticket_number: str
|
|
status: str
|
|
priority: str | None = None
|
|
unit_id: int | None = None
|
|
category_id: int | None = None
|
|
assigned_to: int | None = None
|
|
assigned_technician_name: str | None = None
|
|
reporter: str | None = None
|
|
phone: str | None = None
|
|
description: str | None = None
|
|
sla_deadline: datetime | None = None
|
|
reopen_count: int = 0
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class TicketOut(TicketBrief):
|
|
"""Full ticket detail with relations."""
|
|
closed_at: datetime | None = None
|
|
eta: datetime | None = None
|
|
cost: Decimal | None = None
|
|
parts_used: str | None = None
|
|
customer_rating: int | None = None
|
|
timeline: list[TicketTimelineOut] = []
|
|
photos: list[TicketPhotoOut] = []
|
|
unit: UnitOut | None = None
|
|
category: CategoryOut | None = None
|
|
sla_status: dict | None = None
|
|
|
|
|
|
class TicketListResponse(BaseModel):
|
|
items: list[TicketBrief]
|
|
total: int
|
|
page: int
|
|
page_size: int
|
|
|
|
|
|
# ── SLA ──────────────────────────────────────────────────────────────
|
|
class SLAStatusOut(BaseModel):
|
|
priority: str | None = None
|
|
response_deadline: str | None = None
|
|
resolution_deadline: str | None = None
|
|
response_breached: bool = False
|
|
resolution_breached: bool = False
|
|
current_status: str | None = None
|