Files
Starseed/docs/specs/M5-tickets-pesee/prompts/ERP-184-pont-bascule.md
T
Matthieu 312c119c06 feat(logistique) : entité WeighingTicket + dette site.code (ERP-183)
Entité WeighingTicket
- Entité métier complète (#[Auditable], TimestampableBlamableTrait, relations
  ORM Client/Supplier/Site) + contrat de sérialisation à 3 maillons
  (weighing_ticket:read / :item:read + contextes par opération).
- Getters calculés displayDate et plateFreeFormat (#[SerializedName]),
  sécurité view/manage, pas de Delete/archive.
- Validation #[Assert\*] messages FR + #[Assert\Callback] RG-5.03 (->atPath()),
  libellé i18n audit.entity.logistique_weighingticket.
- Repository : interface Domain + DoctrineWeighingTicketRepository
  (recherche + tri number DESC, deletedAt IS NULL).

Dette site.code
- Site.code mappé VARCHAR(8) (groupes read/write), dérivation auto au
  PrePersist (2 premiers chiffres du CP), UniqueConstraint uq_site_code.
- Migration Version20260617160000 : ALTER COLUMN code SET NOT NULL + COMMENT.
- Fixtures (codes 86/17/82) et SiteApiTest ajustés.

Câblage
- doctrine.yaml : mapping ORM du module Logistique (absent du scaffold ERP-181).
- ColumnCommentsCatalog : site.code + table weighing_ticket.

Specs M5 versionnées (spec-back / spec-front / prompts).
2026-06-18 14:37:16 +02:00

2.4 KiB

Prompt d'implémentation — M5 · ERP-184 (1.4) — Pesée pont bascule (stub + DSD + endpoint)

Projet Starseed. Tâche back. Lis CLAUDE.md, .claude/rules/backend.md et la spec : docs/specs/M5-tickets-pesee/spec-back.md (§ 2.6, § 2.7, § 4.2). Prérequis : ERP-182.

Mission

Implémenter la pesée déclenchée par les boutons « Pesée bascule » / « Pesée manuelle » : stub (pas de liaison matérielle au M5) + allocateur DSD + endpoint API.

Étapes

  1. Contrat Logistique\Domain\Contract\WeighbridgeReaderInterface :
    public function read(SiteInterface $site): WeighbridgeReading; // {weight:int kg, dsd:int}
    
    • WeighbridgeUnavailableException.
  2. Impl Logistique\Infrastructure\Weighbridge\RandomWeighbridgeReader : weight = random_int(10000, 50000) (RG-5.06), dsd = DsdAllocator::next($site).
  3. DsdAllocator (service) : compteur DSD par site sur weighbridge_dsd_counter, incrément avec verrou ligne SELECT ... FOR UPDATE dans une transaction.
    • AUTO : incrémente et renvoie la nouvelle valeur.
    • MANUAL : dsd = dernier dsd du site + 1 (RG-5.04).
  4. Endpoint POST /api/weighbridge_readings — ressource virtuelle (DTO WeighbridgeReadingInput/Output) + Processor dédié, pas de controller Symfony :
    • { "mode": "AUTO" }{ weight, dsd, mode } (site courant via CurrentSiteProviderInterface).
    • { "mode": "MANUAL", "weight": <int>, "manualNumber": "<str>" }{ weight, dsd, manualNumber, mode }.
    • Erreur WeighbridgeUnavailableExceptionHTTP 503 explicite « Pont bascule indisponible — passez en pesée manuelle » (RG-5.06).
    • Sécurité is_granted('logistique.weighing_tickets.manage').
  5. Le dsd renvoyé est prévisionnel : noter en commentaire que l'attribution autoritaire est refaite à la création du ticket (ERP-185).

Garde-fous

  • declare(strict_types=1); ; commentaires FR.
  • Consommer CurrentSiteProviderInterface (contrat Sites) — pas d'import de logique d'un autre module.
  • Pas de controller sous /api (API Platform).

Vérification

  • make test : WeighbridgeReaderStubTest (poids ∈ [10000,50000] + chemin erreur → 503), DsdAllocatorTest (AUTO incrémente / MANUAL = dernier+1 / par site).
  • make php-cs-fixer-allow-risky.
  • Appel manuel POST /api/weighbridge_readings {AUTO} (token Usine) → poids + dsd cohérents.