feat : cycle de vie brouillon/validé du ticket de pesée (ERP-193)
Une pesée (bascule ou manuelle) s'enregistre désormais dès la validation de sa
modale, sans exiger la contrepartie ni l'immatriculation : le ticket naît
« brouillon » (status DRAFT, sans numéro). Le bouton « Valider » finalise quand
les 3 champs du haut (contrepartie + champ associé + immatriculation) ET les 2
pesées sont renseignés : attribution du numéro {siteCode}-TP-{NNNN} et passage
en VALIDATED, puis ouverture du bon de pesée PDF.
Back : counterparty_type/immatriculation/number nullables + colonne status
(migration racine), contraintes strictes déplacées en groupe de validation
finalize, opération PATCH /weighing_tickets/{id}/validate, numéro attribué à la
validation. Front : 4 champs en haut hors blocs, persistance immédiate des
pesées, écrans Ajouter/Modifier refondus, colonne Statut dans la liste, form à
plat pleine largeur. Tests back (lifecycle brouillon/validate) + front à jour.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||
<!-- Padding vertical piloté par la page (1er bloc sans pt, dernier sans pb). -->
|
||||
<div>
|
||||
<!-- En-tête du bloc : titre + boutons de pesée (bascule / manuelle). -->
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-[20px] font-semibold text-m-primary">{{ title }}</h2>
|
||||
@@ -23,122 +24,79 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex flex-col gap-4">
|
||||
<!-- Ligne 1 : contrepartie (type en col 1 + champ conditionnel en col 2),
|
||||
rendue par le parent (bloc vide uniquement) via le slot. -->
|
||||
<div v-if="$slots.counterparty" class="grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<slot name="counterparty" />
|
||||
</div>
|
||||
<!-- Ligne : Date/heure, Poids, DSD. L'immatriculation et « Tout format »
|
||||
vivent désormais dans les 4 champs du haut, hors des blocs (ERP-193). -->
|
||||
<div class="mt-6 grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<!-- Date/heure de la pesée — date du jour + heure courante par défaut
|
||||
(RG-5.07), ré-horodatée à la validation de la pesée. -->
|
||||
<MalioDateTime
|
||||
:model-value="block.date"
|
||||
:label="t('logistique.weighingTickets.form.date')"
|
||||
:required="true"
|
||||
:editable="true"
|
||||
:disabled="disabled"
|
||||
:error="errors.date"
|
||||
@update:model-value="(v: string | null) => emitBlock('date', v)"
|
||||
/>
|
||||
|
||||
<!-- Ligne 2 : Date, Poids, DSD, Immatriculation. -->
|
||||
<div class="grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<!-- Date/heure de la pesée — date du jour + heure courante par défaut
|
||||
(RG-5.07). MalioDateTime : on enregistre l'instant réel de la pesée
|
||||
(jamais 00:00:00), le back stocke un TIMESTAMP. -->
|
||||
<MalioDateTime
|
||||
:model-value="block.date"
|
||||
:label="t('logistique.weighingTickets.form.date')"
|
||||
:required="true"
|
||||
:editable="true"
|
||||
:disabled="disabled"
|
||||
:error="errors.date"
|
||||
@update:model-value="(v: string | null) => emitBlock('date', v)"
|
||||
/>
|
||||
<!-- Poids : champ texte verrouillé sur les chiffres, toujours désactivé
|
||||
(rempli par la pesée, jamais saisi à la main — RG-5.07). -->
|
||||
<MalioInputText
|
||||
:model-value="weightDisplay"
|
||||
:mask="NUMERIC_MASK"
|
||||
:label="t('logistique.weighingTickets.form.weight')"
|
||||
:required="true"
|
||||
:disabled="true"
|
||||
:error="errors.weight"
|
||||
/>
|
||||
|
||||
<!-- Poids : champ texte verrouillé sur les chiffres, toujours désactivé
|
||||
(rempli par la pesée, jamais saisi à la main — RG-5.07). Unité Kg
|
||||
dans le label. -->
|
||||
<MalioInputText
|
||||
:model-value="weightDisplay"
|
||||
:mask="NUMERIC_MASK"
|
||||
:label="t('logistique.weighingTickets.form.weight')"
|
||||
:required="true"
|
||||
:disabled="true"
|
||||
:error="errors.weight"
|
||||
/>
|
||||
|
||||
<!-- DSD : champ texte verrouillé sur les chiffres, toujours désactivé
|
||||
(rempli par la pesée — RG-5.04 / RG-5.07). -->
|
||||
<MalioInputText
|
||||
:model-value="dsdDisplay"
|
||||
:mask="NUMERIC_MASK"
|
||||
:label="t('logistique.weighingTickets.form.dsd')"
|
||||
:required="true"
|
||||
:disabled="true"
|
||||
:error="errors.dsd"
|
||||
/>
|
||||
|
||||
<!-- Immatriculation : masque XX-000-XX (plaque FR SIV) ; en « Tout format »,
|
||||
masque ÉLARGI (lettres/chiffres/espace/tiret, MAJ) pour les plaques
|
||||
anciennes/étrangères, mais sans laisser passer n'importe quoi.
|
||||
PARTAGÉE entre les 2 blocs (RG-5.01) — v-model remonté au form parent.
|
||||
TODO migrer le masque plaque quand @malio/layer-ui couvrira le format. -->
|
||||
<MalioInputText
|
||||
:model-value="immatriculation"
|
||||
:mask="plateFreeFormat ? FREE_PLATE_MASK : PLATE_MASK"
|
||||
:label="t('logistique.weighingTickets.form.immatriculation')"
|
||||
:required="true"
|
||||
:disabled="disabled"
|
||||
:error="errors.immatriculation"
|
||||
@update:model-value="(v: string | null) => $emit('update:immatriculation', v)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Ligne 3 : « Tout format » (désactive le masque plaque). Partagé entre
|
||||
blocs (RG-5.01). Sur sa propre ligne. -->
|
||||
<div class="grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<MalioCheckbox
|
||||
:id="`${blockId}-plate-free-format`"
|
||||
:model-value="plateFreeFormat"
|
||||
:label="t('logistique.weighingTickets.form.plateFreeFormat')"
|
||||
group-class="self-center"
|
||||
:disabled="disabled"
|
||||
@update:model-value="(v: boolean) => $emit('update:plateFreeFormat', v)"
|
||||
/>
|
||||
</div>
|
||||
<!-- DSD : champ texte verrouillé sur les chiffres, toujours désactivé
|
||||
(rempli par la pesée — RG-5.04 / RG-5.07). -->
|
||||
<MalioInputText
|
||||
:model-value="dsdDisplay"
|
||||
:mask="NUMERIC_MASK"
|
||||
:label="t('logistique.weighingTickets.form.dsd')"
|
||||
:required="true"
|
||||
:disabled="true"
|
||||
:error="errors.dsd"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { WeighingBlockState } from '~/modules/logistique/composables/useWeighingTicketForm'
|
||||
import { NUMERIC_MASK, PLATE_MASK, FREE_PLATE_MASK } from '~/modules/logistique/utils/weighingMasks'
|
||||
import { NUMERIC_MASK } from '~/modules/logistique/utils/weighingMasks'
|
||||
|
||||
/**
|
||||
* Bloc de pesée (« Poids à vide » ou « Poids à plein ») de l'écran Ticket de pesée.
|
||||
* Champs Date / Poids / DSD / Immatriculation / « Tout format » + boutons de pesée.
|
||||
* L'immatriculation et « Tout format » sont PARTAGÉS entre les 2 blocs (RG-5.01) :
|
||||
* portés par le form parent et remontés en `update:*`. Le slot `counterparty`
|
||||
* permet au parent d'injecter la contrepartie sur le seul bloc vide (RG-5.03).
|
||||
* Masques de saisie factorisés dans `utils/weighingMasks`.
|
||||
* Champs Date/heure / Poids / DSD + boutons de pesée (bascule / manuelle). Depuis
|
||||
* ERP-193, la contrepartie, l'immatriculation et « Tout format » sont remontés dans
|
||||
* les 4 champs du haut de page (hors blocs). Masque numérique factorisé dans
|
||||
* `utils/weighingMasks`.
|
||||
*/
|
||||
|
||||
const props = defineProps<{
|
||||
const props = withDefaults(defineProps<{
|
||||
/** Identifiant technique du bloc (pour les `id` de champs uniques). */
|
||||
blockId: string
|
||||
title: string
|
||||
block: WeighingBlockState
|
||||
/** Immatriculation partagée (RG-5.01) — portée par le form parent. */
|
||||
immatriculation: string | null
|
||||
/** « Tout format » partagé (RG-5.01) — porté par le form parent. */
|
||||
plateFreeFormat: boolean
|
||||
/** Erreurs 422 par champ (propertyPath → message). */
|
||||
errors?: Record<string, string>
|
||||
disabled?: boolean
|
||||
}>()
|
||||
}>(), {
|
||||
errors: () => ({}),
|
||||
disabled: false,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:block': [field: keyof WeighingBlockState, value: unknown]
|
||||
'update:immatriculation': [value: string | null]
|
||||
'update:plateFreeFormat': [value: boolean]
|
||||
'request-auto': []
|
||||
'request-manual': []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const errors = computed(() => props.errors ?? {})
|
||||
|
||||
// Poids / DSD : champs texte → on présente l'entier sous forme de chaîne (vide
|
||||
// tant que la pesée n'a pas rempli la valeur).
|
||||
const weightDisplay = computed(() => (props.block.weight === null ? '' : String(props.block.weight)))
|
||||
|
||||
@@ -16,17 +16,17 @@ describe('useWeighingTicketForm', () => {
|
||||
})
|
||||
|
||||
// ── Omission des requis vides (compact) ──────────────────────────────────
|
||||
it('buildCreatePayload omet les clés null (requis vides absents, pas envoyés à null)', () => {
|
||||
it('buildDraftPayload : brouillon vierge → pas de champ requis ni de bloc non pesé', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
// Formulaire vierge : counterpartyType / immatriculation non remplis.
|
||||
const payload = form.buildCreatePayload()
|
||||
// Absents (et non null) → le back applique NotBlank (message métier) plutôt
|
||||
// qu'une erreur de type opaque (« doit être de type string »).
|
||||
// Formulaire vierge : counterpartyType / immatriculation non remplis, aucune pesée.
|
||||
const payload = form.buildDraftPayload()
|
||||
// Absents (et non null) → le back laisse jouer les contraintes du groupe finalize.
|
||||
expect(payload).not.toHaveProperty('counterpartyType')
|
||||
expect(payload).not.toHaveProperty('immatriculation')
|
||||
// Bloc non pesé → ni poids ni date (on n'envoie pas une date de pesée sans pesée).
|
||||
expect(payload).not.toHaveProperty('emptyWeight')
|
||||
// Les non-null restent : date/heure courante + booléen Tout format.
|
||||
expect(payload.emptyDate).toBe('2026-06-22T08:30:00')
|
||||
expect(payload).not.toHaveProperty('emptyDate')
|
||||
// Seul le booléen « Tout format » reste.
|
||||
expect(payload.plateFreeFormat).toBe(false)
|
||||
})
|
||||
|
||||
@@ -53,7 +53,7 @@ describe('useWeighingTicketForm', () => {
|
||||
expect(form.supplierIri.value).toBeNull()
|
||||
expect(form.otherLabel.value).toBeNull()
|
||||
|
||||
const payload = form.buildCreatePayload()
|
||||
const payload = form.buildDraftPayload()
|
||||
expect(payload.counterpartyType).toBe('CLIENT')
|
||||
expect(payload.client).toBe('/api/clients/629')
|
||||
expect(payload).not.toHaveProperty('supplier')
|
||||
@@ -68,7 +68,7 @@ describe('useWeighingTicketForm', () => {
|
||||
|
||||
expect(form.counterpartyField.value).toBe('supplier')
|
||||
expect(form.clientIri.value).toBeNull()
|
||||
expect(form.buildCreatePayload().supplier).toBe('/api/suppliers/7')
|
||||
expect(form.buildDraftPayload().supplier).toBe('/api/suppliers/7')
|
||||
})
|
||||
|
||||
it('AUTRE : ne conserve que le libellé libre', () => {
|
||||
@@ -79,7 +79,7 @@ describe('useWeighingTicketForm', () => {
|
||||
|
||||
expect(form.counterpartyField.value).toBe('other')
|
||||
expect(form.clientIri.value).toBeNull()
|
||||
expect(form.buildCreatePayload().otherLabel).toBe('Reprise interne')
|
||||
expect(form.buildDraftPayload().otherLabel).toBe('Reprise interne')
|
||||
})
|
||||
|
||||
// ── Immatriculation / « Tout format » partagés entre blocs (RG-5.01) ──────
|
||||
@@ -88,11 +88,11 @@ describe('useWeighingTicketForm', () => {
|
||||
form.immatriculation.value = 'AB-123-CD'
|
||||
form.plateFreeFormat.value = true
|
||||
|
||||
// Les 2 payloads (création + finalisation) reflètent la même valeur.
|
||||
expect(form.buildCreatePayload().immatriculation).toBe('AB-123-CD')
|
||||
expect(form.buildCreatePayload().plateFreeFormat).toBe(true)
|
||||
expect(form.buildFullPayload().immatriculation).toBe('AB-123-CD')
|
||||
expect(form.buildFullPayload().plateFreeFormat).toBe(true)
|
||||
// Les 2 payloads (brouillon + validation) reflètent la même valeur.
|
||||
expect(form.buildDraftPayload().immatriculation).toBe('AB-123-CD')
|
||||
expect(form.buildDraftPayload().plateFreeFormat).toBe(true)
|
||||
expect(form.buildValidatePayload().immatriculation).toBe('AB-123-CD')
|
||||
expect(form.buildValidatePayload().plateFreeFormat).toBe(true)
|
||||
})
|
||||
|
||||
// ── Application d'une lecture de pesée ────────────────────────────────────
|
||||
@@ -113,23 +113,28 @@ describe('useWeighingTicketForm', () => {
|
||||
expect(form.full.manualNumber).toBe('PAP-555')
|
||||
})
|
||||
|
||||
it('buildCreatePayload porte la pesée à vide, buildFullPayload la pesée à plein', () => {
|
||||
it('buildDraftPayload porte les pesées effectuées ; buildValidatePayload les 4 champs du haut', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
form.setCounterpartyType('CLIENT')
|
||||
form.clientIri.value = '/api/clients/1'
|
||||
form.immatriculation.value = 'AB-123-CD'
|
||||
form.applyReading(form.empty, { weight: 7150, dsd: 1, mode: 'AUTO' })
|
||||
form.applyReading(form.full, { weight: 14300, dsd: 2, mode: 'AUTO' })
|
||||
|
||||
const create = form.buildCreatePayload()
|
||||
expect(create.emptyWeight).toBe(7150)
|
||||
expect(create.emptyDsd).toBe(1)
|
||||
expect(create.emptyMode).toBe('AUTO')
|
||||
expect(create).not.toHaveProperty('fullWeight')
|
||||
// Le brouillon porte LES DEUX pesées effectuées.
|
||||
const draft = form.buildDraftPayload()
|
||||
expect(draft.emptyWeight).toBe(7150)
|
||||
expect(draft.emptyMode).toBe('AUTO')
|
||||
expect(draft.fullWeight).toBe(14300)
|
||||
expect(draft.fullMode).toBe('AUTO')
|
||||
|
||||
const full = form.buildFullPayload()
|
||||
expect(full.fullWeight).toBe(14300)
|
||||
expect(full.fullDsd).toBe(2)
|
||||
expect(full.fullMode).toBe('AUTO')
|
||||
// La validation ne porte que les 4 champs du haut (pesées déjà persistées).
|
||||
const validate = form.buildValidatePayload()
|
||||
expect(validate.counterpartyType).toBe('CLIENT')
|
||||
expect(validate.client).toBe('/api/clients/1')
|
||||
expect(validate.immatriculation).toBe('AB-123-CD')
|
||||
expect(validate).not.toHaveProperty('emptyWeight')
|
||||
expect(validate).not.toHaveProperty('fullWeight')
|
||||
})
|
||||
|
||||
// ── Pré-remplissage (écran Modification, ERP-190) ─────────────────────────
|
||||
@@ -174,10 +179,11 @@ describe('useWeighingTicketForm', () => {
|
||||
expect(form.empty.weight).toBeNull()
|
||||
})
|
||||
|
||||
it('buildUpdatePayload fusionne contrepartie + véhicule + les 2 pesées', () => {
|
||||
it('buildDraftPayload après hydrate porte contrepartie + véhicule + les 2 pesées', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
form.hydrate({
|
||||
id: 9,
|
||||
status: 'VALIDATED',
|
||||
counterpartyType: 'CLIENT',
|
||||
client: { '@id': '/api/clients/629' },
|
||||
immatriculation: 'AB-123-CD',
|
||||
@@ -185,7 +191,9 @@ describe('useWeighingTicketForm', () => {
|
||||
fullWeight: 14300, fullDsd: 2, fullMode: 'AUTO',
|
||||
})
|
||||
|
||||
const payload = form.buildUpdatePayload()
|
||||
expect(form.status.value).toBe('VALIDATED')
|
||||
|
||||
const payload = form.buildDraftPayload()
|
||||
expect(payload.counterpartyType).toBe('CLIENT')
|
||||
expect(payload.client).toBe('/api/clients/629')
|
||||
expect(payload.emptyWeight).toBe(7150)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { WeighbridgeMode } from '~/modules/logistique/composables/useWeighbridge'
|
||||
import type { CounterpartyType } from '~/modules/logistique/composables/useWeighingTicketForm'
|
||||
import type { CounterpartyType, WeighingTicketStatus } from '~/modules/logistique/composables/useWeighingTicketForm'
|
||||
|
||||
/**
|
||||
* Détail d'un ticket de pesée (`GET /api/weighing_tickets/{id}`, spec-back
|
||||
@@ -8,11 +8,13 @@ import type { CounterpartyType } from '~/modules/logistique/composables/useWeigh
|
||||
*/
|
||||
export interface WeighingTicketDetail {
|
||||
id: number
|
||||
/** Numéro `{siteCode}-TP-{NNNN}` — immuable (RG-5.09). */
|
||||
number: string
|
||||
/** Cycle de vie (DRAFT/VALIDATED, ERP-193). */
|
||||
status?: WeighingTicketStatus
|
||||
/** Numéro `{siteCode}-TP-{NNNN}` — null tant que brouillon, immuable ensuite (RG-5.09). */
|
||||
number?: string | null
|
||||
/** Site rattaché (embarqué) — immuable (RG-5.09). */
|
||||
site?: { id: number, name: string, code: string } | null
|
||||
counterpartyType: CounterpartyType
|
||||
counterpartyType?: CounterpartyType | null
|
||||
client?: { '@id': string, companyName: string } | null
|
||||
supplier?: { '@id': string, companyName: string } | null
|
||||
otherLabel?: string | null
|
||||
|
||||
@@ -11,12 +11,13 @@ import type { WeighbridgeMode } from '~/modules/logistique/composables/useWeighb
|
||||
* - **Contrepartie conditionnelle (RG-5.03)** : `counterpartyType` (CLIENT /
|
||||
* FOURNISSEUR / AUTRE) pilote le champ requis (client / supplier / otherLabel).
|
||||
* Changer de type purge les champs des autres types — aucune donnée fantôme.
|
||||
* - **Immatriculation + « Tout format » partagés entre les 2 blocs (RG-5.01)** :
|
||||
* une seule valeur (refs uniques) — modifier l'un met à jour l'autre puisque
|
||||
* les 2 blocs bindent la même ref.
|
||||
* - **Workflow 2 temps** : `buildCreatePayload()` (POST à l'« Enregistrer » du
|
||||
* bloc vide) crée le ticket avec la pesée à vide ; `buildFullPayload()` (PATCH
|
||||
* au « Valider ») ajoute la pesée à plein (net recalculé serveur, RG-5.05).
|
||||
* - **Immatriculation + « Tout format »** font partie des 4 champs du haut, hors
|
||||
* blocs (ERP-193). Une seule valeur, partagée entre les 2 pesées (RG-5.01).
|
||||
* - **Cycle brouillon -> validé (ERP-193)** : `buildDraftPayload()` persiste l'état
|
||||
* courant (pesée enregistrée dès la validation de sa modale, même sans
|
||||
* contrepartie/immat) via POST (création du brouillon) puis PATCH ; quand les 3
|
||||
* champs du haut + les 2 pesées sont là, `buildValidatePayload()` finalise via
|
||||
* `PATCH /weighing_tickets/{id}/validate` (numéro attribué, status VALIDATED).
|
||||
*
|
||||
* Composable UI-agnostique et testable : aucune dépendance API ici (les appels
|
||||
* vivent dans l'écran via `useApi`). Instancié PAR écran (refs locales).
|
||||
@@ -39,10 +40,14 @@ export interface WeighingBlockState {
|
||||
manualNumber: string | null
|
||||
}
|
||||
|
||||
/** Cycle de vie du ticket (miroir back, ERP-193). */
|
||||
export type WeighingTicketStatus = 'DRAFT' | 'VALIDATED'
|
||||
|
||||
/** Forme minimale d'un détail de ticket consommée par `hydrate` (cf. useWeighingTicket). */
|
||||
export interface WeighingTicketHydration {
|
||||
id: number
|
||||
counterpartyType: CounterpartyType
|
||||
status?: WeighingTicketStatus
|
||||
counterpartyType?: CounterpartyType | null
|
||||
client?: { '@id': string } | null
|
||||
supplier?: { '@id': string } | null
|
||||
otherLabel?: string | null
|
||||
@@ -124,9 +129,13 @@ export function useWeighingTicketForm() {
|
||||
const empty = reactive<WeighingBlockState>(emptyBlock(now))
|
||||
const full = reactive<WeighingBlockState>(emptyBlock(now))
|
||||
|
||||
// Id du ticket créé (POST du bloc vide) — pilote le PATCH du bloc plein.
|
||||
// Id du ticket persisté (POST du 1er enregistrement de pesée) — pilote ensuite
|
||||
// les PATCH (brouillon) puis la validation. Null tant que rien n'est persisté.
|
||||
const ticketId = ref<number | null>(null)
|
||||
|
||||
// Cycle de vie courant (DRAFT tant que non validé, ERP-193).
|
||||
const status = ref<WeighingTicketStatus>('DRAFT')
|
||||
|
||||
/**
|
||||
* Champ de contrepartie attendu selon le type courant — utilisé par l'écran
|
||||
* pour afficher conditionnellement le bon champ (RG-5.03).
|
||||
@@ -183,22 +192,35 @@ export function useWeighingTicketForm() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Payload de CRÉATION (POST /weighing_tickets, spec-back § 4.3) : contrepartie
|
||||
* + véhicule + pesée à VIDE. Le numéro, le site et le net sont attribués
|
||||
* serveur (rien à envoyer). Les noms de champs miroir des `propertyPath` back
|
||||
* pour que `useFormErrors` mappe les 422 inline.
|
||||
* Champs d'un bloc de pesée, UNIQUEMENT s'il a été pesé (poids renseigné) — on
|
||||
* n'envoie pas la date par défaut d'un bloc vierge (sinon le back stockerait une
|
||||
* date de pesée sans poids). Noms de clés alignés sur les `propertyPath` back.
|
||||
*/
|
||||
function buildCreatePayload(): Record<string, unknown> {
|
||||
function blockPayload(prefix: 'empty' | 'full', block: WeighingBlockState): Record<string, unknown> {
|
||||
if (block.weight === null) return {}
|
||||
return {
|
||||
[`${prefix}Date`]: block.date,
|
||||
[`${prefix}Weight`]: block.weight,
|
||||
[`${prefix}Dsd`]: block.dsd,
|
||||
[`${prefix}Mode`]: block.mode,
|
||||
[`${prefix}ManualNumber`]: block.manualNumber || null,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Payload de BROUILLON (POST création / PATCH mise à jour, ERP-193) : l'état
|
||||
* courant complet (4 champs du haut + pesées effectuées). Aucun champ n'est
|
||||
* requis ici (le back valide en mode relâché) — une pesée s'enregistre sans
|
||||
* contrepartie ni immatriculation. Numéro/site/net attribués serveur.
|
||||
*/
|
||||
function buildDraftPayload(): Record<string, unknown> {
|
||||
return compact({
|
||||
counterpartyType: counterpartyType.value,
|
||||
...counterpartyPayload(),
|
||||
immatriculation: immatriculation.value || null,
|
||||
plateFreeFormat: plateFreeFormat.value,
|
||||
emptyDate: empty.date || null,
|
||||
emptyWeight: empty.weight,
|
||||
emptyDsd: empty.dsd,
|
||||
emptyMode: empty.mode,
|
||||
emptyManualNumber: empty.manualNumber || null,
|
||||
...blockPayload('empty', empty),
|
||||
...blockPayload('full', full),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -211,6 +233,7 @@ export function useWeighingTicketForm() {
|
||||
*/
|
||||
function hydrate(detail: WeighingTicketHydration): void {
|
||||
ticketId.value = detail.id
|
||||
status.value = detail.status ?? 'DRAFT'
|
||||
counterpartyType.value = detail.counterpartyType ?? null
|
||||
clientIri.value = detail.client?.['@id'] ?? null
|
||||
supplierIri.value = detail.supplier?.['@id'] ?? null
|
||||
@@ -232,30 +255,18 @@ export function useWeighingTicketForm() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Payload de MODIFICATION (PATCH /weighing_tickets/{id}, ERP-190) : tous les
|
||||
* champs éditables (contrepartie + véhicule + les 2 pesées). Le numéro et le
|
||||
* site sont immuables (RG-5.09, ignorés par le back même si envoyés). Le net
|
||||
* est recalculé serveur (RG-5.05).
|
||||
* Payload de VALIDATION (PATCH /weighing_tickets/{id}/validate, ERP-193) : les
|
||||
* 4 champs du haut (contrepartie + immatriculation + « Tout format »). Les pesées
|
||||
* sont déjà persistées par les enregistrements brouillon ; le back rejoue ici la
|
||||
* validation stricte (groupe `finalize` : 3 champs requis + 2 pesées) et attribue
|
||||
* le numéro. Les `propertyPath` des 422 sont mappés inline par useFormErrors.
|
||||
*/
|
||||
function buildUpdatePayload(): Record<string, unknown> {
|
||||
return { ...buildCreatePayload(), ...buildFullPayload() }
|
||||
}
|
||||
|
||||
/**
|
||||
* Payload de FINALISATION (PATCH /weighing_tickets/{id}, spec-back § 4.4) :
|
||||
* pesée à PLEIN. Le véhicule (immat / tout format) peut avoir été ajusté entre
|
||||
* les 2 blocs → on le repousse aussi (valeur partagée, RG-5.01). Le net est
|
||||
* recalculé serveur (RG-5.05).
|
||||
*/
|
||||
function buildFullPayload(): Record<string, unknown> {
|
||||
function buildValidatePayload(): Record<string, unknown> {
|
||||
return compact({
|
||||
counterpartyType: counterpartyType.value,
|
||||
...counterpartyPayload(),
|
||||
immatriculation: immatriculation.value || null,
|
||||
plateFreeFormat: plateFreeFormat.value,
|
||||
fullDate: full.date || null,
|
||||
fullWeight: full.weight,
|
||||
fullDsd: full.dsd,
|
||||
fullMode: full.mode,
|
||||
fullManualNumber: full.manualNumber || null,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -277,9 +288,9 @@ export function useWeighingTicketForm() {
|
||||
missingWeighingFields,
|
||||
// workflow
|
||||
ticketId,
|
||||
status,
|
||||
hydrate,
|
||||
buildCreatePayload,
|
||||
buildFullPayload,
|
||||
buildUpdatePayload,
|
||||
buildDraftPayload,
|
||||
buildValidatePayload,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { usePaginatedList } from '~/shared/composables/usePaginatedList'
|
||||
import type { WeighingTicketStatus } from '~/modules/logistique/composables/useWeighingTicketForm'
|
||||
|
||||
/**
|
||||
* Vue MINIMALE d'une contrepartie embarquee (Client M1 ou Fournisseur M2) dans la
|
||||
@@ -25,8 +26,10 @@ export interface WeighingTicketParty {
|
||||
*/
|
||||
export interface WeighingTicket {
|
||||
id: number
|
||||
/** Numero metier `{siteCode}-TP-{NNNN}` attribue par site (RG-5.02). */
|
||||
number: string
|
||||
/** Cycle de vie : DRAFT (« En attente ») ou VALIDATED (« Terminée ») — ERP-193. */
|
||||
status: WeighingTicketStatus
|
||||
/** Numero metier `{siteCode}-TP-{NNNN}` — null tant que brouillon (RG-5.02). */
|
||||
number: string | null
|
||||
/** Embarque uniquement si contrepartie = Client (RG-5.03), sinon absent. */
|
||||
client: WeighingTicketParty | null
|
||||
/** Embarque uniquement si contrepartie = Fournisseur (RG-5.03), sinon absent. */
|
||||
|
||||
@@ -48,9 +48,10 @@ const InputStub = defineComponent({
|
||||
},
|
||||
})
|
||||
|
||||
// WeighingBlock stubbe : rend le slot counterparty (présent sur le bloc vide).
|
||||
// WeighingBlock stubbé (Date/Poids/DSD + boutons) — la contrepartie vit désormais
|
||||
// dans les 4 champs du haut, hors bloc (ERP-193).
|
||||
const BlockStub = defineComponent({
|
||||
setup(_, { slots }) { return () => h('div', { 'data-testid': 'block' }, slots.counterparty?.()) },
|
||||
setup() { return () => h('div', { 'data-testid': 'block' }) },
|
||||
})
|
||||
|
||||
const ModalStub = defineComponent({
|
||||
@@ -82,6 +83,7 @@ async function mountPage() {
|
||||
|
||||
const DETAIL = {
|
||||
id: 9,
|
||||
status: 'VALIDATED',
|
||||
number: '86-TP-0001',
|
||||
site: { id: 1, name: 'Chatellerault', code: '86' },
|
||||
counterpartyType: 'CLIENT',
|
||||
@@ -105,11 +107,11 @@ describe('Écran Modification ticket de pesée (page /weighing-tickets/{id}/edit
|
||||
expect(mockFetchTicket).toHaveBeenCalledWith('9')
|
||||
})
|
||||
|
||||
it('bascule des boutons : « Enregistrer » + « Imprimer » présents, pas de « Valider »', async () => {
|
||||
it('ticket validé : action principale « Enregistrer » + « Imprimer » (pas « Valider »)', async () => {
|
||||
const wrapper = await mountPage()
|
||||
// DETAIL.status = VALIDATED → l'action principale s'intitule « Enregistrer ».
|
||||
expect(wrapper.find('[data-label="logistique.weighingTickets.form.save"]').exists()).toBe(true)
|
||||
expect(wrapper.find('[data-label="logistique.weighingTickets.form.print"]').exists()).toBe(true)
|
||||
// « Valider » est le bouton de l'écran d'AJOUT — absent en modification (RG-5.08).
|
||||
expect(wrapper.find('[data-label="logistique.weighingTickets.form.validate"]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
@@ -119,15 +121,24 @@ describe('Écran Modification ticket de pesée (page /weighing-tickets/{id}/edit
|
||||
expect(mockOpen).toHaveBeenCalledWith('/api/weighing_tickets/9/print.pdf', '_blank')
|
||||
})
|
||||
|
||||
it('« Enregistrer » PATCH le ticket puis revient à la liste', async () => {
|
||||
it('« Enregistrer » : PATCH brouillon puis PATCH /validate, retour à la liste', async () => {
|
||||
const wrapper = await mountPage()
|
||||
await wrapper.find('[data-label="logistique.weighingTickets.form.save"]').trigger('click')
|
||||
await flushPromises()
|
||||
// 1. Persistance de l'état courant (brouillon) avec les 2 pesées.
|
||||
expect(mockPatch).toHaveBeenCalledWith(
|
||||
'/weighing_tickets/9',
|
||||
expect.objectContaining({ counterpartyType: 'CLIENT', client: '/api/clients/629', fullWeight: 14300 }),
|
||||
expect.objectContaining({ toast: false }),
|
||||
)
|
||||
// 2. Validation (back autoritaire) — ne porte que les 4 champs du haut.
|
||||
expect(mockPatch).toHaveBeenCalledWith(
|
||||
'/weighing_tickets/9/validate',
|
||||
expect.objectContaining({ counterpartyType: 'CLIENT', immatriculation: 'AB-123-CD' }),
|
||||
expect.objectContaining({ toast: false }),
|
||||
)
|
||||
// « Enregistrer » ouvre aussi le bon de pesée PDF (RG-5.08).
|
||||
expect(mockOpen).toHaveBeenCalledWith('/api/weighing_tickets/9/print.pdf', '_blank')
|
||||
expect(mockPush).toHaveBeenCalledWith('/weighing-tickets')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
import { defineComponent, h, ref, reactive, Suspense } from 'vue'
|
||||
|
||||
// ── Mocks des composables modules (le form RÉEL est conservé). ────────────────
|
||||
const mockPost = vi.hoisted(() => vi.fn())
|
||||
const mockPatch = vi.hoisted(() => vi.fn())
|
||||
const mockPush = vi.hoisted(() => vi.fn())
|
||||
const mockOpen = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.mock('~/modules/logistique/composables/useWeighingTicketReferentials', () => ({
|
||||
useWeighingTicketReferentials: () => ({ clients: ref([]), suppliers: ref([]), load: vi.fn().mockResolvedValue(undefined) }),
|
||||
}))
|
||||
vi.mock('~/modules/logistique/composables/useWeighbridge', () => ({
|
||||
useWeighbridge: () => ({ triggerAuto: vi.fn(), triggerManual: vi.fn(), extractWeighbridgeError: () => 'err' }),
|
||||
}))
|
||||
|
||||
// ── Auto-imports Nuxt stubbés globalement ───────────────────────────────────
|
||||
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||
vi.stubGlobal('useHead', () => undefined)
|
||||
vi.stubGlobal('useApi', () => ({ get: vi.fn(), post: mockPost, patch: mockPatch }))
|
||||
vi.stubGlobal('useRouter', () => ({ push: mockPush }))
|
||||
vi.stubGlobal('usePermissions', () => ({ can: () => true }))
|
||||
vi.stubGlobal('navigateTo', vi.fn())
|
||||
vi.stubGlobal('useFormErrors', () => ({ errors: reactive({}), setError: vi.fn(), clearErrors: vi.fn(), handleApiError: vi.fn() }))
|
||||
globalThis.open = mockOpen
|
||||
|
||||
const NewPage = (await import('../weighing-tickets/new.vue')).default
|
||||
|
||||
const ButtonStub = defineComponent({
|
||||
props: { label: { type: String, default: '' }, disabled: { type: Boolean, default: false } },
|
||||
emits: ['click'],
|
||||
setup(props, { emit }) {
|
||||
return () => h('button', { 'data-label': props.label, onClick: () => emit('click') }, props.label)
|
||||
},
|
||||
})
|
||||
const InputStub = defineComponent({
|
||||
props: { label: { type: String, default: '' }, modelValue: { default: null } },
|
||||
setup(props) { return () => h('input', { 'data-label': props.label, 'value': props.modelValue as string }) },
|
||||
})
|
||||
const BlockStub = defineComponent({ setup() { return () => h('div', { 'data-testid': 'block' }) } })
|
||||
const ModalStub = defineComponent({
|
||||
props: { modelValue: { type: Boolean, default: false } },
|
||||
setup(_, { slots }) { return () => h('div', {}, [slots.header?.(), slots.default?.(), slots.footer?.()]) },
|
||||
})
|
||||
|
||||
const stubs = {
|
||||
MalioButtonIcon: ButtonStub,
|
||||
MalioButton: ButtonStub,
|
||||
MalioInputText: InputStub,
|
||||
MalioSelect: InputStub,
|
||||
MalioDateTime: InputStub,
|
||||
MalioCheckbox: InputStub,
|
||||
MalioModal: ModalStub,
|
||||
WeighingBlock: BlockStub,
|
||||
}
|
||||
|
||||
async function mountPage() {
|
||||
const wrapper = mount(defineComponent({
|
||||
components: { NewPage },
|
||||
setup: () => () => h(Suspense, null, { default: () => h(NewPage) }),
|
||||
}), { global: { stubs } })
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
describe('Écran Ajouter ticket de pesée (page /weighing-tickets/new)', () => {
|
||||
beforeEach(() => {
|
||||
mockPost.mockReset().mockResolvedValue({ id: 42 })
|
||||
mockPatch.mockReset().mockResolvedValue({})
|
||||
mockPush.mockReset()
|
||||
mockOpen.mockReset()
|
||||
})
|
||||
|
||||
it('un seul bouton « Valider » (pas de « Enregistrer » séparé)', async () => {
|
||||
const wrapper = await mountPage()
|
||||
expect(wrapper.find('[data-label="logistique.weighingTickets.form.validate"]').exists()).toBe(true)
|
||||
expect(wrapper.find('[data-label="logistique.weighingTickets.form.save"]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('« Valider » : POST brouillon (création) puis PATCH /validate, PDF + retour liste', async () => {
|
||||
const wrapper = await mountPage()
|
||||
await wrapper.find('[data-label="logistique.weighingTickets.form.validate"]').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
// 1. Création du brouillon (POST) → récupère l'id.
|
||||
expect(mockPost).toHaveBeenCalledWith(
|
||||
'/weighing_tickets',
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ toast: false }),
|
||||
)
|
||||
// 2. Validation (back autoritaire) sur l'id retourné.
|
||||
expect(mockPatch).toHaveBeenCalledWith(
|
||||
'/weighing_tickets/42/validate',
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ toast: false }),
|
||||
)
|
||||
// 3. Ouverture du bon de pesée PDF + retour à la liste.
|
||||
expect(mockOpen).toHaveBeenCalledWith('/api/weighing_tickets/42/print.pdf', '_blank')
|
||||
expect(mockPush).toHaveBeenCalledWith('/weighing-tickets')
|
||||
})
|
||||
})
|
||||
@@ -18,23 +18,14 @@
|
||||
<p v-else-if="error" class="mt-12 text-center text-m-danger">{{ t('logistique.weighingTickets.edit.notFound') }}</p>
|
||||
|
||||
<template v-else>
|
||||
<!-- Numéro + site : immuables (RG-5.09), rappelés dans le titre de l'écran. -->
|
||||
<div class="mt-[48px] flex flex-col gap-8">
|
||||
<!-- ── Bloc « Poids à vide » (porte la contrepartie, RG-5.03) ──── -->
|
||||
<WeighingBlock
|
||||
block-id="empty"
|
||||
:title="t('logistique.weighingTickets.form.emptyBlock')"
|
||||
:block="form.empty"
|
||||
:immatriculation="form.immatriculation.value"
|
||||
:plate-free-format="form.plateFreeFormat.value"
|
||||
:errors="emptyBlockErrors"
|
||||
@update:block="(field, value) => updateBlock('empty', field, value)"
|
||||
@update:immatriculation="(v) => form.immatriculation.value = v"
|
||||
@update:plate-free-format="(v) => form.plateFreeFormat.value = v"
|
||||
@request-auto="openAuto('empty')"
|
||||
@request-manual="openManual('empty')"
|
||||
>
|
||||
<template #counterparty>
|
||||
<!-- Form à plat, pleine largeur (sans box-shadow) : un filet noir 1px
|
||||
sépare chacun des 3 blocs (divide-y). -->
|
||||
<div class="mt-[48px] flex flex-col divide-y divide-black">
|
||||
<!-- ── 4 champs du haut : contrepartie + immatriculation + « Tout
|
||||
format » (ERP-193, hors blocs de pesée). 1er bloc : pas de
|
||||
padding-top (marge titre→form = mt-[48px] standard). ───────── -->
|
||||
<div class="pb-[20px]">
|
||||
<div class="grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<MalioSelect
|
||||
:model-value="form.counterpartyType.value"
|
||||
:options="counterpartyOptions"
|
||||
@@ -72,28 +63,56 @@
|
||||
:error="errors.otherLabel"
|
||||
@update:model-value="(v: string | null) => form.otherLabel.value = v"
|
||||
/>
|
||||
</template>
|
||||
</WeighingBlock>
|
||||
|
||||
<!-- Bloc « Poids à plein » : le bouton « Enregistrer » du bloc vide
|
||||
DISPARAÎT en modification (RG-5.08) — on enregistre via le bas. -->
|
||||
<!-- Pas de cellule vide sans type sélectionné : immat et « Tout
|
||||
format » se collent au type ; le champ conditionnel les
|
||||
décale une fois un type choisi. -->
|
||||
<MalioInputText
|
||||
:model-value="form.immatriculation.value"
|
||||
:mask="form.plateFreeFormat.value ? FREE_PLATE_MASK : PLATE_MASK"
|
||||
:label="t('logistique.weighingTickets.form.immatriculation')"
|
||||
:required="true"
|
||||
:error="errors.immatriculation"
|
||||
@update:model-value="(v: string | null) => form.immatriculation.value = v"
|
||||
/>
|
||||
<MalioCheckbox
|
||||
id="plate-free-format"
|
||||
:model-value="form.plateFreeFormat.value"
|
||||
:label="t('logistique.weighingTickets.form.plateFreeFormat')"
|
||||
group-class="self-center"
|
||||
@update:model-value="(v: boolean) => form.plateFreeFormat.value = v"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ── Bloc « Poids à vide » ──────────────────────────────────── -->
|
||||
<WeighingBlock
|
||||
class="py-[20px]"
|
||||
block-id="empty"
|
||||
:title="t('logistique.weighingTickets.form.emptyBlock')"
|
||||
:block="form.empty"
|
||||
:errors="emptyBlockErrors"
|
||||
@update:block="(field, value) => updateBlock('empty', field, value)"
|
||||
@request-auto="openAuto('empty')"
|
||||
@request-manual="openManual('empty')"
|
||||
/>
|
||||
|
||||
<!-- ── Bloc « Poids à plein » (dernier bloc : pas de padding-bottom,
|
||||
pour ne pas écarter le bouton). ──────────────────────────── -->
|
||||
<WeighingBlock
|
||||
class="pt-[20px]"
|
||||
block-id="full"
|
||||
:title="t('logistique.weighingTickets.form.fullBlock')"
|
||||
:block="form.full"
|
||||
:immatriculation="form.immatriculation.value"
|
||||
:plate-free-format="form.plateFreeFormat.value"
|
||||
:errors="fullBlockErrors"
|
||||
@update:block="(field, value) => updateBlock('full', field, value)"
|
||||
@update:immatriculation="(v) => form.immatriculation.value = v"
|
||||
@update:plate-free-format="(v) => form.plateFreeFormat.value = v"
|
||||
@request-auto="openAuto('full')"
|
||||
@request-manual="openManual('full')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Bas d'écran : « Enregistrer » (remplace « Valider », RG-5.08) +
|
||||
« Imprimer » (absent à l'ajout, RG-5.08). -->
|
||||
<!-- Bas d'écran : « Imprimer » (ouvre le PDF back) + action principale
|
||||
(« Valider » si brouillon, « Enregistrer » si déjà validé). -->
|
||||
<div class="mt-12 flex justify-center gap-6">
|
||||
<MalioButton
|
||||
variant="secondary"
|
||||
@@ -104,16 +123,14 @@
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('logistique.weighingTickets.form.save')"
|
||||
:label="primaryLabel"
|
||||
:disabled="saving"
|
||||
@click="submitSave"
|
||||
@click="submitPrimary"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- ── Modal « Confirmation pesée bascule » (RG-5.06) ──────────────────-->
|
||||
<!-- La question est portée par le titre ; pas de texte de corps. Bouton
|
||||
« Valider » seul, centré (l'annulation se fait via la croix). -->
|
||||
<MalioModal v-model="autoModal.open" modal-class="max-w-md" footer-class="justify-center pb-6">
|
||||
<template #header>
|
||||
<h2 class="text-[24px] font-bold">{{ t('logistique.weighingTickets.form.weighbridge.confirmTitle') }}</h2>
|
||||
@@ -130,9 +147,6 @@
|
||||
</MalioModal>
|
||||
|
||||
<!-- ── Modal « Pesée manuelle » ────────────────────────────────────────-->
|
||||
<!-- Marges : titre UPPERCASE à 24px du haut (pt-6), 28px horizontaux (mx-7 header
|
||||
/ px-7 body+footer), bordure à 12px sous le titre (pb-3) et insérée (mx-7,
|
||||
ne touche pas les bords), formulaire à 36px sous la bordure (pt-9). -->
|
||||
<MalioModal
|
||||
v-model="manualModal.open"
|
||||
modal-class="max-w-md"
|
||||
@@ -144,7 +158,6 @@
|
||||
<h2 class="text-[24px] font-bold uppercase">{{ t('logistique.weighingTickets.form.manual.title') }}</h2>
|
||||
</template>
|
||||
<div class="flex flex-col gap-2">
|
||||
<!-- Poids : champ texte verrouillé sur les chiffres (comme le formulaire). -->
|
||||
<MalioInputText
|
||||
v-model="manualModal.weight"
|
||||
:mask="NUMERIC_MASK"
|
||||
@@ -177,7 +190,7 @@ import { useWeighingTicketForm, type WeighingBlockState } from '~/modules/logist
|
||||
import { useWeighbridge } from '~/modules/logistique/composables/useWeighbridge'
|
||||
import { useWeighingTicket } from '~/modules/logistique/composables/useWeighingTicket'
|
||||
import { useWeighingTicketReferentials, type RefOption } from '~/modules/logistique/composables/useWeighingTicketReferentials'
|
||||
import { NUMERIC_MASK } from '~/modules/logistique/utils/weighingMasks'
|
||||
import { NUMERIC_MASK, PLATE_MASK, FREE_PLATE_MASK } from '~/modules/logistique/utils/weighingMasks'
|
||||
|
||||
const { t } = useI18n()
|
||||
const api = useApi()
|
||||
@@ -196,30 +209,13 @@ const form = useWeighingTicketForm()
|
||||
const weighbridge = useWeighbridge()
|
||||
const referentials = useWeighingTicketReferentials()
|
||||
const { fetchTicket } = useWeighingTicket()
|
||||
const { errors, setError, clearErrors, handleApiError } = useFormErrors()
|
||||
|
||||
/**
|
||||
* Marque Poids/DSD manquants d'un bloc (RG-5.07). `emptyWeight` est validé côté
|
||||
* back (NotBlank → renvoyé avec les autres violations) ; `fullWeight` n'a pas
|
||||
* d'équivalent back (workflow 2 temps) et reste donc front-only. Le DSD est
|
||||
* alloué serveur → simple repère front en miroir du poids. Retourne false si une
|
||||
* pesée manque.
|
||||
*/
|
||||
function validateWeighing(which: 'empty' | 'full'): boolean {
|
||||
const missing = form.missingWeighingFields(which)
|
||||
for (const path of missing) {
|
||||
setError(path, path.endsWith('Weight')
|
||||
? t('logistique.weighingTickets.form.weightRequired')
|
||||
: t('logistique.weighingTickets.form.dsdRequired'))
|
||||
}
|
||||
return missing.length === 0
|
||||
}
|
||||
const { errors, clearErrors, handleApiError } = useFormErrors()
|
||||
|
||||
const loading = ref(true)
|
||||
const error = ref(false)
|
||||
const saving = ref(false)
|
||||
|
||||
// Numéro immuable (RG-5.09), rappelé dans le titre de l'écran.
|
||||
// Numéro immuable (RG-5.09), rappelé dans le titre — vide tant que brouillon.
|
||||
const ticketNumber = ref<string>('')
|
||||
|
||||
const headerTitle = computed(() =>
|
||||
@@ -228,6 +224,15 @@ const headerTitle = computed(() =>
|
||||
: t('logistique.weighingTickets.edit.titleFallback'),
|
||||
)
|
||||
|
||||
// Libellé de l'action principale : « Valider » pour un brouillon (finalisation),
|
||||
// « Enregistrer » pour un ticket déjà validé (mise à jour, ERP-193).
|
||||
const isValidated = computed(() => form.status.value === 'VALIDATED')
|
||||
const primaryLabel = computed(() =>
|
||||
isValidated.value
|
||||
? t('logistique.weighingTickets.form.save')
|
||||
: t('logistique.weighingTickets.form.validate'),
|
||||
)
|
||||
|
||||
useHead({ title: t('logistique.weighingTickets.edit.titleFallback') })
|
||||
|
||||
/** Retour vers la liste (flèche d'en-tête). */
|
||||
@@ -235,7 +240,7 @@ function goBack(): void {
|
||||
router.push('/weighing-tickets')
|
||||
}
|
||||
|
||||
// ── Contrepartie (RG-5.03) ───────────────────────────────────────────────────
|
||||
// ── Contrepartie (RG-5.03) — ordre maquette : Fournisseur / Client / Autre. ───
|
||||
const counterpartyOptions = computed<RefOption[]>(() => [
|
||||
{ value: 'FOURNISSEUR', label: t('logistique.weighingTickets.form.counterparty.supplier') },
|
||||
{ value: 'CLIENT', label: t('logistique.weighingTickets.form.counterparty.client') },
|
||||
@@ -252,11 +257,7 @@ const emptyBlockErrors = computed<Record<string, string>>(() => ({
|
||||
date: errors.emptyDate,
|
||||
weight: errors.emptyWeight,
|
||||
dsd: errors.emptyDsd,
|
||||
immatriculation: errors.immatriculation,
|
||||
}))
|
||||
// Immatriculation volontairement ABSENTE ici : partagée entre les 2 blocs
|
||||
// (RG-5.01) mais affichée/validée sur le bloc « Poids à vide » uniquement — pas
|
||||
// de doublon d'erreur sur le bloc « Poids à plein ».
|
||||
const fullBlockErrors = computed<Record<string, string>>(() => ({
|
||||
date: errors.fullDate,
|
||||
weight: errors.fullWeight,
|
||||
@@ -282,6 +283,7 @@ function openAuto(target: 'empty' | 'full'): void {
|
||||
autoModal.open = true
|
||||
}
|
||||
|
||||
/** Déclenche la pesée bascule puis enregistre le brouillon (ERP-193). */
|
||||
async function confirmAuto(): Promise<void> {
|
||||
if (autoModal.loading) return
|
||||
autoModal.loading = true
|
||||
@@ -290,6 +292,7 @@ async function confirmAuto(): Promise<void> {
|
||||
const reading = await weighbridge.triggerAuto()
|
||||
form.applyReading(form[autoModal.target], reading)
|
||||
autoModal.open = false
|
||||
await saveDraft()
|
||||
}
|
||||
catch (e) {
|
||||
autoModal.error = weighbridge.extractWeighbridgeError(e)
|
||||
@@ -317,6 +320,7 @@ function openManual(target: 'empty' | 'full'): void {
|
||||
manualModal.open = true
|
||||
}
|
||||
|
||||
/** Valide la saisie manuelle, remplit le bloc puis enregistre le brouillon. */
|
||||
async function confirmManual(): Promise<void> {
|
||||
if (manualModal.loading) return
|
||||
manualModal.errors = {}
|
||||
@@ -336,6 +340,7 @@ async function confirmManual(): Promise<void> {
|
||||
const reading = await weighbridge.triggerManual(weight as number, manualNumber)
|
||||
form.applyReading(form[manualModal.target], reading)
|
||||
manualModal.open = false
|
||||
await saveDraft()
|
||||
}
|
||||
catch (e) {
|
||||
manualModal.errors = { weight: weighbridge.extractWeighbridgeError(e) }
|
||||
@@ -345,18 +350,34 @@ async function confirmManual(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Soumission / impression ───────────────────────────────────────────────────
|
||||
/** « Enregistrer » : PATCH /weighing_tickets/{id} (recalcul net serveur, RG-5.05). */
|
||||
async function submitSave(): Promise<void> {
|
||||
if (saving.value) return
|
||||
// ── Persistance / impression ──────────────────────────────────────────────────
|
||||
/** Enregistre l'état courant en BROUILLON (PATCH). False sur erreur (422 inline). */
|
||||
async function saveDraft(): Promise<boolean> {
|
||||
clearErrors()
|
||||
// Vide : marqué seulement (le back garde emptyWeight et renvoie tout d'un coup).
|
||||
// Plein : bloquant côté front (pas de règle back, workflow 2 temps).
|
||||
validateWeighing('empty')
|
||||
if (!validateWeighing('full')) return
|
||||
try {
|
||||
await api.patch(`/weighing_tickets/${ticketId}`, form.buildDraftPayload(), { toast: false })
|
||||
return true
|
||||
}
|
||||
catch (e) {
|
||||
handleApiError(e, { fallbackMessage: t('logistique.weighingTickets.toast.error') })
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action principale : persiste l'état courant puis finalise/re-valide via
|
||||
* PATCH /validate (back autoritaire : 3 champs du haut + 2 pesées). Ouvre le bon de
|
||||
* pesée PDF (RG-5.08) — aussi bien à la validation d'un brouillon qu'à
|
||||
* l'enregistrement d'un ticket déjà validé. Retour à la liste au succès.
|
||||
*/
|
||||
async function submitPrimary(): Promise<void> {
|
||||
if (saving.value) return
|
||||
saving.value = true
|
||||
try {
|
||||
await api.patch(`/weighing_tickets/${ticketId}`, form.buildUpdatePayload(), { toast: false })
|
||||
if (!(await saveDraft())) return
|
||||
|
||||
await api.patch(`/weighing_tickets/${ticketId}/validate`, form.buildValidatePayload(), { toast: false })
|
||||
window.open(`/api/weighing_tickets/${ticketId}/print.pdf`, '_blank')
|
||||
router.push('/weighing-tickets')
|
||||
}
|
||||
catch (e) {
|
||||
@@ -376,11 +397,10 @@ function printTicket(): void {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
// Référentiels (selects contrepartie) en parallèle, non bloquants.
|
||||
referentials.load().catch(() => {})
|
||||
try {
|
||||
const detail = await fetchTicket(ticketId)
|
||||
ticketNumber.value = detail.number
|
||||
ticketNumber.value = detail.number ?? ''
|
||||
form.hydrate(detail)
|
||||
}
|
||||
catch {
|
||||
|
||||
@@ -84,12 +84,16 @@ const {
|
||||
// restent vides. Date et poids sont formates ici (cf. helpers ci-dessous).
|
||||
const rows = computed(() => tickets.value.map(ticket => ({
|
||||
id: ticket.id,
|
||||
number: ticket.number,
|
||||
// Numéro vide tant que brouillon (attribué à la validation, ERP-193).
|
||||
number: ticket.number ?? '',
|
||||
client: ticket.client?.companyName ?? '',
|
||||
supplier: ticket.supplier?.companyName ?? '',
|
||||
otherLabel: ticket.otherLabel ?? '',
|
||||
displayDate: formatDateFr(ticket.displayDate),
|
||||
netWeight: formatWeightKg(ticket.netWeight),
|
||||
status: t(ticket.status === 'VALIDATED'
|
||||
? 'logistique.weighingTickets.status.validated'
|
||||
: 'logistique.weighingTickets.status.draft'),
|
||||
})))
|
||||
|
||||
const columns = [
|
||||
@@ -99,6 +103,7 @@ const columns = [
|
||||
{ key: 'otherLabel', label: t('logistique.weighingTickets.column.other') },
|
||||
{ key: 'displayDate', label: t('logistique.weighingTickets.column.date') },
|
||||
{ key: 'netWeight', label: t('logistique.weighingTickets.column.weight') },
|
||||
{ key: 'status', label: t('logistique.weighingTickets.column.status') },
|
||||
]
|
||||
|
||||
/** Clic sur une ligne → ecran Modification (pas de consultation separee, spec § Navigation). */
|
||||
|
||||
@@ -13,30 +13,19 @@
|
||||
<h1 class="text-[30px] font-semibold text-m-primary">{{ t('logistique.weighingTickets.form.addTitle') }}</h1>
|
||||
</div>
|
||||
|
||||
<div class="mt-[48px] flex flex-col gap-8">
|
||||
<!-- ── Bloc « Poids à vide » (porte la contrepartie, RG-5.03) ──────── -->
|
||||
<WeighingBlock
|
||||
block-id="empty"
|
||||
:title="t('logistique.weighingTickets.form.emptyBlock')"
|
||||
:block="form.empty"
|
||||
:immatriculation="form.immatriculation.value"
|
||||
:plate-free-format="form.plateFreeFormat.value"
|
||||
:errors="emptyBlockErrors"
|
||||
:disabled="emptyLocked"
|
||||
@update:block="(field, value) => updateBlock('empty', field, value)"
|
||||
@update:immatriculation="(v) => form.immatriculation.value = v"
|
||||
@update:plate-free-format="(v) => form.plateFreeFormat.value = v"
|
||||
@request-auto="openAuto('empty')"
|
||||
@request-manual="openManual('empty')"
|
||||
>
|
||||
<!-- Contrepartie : sélecteur + champ conditionnel (RG-5.03). -->
|
||||
<template #counterparty>
|
||||
<!-- Form à plat, pleine largeur (sans box-shadow) : un filet noir 1px
|
||||
sépare chacun des 3 blocs (divide-y). -->
|
||||
<div class="mt-[48px] flex flex-col divide-y divide-black">
|
||||
<!-- ── 4 champs du haut : contrepartie (type + champ conditionnel),
|
||||
immatriculation, « Tout format » (ERP-193, hors blocs de pesée).
|
||||
1er bloc : pas de padding-top (marge titre→form = mt-[48px] standard). ── -->
|
||||
<div class="pb-[20px]">
|
||||
<div class="grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<MalioSelect
|
||||
:model-value="form.counterpartyType.value"
|
||||
:options="counterpartyOptions"
|
||||
:label="t('logistique.weighingTickets.form.counterparty.type')"
|
||||
:required="true"
|
||||
:disabled="emptyLocked"
|
||||
empty-option-label=""
|
||||
:error="errors.counterpartyType"
|
||||
@update:model-value="onCounterpartyTypeChange"
|
||||
@@ -47,7 +36,6 @@
|
||||
:options="referentials.suppliers.value"
|
||||
:label="t('logistique.weighingTickets.form.counterparty.supplier')"
|
||||
:required="true"
|
||||
:disabled="emptyLocked"
|
||||
empty-option-label=""
|
||||
:error="errors.supplier"
|
||||
@update:model-value="(v: string | number | null) => form.supplierIri.value = v === null ? null : String(v)"
|
||||
@@ -58,7 +46,6 @@
|
||||
:options="referentials.clients.value"
|
||||
:label="t('logistique.weighingTickets.form.counterparty.client')"
|
||||
:required="true"
|
||||
:disabled="emptyLocked"
|
||||
empty-option-label=""
|
||||
:error="errors.client"
|
||||
@update:model-value="(v: string | number | null) => form.clientIri.value = v === null ? null : String(v)"
|
||||
@@ -68,60 +55,76 @@
|
||||
:model-value="form.otherLabel.value"
|
||||
:label="t('logistique.weighingTickets.form.counterparty.other')"
|
||||
:required="true"
|
||||
:disabled="emptyLocked"
|
||||
:error="errors.otherLabel"
|
||||
@update:model-value="(v: string | null) => form.otherLabel.value = v"
|
||||
/>
|
||||
</template>
|
||||
</WeighingBlock>
|
||||
|
||||
<!-- « Enregistrer » du bloc vide : POST initial du ticket (disparaît une
|
||||
fois le ticket créé — RG-5.08). -->
|
||||
<div v-if="form.ticketId.value === null" class="flex justify-center">
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('logistique.weighingTickets.form.save')"
|
||||
:disabled="creating"
|
||||
@click="submitCreate"
|
||||
/>
|
||||
<!-- Pas de cellule vide quand aucun type n'est choisi : immat et
|
||||
« Tout format » se collent au type, et le champ conditionnel
|
||||
les décale une fois un type sélectionné. -->
|
||||
<!-- Immatriculation : masque XX-000-XX (plaque FR SIV) ; en « Tout
|
||||
format », masque élargi. Partagée par les 2 pesées (RG-5.01). -->
|
||||
<MalioInputText
|
||||
:model-value="form.immatriculation.value"
|
||||
:mask="form.plateFreeFormat.value ? FREE_PLATE_MASK : PLATE_MASK"
|
||||
:label="t('logistique.weighingTickets.form.immatriculation')"
|
||||
:required="true"
|
||||
:error="errors.immatriculation"
|
||||
@update:model-value="(v: string | null) => form.immatriculation.value = v"
|
||||
/>
|
||||
<MalioCheckbox
|
||||
id="plate-free-format"
|
||||
:model-value="form.plateFreeFormat.value"
|
||||
:label="t('logistique.weighingTickets.form.plateFreeFormat')"
|
||||
group-class="self-center"
|
||||
@update:model-value="(v: boolean) => form.plateFreeFormat.value = v"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ── Bloc « Poids à plein » ───────────────────────────────────────-->
|
||||
<!-- ── Bloc « Poids à vide » ──────────────────────────────────────── -->
|
||||
<WeighingBlock
|
||||
class="py-[20px]"
|
||||
block-id="empty"
|
||||
:title="t('logistique.weighingTickets.form.emptyBlock')"
|
||||
:block="form.empty"
|
||||
:errors="emptyBlockErrors"
|
||||
@update:block="(field, value) => updateBlock('empty', field, value)"
|
||||
@request-auto="openAuto('empty')"
|
||||
@request-manual="openManual('empty')"
|
||||
/>
|
||||
|
||||
<!-- ── Bloc « Poids à plein » (dernier bloc : pas de padding-bottom,
|
||||
pour ne pas écarter le bouton « Valider »). ───────────────────── -->
|
||||
<WeighingBlock
|
||||
class="pt-[20px]"
|
||||
block-id="full"
|
||||
:title="t('logistique.weighingTickets.form.fullBlock')"
|
||||
:block="form.full"
|
||||
:immatriculation="form.immatriculation.value"
|
||||
:plate-free-format="form.plateFreeFormat.value"
|
||||
:errors="fullBlockErrors"
|
||||
@update:block="(field, value) => updateBlock('full', field, value)"
|
||||
@update:immatriculation="(v) => form.immatriculation.value = v"
|
||||
@update:plate-free-format="(v) => form.plateFreeFormat.value = v"
|
||||
@request-auto="openAuto('full')"
|
||||
@request-manual="openManual('full')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- « Valider » (bas d'écran) : PATCH de la pesée à plein puis ouverture du
|
||||
bon de pesée PDF (RG-5.08). Indisponible tant que le ticket n'est pas créé. -->
|
||||
<!-- « Valider » : persiste l'état courant (brouillon) puis finalise (3 champs
|
||||
du haut + 2 pesées, validation back autoritaire) et ouvre le bon de
|
||||
pesée PDF (RG-5.08, ERP-193). Toujours actif : les 422 s'affichent inline. -->
|
||||
<div class="mt-12 flex justify-center">
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('logistique.weighingTickets.form.validate')"
|
||||
:disabled="validating || form.ticketId.value === null"
|
||||
:disabled="validating"
|
||||
@click="submitValidate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- ── Modal « Confirmation pesée bascule » (RG-5.06) ──────────────────-->
|
||||
<!-- La question est portée par le titre ; pas de texte de corps. Bouton
|
||||
« Valider » seul, centré (l'annulation se fait via la croix). -->
|
||||
<MalioModal v-model="autoModal.open" modal-class="max-w-md" footer-class="justify-center pb-6">
|
||||
<template #header>
|
||||
<h2 class="text-[24px] font-bold">{{ t('logistique.weighingTickets.form.weighbridge.confirmTitle') }}</h2>
|
||||
</template>
|
||||
<!-- Erreur de pont indisponible affichée INLINE dans la modal + invite
|
||||
à la pesée manuelle (RG-5.06). -->
|
||||
<p v-if="autoModal.error" class="text-m-danger">{{ autoModal.error }}</p>
|
||||
<template #footer>
|
||||
<MalioButton
|
||||
@@ -134,9 +137,6 @@
|
||||
</MalioModal>
|
||||
|
||||
<!-- ── Modal « Pesée manuelle » ────────────────────────────────────────-->
|
||||
<!-- Marges : titre UPPERCASE à 24px du haut (pt-6), 28px horizontaux (mx-7 header
|
||||
/ px-7 body+footer), bordure à 12px sous le titre (pb-3) et insérée (mx-7,
|
||||
ne touche pas les bords), formulaire à 36px sous la bordure (pt-9). -->
|
||||
<MalioModal
|
||||
v-model="manualModal.open"
|
||||
modal-class="max-w-md"
|
||||
@@ -148,7 +148,6 @@
|
||||
<h2 class="text-[24px] font-bold uppercase">{{ t('logistique.weighingTickets.form.manual.title') }}</h2>
|
||||
</template>
|
||||
<div class="flex flex-col gap-2">
|
||||
<!-- Poids : champ texte verrouillé sur les chiffres (comme le formulaire). -->
|
||||
<MalioInputText
|
||||
v-model="manualModal.weight"
|
||||
:mask="NUMERIC_MASK"
|
||||
@@ -180,7 +179,7 @@ import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useWeighingTicketForm, type WeighingBlockState } from '~/modules/logistique/composables/useWeighingTicketForm'
|
||||
import { useWeighbridge } from '~/modules/logistique/composables/useWeighbridge'
|
||||
import { useWeighingTicketReferentials, type RefOption } from '~/modules/logistique/composables/useWeighingTicketReferentials'
|
||||
import { NUMERIC_MASK } from '~/modules/logistique/utils/weighingMasks'
|
||||
import { NUMERIC_MASK, PLATE_MASK, FREE_PLATE_MASK } from '~/modules/logistique/utils/weighingMasks'
|
||||
|
||||
const { t } = useI18n()
|
||||
const api = useApi()
|
||||
@@ -197,28 +196,8 @@ if (!can('logistique.weighing_tickets.manage')) {
|
||||
const form = useWeighingTicketForm()
|
||||
const weighbridge = useWeighbridge()
|
||||
const referentials = useWeighingTicketReferentials()
|
||||
const { errors, setError, clearErrors, handleApiError } = useFormErrors()
|
||||
const { errors, clearErrors, handleApiError } = useFormErrors()
|
||||
|
||||
/**
|
||||
* Validation front-only de la pesée d'un bloc (Poids + DSD obligatoires, RG-5.07).
|
||||
* Le back rend ces colonnes nullable (workflow 2 temps), l'obligation est donc
|
||||
* portée côté front (ERP-101). Pose l'erreur inline sous chaque champ manquant et
|
||||
* retourne false si une pesée manque.
|
||||
*/
|
||||
function validateWeighing(which: 'empty' | 'full'): boolean {
|
||||
const missing = form.missingWeighingFields(which)
|
||||
for (const path of missing) {
|
||||
setError(path, path.endsWith('Weight')
|
||||
? t('logistique.weighingTickets.form.weightRequired')
|
||||
: t('logistique.weighingTickets.form.dsdRequired'))
|
||||
}
|
||||
return missing.length === 0
|
||||
}
|
||||
|
||||
// Le bloc vide se verrouille une fois le ticket créé (numéro/site attribués).
|
||||
const emptyLocked = computed(() => form.ticketId.value !== null)
|
||||
|
||||
const creating = ref(false)
|
||||
const validating = ref(false)
|
||||
|
||||
/** Retour vers la liste (flèche d'en-tête). */
|
||||
@@ -226,8 +205,7 @@ function goBack(): void {
|
||||
router.push('/weighing-tickets')
|
||||
}
|
||||
|
||||
// ── Contrepartie (RG-5.03) ───────────────────────────────────────────────────
|
||||
// Ordre maquette : Fournisseur / Client / Autre.
|
||||
// ── Contrepartie (RG-5.03) — ordre maquette : Fournisseur / Client / Autre. ───
|
||||
const counterpartyOptions = computed<RefOption[]>(() => [
|
||||
{ value: 'FOURNISSEUR', label: t('logistique.weighingTickets.form.counterparty.supplier') },
|
||||
{ value: 'CLIENT', label: t('logistique.weighingTickets.form.counterparty.client') },
|
||||
@@ -244,12 +222,7 @@ const emptyBlockErrors = computed<Record<string, string>>(() => ({
|
||||
date: errors.emptyDate,
|
||||
weight: errors.emptyWeight,
|
||||
dsd: errors.emptyDsd,
|
||||
immatriculation: errors.immatriculation,
|
||||
}))
|
||||
// Immatriculation volontairement ABSENTE ici : elle est partagée entre les 2 blocs
|
||||
// (RG-5.01) mais saisie/validée sur le bloc « Poids à vide ». On n'affiche donc
|
||||
// son erreur que sur le 1er bloc, pas en double sur le bloc « Poids à plein »
|
||||
// (le formulaire se valide en 2 temps).
|
||||
const fullBlockErrors = computed<Record<string, string>>(() => ({
|
||||
date: errors.fullDate,
|
||||
weight: errors.fullWeight,
|
||||
@@ -258,7 +231,6 @@ const fullBlockErrors = computed<Record<string, string>>(() => ({
|
||||
|
||||
/** Mute un champ d'un bloc de pesée (état centralisé dans le form). */
|
||||
function updateBlock(target: 'empty' | 'full', field: keyof WeighingBlockState, value: unknown): void {
|
||||
// Affectation typée via l'index du bloc reactif (date est le seul champ éditable).
|
||||
(form[target] as Record<string, unknown>)[field as string] = value
|
||||
}
|
||||
|
||||
@@ -276,7 +248,7 @@ function openAuto(target: 'empty' | 'full'): void {
|
||||
autoModal.open = true
|
||||
}
|
||||
|
||||
/** Déclenche la pesée bascule ; erreur (RG-5.06) affichée dans la modal. */
|
||||
/** Déclenche la pesée bascule puis enregistre le brouillon (ERP-193). */
|
||||
async function confirmAuto(): Promise<void> {
|
||||
if (autoModal.loading) return
|
||||
autoModal.loading = true
|
||||
@@ -285,9 +257,9 @@ async function confirmAuto(): Promise<void> {
|
||||
const reading = await weighbridge.triggerAuto()
|
||||
form.applyReading(form[autoModal.target], reading)
|
||||
autoModal.open = false
|
||||
await saveDraft()
|
||||
}
|
||||
catch (error) {
|
||||
// Pont indisponible : message inline + invite à la pesée manuelle.
|
||||
autoModal.error = weighbridge.extractWeighbridgeError(error)
|
||||
}
|
||||
finally {
|
||||
@@ -313,7 +285,7 @@ function openManual(target: 'empty' | 'full'): void {
|
||||
manualModal.open = true
|
||||
}
|
||||
|
||||
/** Valide la saisie manuelle puis remplit le bloc (DSD calculé serveur, RG-5.04). */
|
||||
/** Valide la saisie manuelle, remplit le bloc puis enregistre le brouillon. */
|
||||
async function confirmManual(): Promise<void> {
|
||||
if (manualModal.loading) return
|
||||
manualModal.errors = {}
|
||||
@@ -333,6 +305,7 @@ async function confirmManual(): Promise<void> {
|
||||
const reading = await weighbridge.triggerManual(weight as number, manualNumber)
|
||||
form.applyReading(form[manualModal.target], reading)
|
||||
manualModal.open = false
|
||||
await saveDraft()
|
||||
}
|
||||
catch (error) {
|
||||
manualModal.errors = { weight: weighbridge.extractWeighbridgeError(error) }
|
||||
@@ -342,45 +315,47 @@ async function confirmManual(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Soumissions ──────────────────────────────────────────────────────────────
|
||||
// ── Persistance ──────────────────────────────────────────────────────────────
|
||||
interface TicketResponse { id: number }
|
||||
|
||||
/** « Enregistrer » du bloc vide : POST /weighing_tickets (création + pesée à vide). */
|
||||
async function submitCreate(): Promise<void> {
|
||||
if (creating.value) return
|
||||
/**
|
||||
* Enregistre l'état courant en BROUILLON (ERP-193) : POST si le ticket n'existe pas
|
||||
* encore (1ʳᵉ pesée enregistrée), PATCH ensuite. Renvoie false sur erreur (422
|
||||
* mappée inline, ex. format d'immatriculation).
|
||||
*/
|
||||
async function saveDraft(): Promise<boolean> {
|
||||
clearErrors()
|
||||
// Marque Poids/DSD manquants pour un retour immédiat, mais on POSTe quand même :
|
||||
// le back renvoie TOUTES les violations d'un coup (counterparty / immat / poids,
|
||||
// NotBlank sur emptyWeight), comme les autres modules. Le DSD est alloué serveur
|
||||
// (pas de règle back) → simple repère front en miroir du poids.
|
||||
validateWeighing('empty')
|
||||
creating.value = true
|
||||
try {
|
||||
const created = await api.post<TicketResponse>('/weighing_tickets', form.buildCreatePayload(), {
|
||||
headers: { Accept: 'application/ld+json' },
|
||||
toast: false,
|
||||
})
|
||||
form.ticketId.value = created.id
|
||||
if (form.ticketId.value === null) {
|
||||
const created = await api.post<TicketResponse>('/weighing_tickets', form.buildDraftPayload(), {
|
||||
headers: { Accept: 'application/ld+json' },
|
||||
toast: false,
|
||||
})
|
||||
form.ticketId.value = created.id
|
||||
}
|
||||
else {
|
||||
await api.patch(`/weighing_tickets/${form.ticketId.value}`, form.buildDraftPayload(), { toast: false })
|
||||
}
|
||||
return true
|
||||
}
|
||||
catch (error) {
|
||||
handleApiError(error, { fallbackMessage: t('logistique.weighingTickets.toast.error') })
|
||||
}
|
||||
finally {
|
||||
creating.value = false
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** « Valider » : PATCH de la pesée à plein puis ouverture du bon de pesée PDF (RG-5.08). */
|
||||
/**
|
||||
* « Valider » : persiste l'état courant puis finalise via PATCH /validate. La
|
||||
* validation stricte (3 champs du haut + 2 pesées) est portée par le back ; les 422
|
||||
* remontent inline. Succès → ouverture du bon de pesée PDF + retour à la liste.
|
||||
*/
|
||||
async function submitValidate(): Promise<void> {
|
||||
if (validating.value || form.ticketId.value === null) return
|
||||
clearErrors()
|
||||
// Pesée à plein obligatoire (front-only) avant finalisation/impression.
|
||||
if (!validateWeighing('full')) return
|
||||
if (validating.value) return
|
||||
validating.value = true
|
||||
try {
|
||||
await api.patch(`/weighing_tickets/${form.ticketId.value}`, form.buildFullPayload(), { toast: false })
|
||||
// Bon de pesée = PDF généré côté back (Twig, ERP-192) — on l'ouvre, on ne
|
||||
// dessine aucun gabarit côté front (RG-5.08).
|
||||
if (!(await saveDraft())) return
|
||||
|
||||
await api.patch(`/weighing_tickets/${form.ticketId.value}/validate`, form.buildValidatePayload(), { toast: false })
|
||||
window.open(`/api/weighing_tickets/${form.ticketId.value}/print.pdf`, '_blank')
|
||||
router.push('/weighing-tickets')
|
||||
}
|
||||
@@ -393,7 +368,6 @@ async function submitValidate(): Promise<void> {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// Échec du chargement des référentiels non bloquant : les selects restent vides.
|
||||
referentials.load().catch(() => {})
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user