Files
denya-onecare/app/schemas/ticket.py
T
root 2407f294f4 feat: Sprint A Wahab review batch — categories, property hierarchy, priority grouping
Items 1-5, 9, 11 from denya-wahab-feedback-s2:
- Category.show_in_form (alert-only flag): Gas Leak hidden from issue picker
  but kept urgent for SLA/alert and reporting; emergency quick path on the
  new-issue form creates urgent tickets via include_hidden categories.
- Seed: Aluminum/Glass, Carpentry, Mould & Damp (Medium default) maintenance
  categories; Lost Property renamed Missing Item (+ sub).
- One alembic migration: add show_in_form (backfill True, Gas Leak False) +
  data rename Lost Property -> Missing Item.
- Property -> Building -> Apartment cascade with searchable apartment combobox
  on the new-issue form and ticket list filters; /api/tickets/units gains
  building filter + /units/grouped variant; /api/tickets gains additive
  building/unit_id filters. apartment_mapping.json committed (deterministic).
- Group-by-priority toggle on /tickets (four sections + unknown bucket,
  age-sortable, composes with filters, URL deep links), FM dashboard active
  tickets, and CS dashboard priority card click-through.
- Tests: 13 new (category visibility, seed idempotency/sync, unit grouping,
  ticket building/unit filters).
2026-08-02 09:30:29 +00:00

134 lines
3.9 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, Field
# ── 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
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] = []
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