Jul 8 - Update scheduled inspection
This commit is contained in:
@@ -376,6 +376,25 @@ contract_notification_recipients:
|
||||
|
||||
`event_types` is a JSON list of `MATRIX_EVENTS` keys. A recipient fires only when the event is in its list. Managed admin-only on the **Contract detail page** (`/projects/<id>`) via `add_notify_recipient` / `remove_notify_recipient`. Dispatch is resolved centrally in `notify_by_matrix()` — see §11.
|
||||
|
||||
### ScheduledInspection
|
||||
|
||||
```
|
||||
scheduled_inspections:
|
||||
id, facility_id (FK→facilities CASCADE), template_id (FK→inspection_templates CASCADE),
|
||||
inspector_id (FK→users SET NULL), frequency ENUM('once','daily','weekly','monthly'),
|
||||
next_due_date DATE, active BOOL, notes TEXT, created_by, created_at,
|
||||
last_completed_at DATETIME, advance_notified BOOL, due_notified BOOL, overdue_notified BOOL
|
||||
inspections.scheduled_inspection_id FK→scheduled_inspections SET NULL ← Phase 36
|
||||
```
|
||||
|
||||
**A plan, not an inspection.** Names a facility + template + assigned inspector + `next_due_date`. Lifecycle:
|
||||
- The assigned inspector (or a manager) clicks **Start** → `scheduled_inspections.start` creates a normal `in_progress` Inspection with `scheduled_inspection_id` set, then redirects to the execute flow.
|
||||
- On **completion** (execute route, status → `completed`), `ScheduledInspection.fulfill()` runs in the same atomic commit: `once` → `active=False`; recurring → `next_due_date` rolls forward past today via `_add_interval()` and the three `*_notified` flags reset.
|
||||
- **Reminders** are dispatched by the cron endpoint (see §11): advance (1 day before) + due-date to the inspector, overdue to admin/director — each fires at most once per occurrence via the `*_notified` flags. Uses `notify()` with `event_type=EVENT_SCHEDULED_INSPECTION`.
|
||||
- Dashboard shows an **upcoming (next 7 days) / overdue** panel for non-customers (inspectors see only their own).
|
||||
|
||||
Management (`/scheduled-inspections/new|edit|delete`) is `@project_manager_required`; **Start** is the assigned inspector or a manager; inspectors' list/dashboard views are scoped to their own `inspector_id`.
|
||||
|
||||
---
|
||||
|
||||
## 6. Role & Permission Matrix
|
||||
@@ -429,6 +448,7 @@ contract_notification_recipients:
|
||||
| `audit` | `/audit` | list (admin only), view, purge |
|
||||
| `reports` | `/reports` | index, facility report, scorecard, CSV/PDF/Excel export, issues-aging, sla-compliance, followup-closure, facility summary PDF |
|
||||
| `scheduled_reports` | `/scheduled-reports` | CRUD + manual trigger (accessible via Reports sub-nav) |
|
||||
| `scheduled_inspections` | `/scheduled-inspections` | list, new/edit/delete (PM+), `GET /<id>/start` (assigned inspector or manager → creates linked inspection), `POST /run` (cron reminders, `token=DIGEST_SECRET`) |
|
||||
| `support` | `/support` | `GET /chat`, `POST /chat/message` (AJAX→Groq), `POST /tickets`, `GET /my-tickets`, `GET/POST /my-tickets/<id>`, `GET /admin/tickets`, `GET/POST /admin/tickets/<id>` |
|
||||
| `broadcast` | `/admin/broadcast` | `GET /` (compose + history), `POST /send` (admin-only; fans out one Notification per targeted user) |
|
||||
| `devices` | `/admin/devices` | `GET /` (device list from `api_device_tokens`), `POST /notify` (admin-only) |
|
||||
@@ -634,6 +654,7 @@ EVENT_ISSUE_FLAGGED = 'issue_flagged'
|
||||
EVENT_CUSTOMER_INSPECTION_DONE = 'customer_inspection_completed'
|
||||
EVENT_CUSTOMER_ISSUE_UPDATED = 'customer_issue_updated'
|
||||
EVENT_SCORE_ALERT = 'score_alert' ← Phase 27
|
||||
EVENT_SCHEDULED_INSPECTION = 'scheduled_inspection' ← Phase 36
|
||||
```
|
||||
|
||||
### Per-Contract Additional Recipients (Phase 33)
|
||||
@@ -654,6 +675,7 @@ Contract recipients fire **regardless of matrix role toggles** — they are addi
|
||||
| `POST /notifications/check-sla` | SLA breach/at-risk alerts | `*/30 * * * *` |
|
||||
| `POST /notifications/cleanup-tokens` | Purge expired API tokens | `0 3 * * *` |
|
||||
| `POST /notifications/check-score-trends` | Facility score drop alerts (Phase 27) | `0 8 * * *` |
|
||||
| `POST /scheduled-inspections/run` | Scheduled inspection reminders — advance/due to inspector, overdue to admin/director (Phase 36) | `*/30 * * * *` |
|
||||
|
||||
---
|
||||
|
||||
@@ -733,7 +755,8 @@ phase1_projects_roles → phase6_features → phase7_mobile_api → phase8_notif
|
||||
→ phase32_device_token_columns
|
||||
→ phase33_contract_recipients
|
||||
→ phase34_facility_qr
|
||||
→ phase35_issue_handler ← HEAD
|
||||
→ phase35_issue_handler
|
||||
→ phase36_scheduled_insp ← HEAD
|
||||
```
|
||||
|
||||
### phase21_performance_indexes
|
||||
@@ -839,6 +862,19 @@ flask db upgrade
|
||||
sudo systemctl restart gunicorn
|
||||
```
|
||||
|
||||
### phase36_scheduled_insp
|
||||
|
||||
Revision id `phase36_scheduled_insp` (file `phase36_scheduled_inspections.py`). Creates `scheduled_inspections` (planned/recurring inspection assignments) and adds `inspections.scheduled_inspection_id` (FK → scheduled_inspections, SET NULL) that links a completed inspection back to the schedule that prompted it. See §5 `ScheduledInspection` and the Scheduled Inspections notes in §7/§11. `INFORMATION_SCHEMA` checks — safe to re-run.
|
||||
|
||||
**Deploy order:**
|
||||
```bash
|
||||
flask db upgrade
|
||||
sudo systemctl restart gunicorn
|
||||
# Add to cron (reminders — advance/due to inspector, overdue to admin/director):
|
||||
# */30 * * * * curl -s -X POST https://yourdomain.com/scheduled-inspections/run \
|
||||
# -d "token=YOUR_DIGEST_SECRET"
|
||||
```
|
||||
|
||||
**Deploy order for phases 24–32:**
|
||||
```bash
|
||||
flask db upgrade
|
||||
@@ -1096,6 +1132,8 @@ timeout = 30
|
||||
-d "secret=SECRET"
|
||||
0 8 * * * curl -s -X POST https://your-domain.com/notifications/check-score-trends \
|
||||
-d "token=SECRET"
|
||||
*/30 * * * * curl -s -X POST https://your-domain.com/scheduled-inspections/run \
|
||||
-d "token=SECRET"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user