HH/.opencode/plans/fix-department-detail-complaints.md
ismail 7369d08012
All checks were successful
Build and Push Docker Image / build (push) Successful in 4m14s
feat: unified reference numbers + feedback modules QA audit
Reference numbers (unified scheme PREFIX-YYYYMM-HOSP-NNNN, e.g. CMP-202606-HHN-0001):
- new ReferenceSequence model + generate_reference() helper (apps/core)
- Complaint/Inquiry/Observation/Appreciation/Suggestion emit unified refs via save()
- prefix-based auto-routing in public track API (CMP/INQ/OBS trackable; APR/SGT internal-only)
- removed legacy CMP-/INQ- generators in ui_views, integrations, px_sources
- migrations: core.0003_referencesequence, appreciation.0006, feedback.0008, observations.0012
- unit tests (format, sanitization, monthly reset, 40-thread concurrency)

QA audit:
- isolated E2E hospital sandbox mirroring HH-N + 10 role users (create_e2e_isolated_env)
- feedback-modules-audit.spec.ts + audit helper (headed, run-to-completion)
- reports/feedback-modules-qa-report.md

Also bundles accumulated in-progress work across complaints, observations,
organizations, templates, and other modules.
2026-06-14 14:29:23 +03:00

42 lines
2.5 KiB
Markdown

# Fix: Department Detail Shows No Complaints + Template Field References
## Root Cause
All 2163 complaints have `sent_to_department=False`. The department detail view queries filter by `sent_to_department=True`, so zero complaints/observations/inquiries appear. The import scripts (`import_all_complaints.py`, `import_historical_complaints.py`) explicitly set `sent_to_department=False`, overwriting the backfill migration from May 16.
## Changes
### 1. NEW FILE: `apps/complaints/management/commands/backfill_sent_to_department.py`
Create management command that sets `sent_to_department=True` on:
- `Complaint.objects.filter(department__isnull=False, sent_to_department=False).update(sent_to_department=True, sent_to_department_at=F('created_at'))`
- `Observation.objects.filter(assigned_department__isnull=False, sent_to_department=False).update(sent_to_department=True, sent_to_department_at=F('created_at'))`
- `Inquiry.objects.filter(department__isnull=False, sent_to_department=False).update(sent_to_department=True, sent_to_department_at=F('created_at'))`
- `ComplaintInvolvedDepartment.objects.filter(sent=False, complaint__department__isnull=False).update(sent=True)`
### 2. EDIT: `apps/complaints/management/commands/import_all_complaints.py`
- Change `sent_to_department=False``sent_to_department=True`
### 3. EDIT: `apps/complaints/management/commands/import_historical_complaints.py`
- Change `sent_to_department=False``sent_to_department=True`
### 4. EDIT: `templates/organizations/orgsection_list.html`
- Remove `point_of_contact` column (Section model no longer has this field)
### 5. EDIT: `templates/organizations/orgsection_form.html`
- Remove `point_of_contact` form field (lines 136-140)
### 6. EDIT: `templates/complaints/government_ticket_form.html`
- Line 295: change `sec.name``sec.name_en || sec.name` (API returns `name_en`, not `name`)
### 7. EDIT: `templates/px_sources/source_user_create_complaint.html`
- Line 303: change `sec.name``sec.name_en || sec.name`
### 8. RUN: `python manage.py backfill_sent_to_department`
- Expected: 2163 complaints, 3 observations, 2 inquiries updated
### 9. VERIFY: `python manage.py check` + tests
## What was ALREADY fixed in previous session
- `department_detail.html`: `sub_subsections``subsections`, removed floor/poc columns, added champion/supervisor/deputy columns
- `orgsection_detail.html`: removed `point_of_contact` from header
- `ui_views.py:2173`: added supervisor/deputy_supervisor to select_related