- pont : stocke legacy_dept (dept osTicket) sur le Dispatch Job + backfill des 70 existants - useHelpers.jobColor/legacyDeptColor : palette comme legacy (Installation vert, Réparation or, Télé rose, Téléphonie vert pâle, Désinstallation rouge foncé) ; tech en pause = rouge vif prioritaire - store _mapJob : expose legacyDept + legacyTicketId - RightPanel : champ « Ticket legacy » (#id · dept) — le client est déjà un lien cliquable vers la fiche - doc mise à jour Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
4.7 KiB
Pont legacy → Dispatch (osTicket → Dispatch Job) — Handoff dev
Tire régulièrement les tickets ouverts assignés au compte « Tech Targo » dans la
DB legacy (osTicket/MariaDB gestionclient) et crée/maj un Dispatch Job ERPNext
pour les répartir (grille Planification / tableau Dispatch).
Pourquoi « Tech Targo » = staff id 3301
Dans le legacy, le travail terrain à dispatcher est assigné au compte générique
« Tech Targo » (staff.id = 3301, username tech) — c'est le default_staff des
départements techniciens (Installation/Réparation/Fibre). Filtre du pont :
ticket.status='open' AND ticket.assign_to=3301. (~70 tickets au démarrage.)
Override possible via LEGACY_TARGO_STAFF_ID.
Surfaces
| Quoi | Où |
|---|---|
| Module | services/targo-hub/lib/legacy-dispatch-sync.js |
| Routage + scheduler | services/targo-hub/server.js (/dispatch/legacy-sync, startSync() au boot) |
| Champ idempotence | Custom Field Dispatch Job.legacy_ticket_id (dispatch-app/frappe-setup/setup_dispatch_custom_fields.py) |
| Conso côté UI | Pool « à assigner » du tableau Dispatch + panneau « Jobs à assigner » de la Planification |
Mapping ticket legacy → Dispatch Job
| Dispatch Job | Source legacy | Notes |
|---|---|---|
legacy_ticket_id |
ticket.id |
clé d'idempotence (lookup avant create) ; affiché dans le panneau détail |
legacy_dept |
ticket_dept.name |
département granulaire → coloriage des cartes « comme legacy » |
ticket_id |
'LEG-' + ticket.id |
nom lisible du DJ |
subject |
ticket.subject |
+ adresse ajoutée si pas de Service Location |
customer |
Customer où legacy_account_id = ticket.account_id |
61/70 matchés ; sinon laissé vide |
service_location + latitude/longitude |
Service Location du customer (ville qui matche) |
→ pin carte |
job_type |
ticket.dept_id → {Installation, Réparation, Retrait, Autre} |
valeurs valides du Select |
scheduled_date |
ticket.due_date (epoch) |
converti America/Toronto (anti-décalage UTC) |
start_time |
ticket.due_time |
HH:MM tel quel · am→08:00 · pm→13:00 · day→aucune |
priority |
ticket.priority (1/2/≥3) |
→ low / medium / high |
duration_h |
défaut par type | Install 2h · Répar 1.5h · autre 1h (le legacy n'en a pas) |
status |
— | toujours open (pool ; PAS auto-assigné à un tech précis) |
Comportement
- Idempotent : 1 ticket legacy = 1 Dispatch Job (clé
legacy_ticket_id). Re-run ⇒ 0 doublon. - Ne clobbe PAS le répartiteur : un DJ déjà assigné/déplacé n'est plus touché ; maj de
scheduled_dateseulement tant qu'il est encoreopen+ non assigné. - SÉQUENTIEL (frappe_pg ne supporte pas la concurrence) — pas de
Promise.all.
Coloriage des cartes (comme legacy)
jobColor() (apps/ops/src/composables/useHelpers.js → legacyDeptColor) colore par legacyDept :
Installation(Fibre)/Monteur/Fusionneur → vert #46992f · Réparation(Fibre) → or #f1c84b ·
Télé (install/réparation) → rose #ec5fb0 · Téléphonie → vert pâle #8fce93 ·
Désinstallation → rouge foncé #c0392b. (Tech en pause → rouge vif, priorité.) Le store
(_mapJob) expose legacyDept/legacyTicketId ; le pool « non-assigné » est déjà trié par scheduledDate.
Endpoints
GET /dispatch/legacy-sync/preview— dry-run, 0 écriture : ce qui serait créé + matching client/SL + non-matchés.POST /dispatch/legacy-sync/run— exécute la synchro (création/maj). Retourne{tickets, created, updated, skipped, errors, unmatched_customer}.
Récurrence
startSync() (server.js, au boot) — opt-in via env :
LEGACY_DISPATCH_SYNC=on # active la récurrence (sinon preview/run manuels seulement)
LEGACY_DISPATCH_SYNC_MIN=15 # période en minutes (défaut 15)
Posé dans /opt/targo-hub/.env. ⚠️ Après modif de .env, recréer le conteneur
(cd /opt/targo-hub && docker compose up -d) — docker restart ne relit pas l'env_file.
1er passage différé de 90 s après le boot, puis toutes les MIN minutes.
État (mise en service 2026-06-06)
70 tickets importés (0 erreur, 9 clients non matchés = comptes post-migration + 2 tickets internes « FORMATION EN HAUTEUR »). Récurrence active (15 min).
TODO / idées
- Fermer/annuler le Dispatch Job quand le ticket legacy passe
closed(v1 ne gère que open). - Filtrer les départements non-terrain (ToDo, Support Informatique, Conception…) si bruit.
- Matcher les 9 clients manquants (créer le Customer ou enrichir
legacy_account_id). - Écrire en retour le tech assigné / la date vers le legacy (bidirectionnel) — non fait (lecture seule legacy).