feat(front) : écran modification d'un ticket de pesée + bouton imprimer (ERP-190)
This commit is contained in:
@@ -102,4 +102,65 @@ describe('useWeighingTicketForm', () => {
|
||||
expect(full.fullDsd).toBe(2)
|
||||
expect(full.fullMode).toBe('AUTO')
|
||||
})
|
||||
|
||||
// ── Pré-remplissage (écran Modification, ERP-190) ─────────────────────────
|
||||
it('hydrate pré-remplit l\'état depuis le détail (dates ISO ramenées à YYYY-MM-DD)', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
form.hydrate({
|
||||
id: 9,
|
||||
counterpartyType: 'CLIENT',
|
||||
client: { '@id': '/api/clients/629' },
|
||||
immatriculation: 'AB-123-CD',
|
||||
plateFreeFormat: false,
|
||||
emptyDate: '2026-06-17T09:00:00+02:00',
|
||||
emptyWeight: 7150,
|
||||
emptyDsd: 1,
|
||||
emptyMode: 'AUTO',
|
||||
fullDate: '2026-06-17T09:12:00+02:00',
|
||||
fullWeight: 14300,
|
||||
fullDsd: 2,
|
||||
fullMode: 'AUTO',
|
||||
})
|
||||
|
||||
expect(form.ticketId.value).toBe(9)
|
||||
expect(form.counterpartyType.value).toBe('CLIENT')
|
||||
expect(form.counterpartyField.value).toBe('client')
|
||||
expect(form.clientIri.value).toBe('/api/clients/629')
|
||||
expect(form.immatriculation.value).toBe('AB-123-CD')
|
||||
// Date datetime back -> date seule pour MalioDate.
|
||||
expect(form.empty.date).toBe('2026-06-17')
|
||||
expect(form.full.date).toBe('2026-06-17')
|
||||
expect(form.empty.weight).toBe(7150)
|
||||
expect(form.full.weight).toBe(14300)
|
||||
})
|
||||
|
||||
it('hydrate gère les champs null omis (skip_null_values) avec des défauts', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
form.hydrate({ id: 5, counterpartyType: 'AUTRE', otherLabel: 'Reprise' })
|
||||
expect(form.otherLabel.value).toBe('Reprise')
|
||||
expect(form.supplierIri.value).toBeNull()
|
||||
expect(form.plateFreeFormat.value).toBe(false)
|
||||
// Pas de date back -> repli sur le jour (stub 2026-06-22).
|
||||
expect(form.empty.date).toBe('2026-06-22')
|
||||
expect(form.empty.weight).toBeNull()
|
||||
})
|
||||
|
||||
it('buildUpdatePayload fusionne contrepartie + véhicule + les 2 pesées', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
form.hydrate({
|
||||
id: 9,
|
||||
counterpartyType: 'CLIENT',
|
||||
client: { '@id': '/api/clients/629' },
|
||||
immatriculation: 'AB-123-CD',
|
||||
emptyWeight: 7150, emptyDsd: 1, emptyMode: 'AUTO',
|
||||
fullWeight: 14300, fullDsd: 2, fullMode: 'AUTO',
|
||||
})
|
||||
|
||||
const payload = form.buildUpdatePayload()
|
||||
expect(payload.counterpartyType).toBe('CLIENT')
|
||||
expect(payload.client).toBe('/api/clients/629')
|
||||
expect(payload.emptyWeight).toBe(7150)
|
||||
expect(payload.fullWeight).toBe(14300)
|
||||
expect(payload.immatriculation).toBe('AB-123-CD')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import type { WeighbridgeMode } from '~/modules/logistique/composables/useWeighbridge'
|
||||
import type { CounterpartyType } from '~/modules/logistique/composables/useWeighingTicketForm'
|
||||
|
||||
/**
|
||||
* Détail d'un ticket de pesée (`GET /api/weighing_tickets/{id}`, spec-back
|
||||
* § 4.0.bis). Champs null OMIS du JSON (`skip_null_values`) → tous optionnels,
|
||||
* lus avec un défaut côté hydratation du formulaire.
|
||||
*/
|
||||
export interface WeighingTicketDetail {
|
||||
id: number
|
||||
/** Numéro `{siteCode}-TP-{NNNN}` — immuable (RG-5.09). */
|
||||
number: string
|
||||
/** Site rattaché (embarqué) — immuable (RG-5.09). */
|
||||
site?: { id: number, name: string, code: string } | null
|
||||
counterpartyType: CounterpartyType
|
||||
client?: { '@id': string, companyName: string } | null
|
||||
supplier?: { '@id': string, companyName: string } | null
|
||||
otherLabel?: string | null
|
||||
immatriculation?: string | null
|
||||
plateFreeFormat?: boolean
|
||||
// Pesée à vide
|
||||
emptyDate?: string | null
|
||||
emptyWeight?: number | null
|
||||
emptyDsd?: number | null
|
||||
emptyMode?: WeighbridgeMode | null
|
||||
emptyManualNumber?: string | null
|
||||
// Pesée à plein
|
||||
fullDate?: string | null
|
||||
fullWeight?: number | null
|
||||
fullDsd?: number | null
|
||||
fullMode?: WeighbridgeMode | null
|
||||
fullManualNumber?: string | null
|
||||
netWeight?: number | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge le détail d'un ticket de pesée pour l'écran de modification (M5,
|
||||
* ERP-190). `Accept: application/ld+json` impose l'enveloppe Hydra (relations
|
||||
* embarquées : client/supplier/site). Appel via `useApi()` (jamais `$fetch`).
|
||||
*/
|
||||
export function useWeighingTicket() {
|
||||
const api = useApi()
|
||||
|
||||
async function fetchTicket(id: number | string): Promise<WeighingTicketDetail> {
|
||||
return await api.get<WeighingTicketDetail>(
|
||||
`/weighing_tickets/${id}`,
|
||||
{},
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
}
|
||||
|
||||
return { fetchTicket }
|
||||
}
|
||||
@@ -39,6 +39,32 @@ export interface WeighingBlockState {
|
||||
manualNumber: string | null
|
||||
}
|
||||
|
||||
/** Forme minimale d'un détail de ticket consommée par `hydrate` (cf. useWeighingTicket). */
|
||||
export interface WeighingTicketHydration {
|
||||
id: number
|
||||
counterpartyType: CounterpartyType
|
||||
client?: { '@id': string } | null
|
||||
supplier?: { '@id': string } | null
|
||||
otherLabel?: string | null
|
||||
immatriculation?: string | null
|
||||
plateFreeFormat?: boolean
|
||||
emptyDate?: string | null
|
||||
emptyWeight?: number | null
|
||||
emptyDsd?: number | null
|
||||
emptyMode?: WeighbridgeMode | null
|
||||
emptyManualNumber?: string | null
|
||||
fullDate?: string | null
|
||||
fullWeight?: number | null
|
||||
fullDsd?: number | null
|
||||
fullMode?: WeighbridgeMode | null
|
||||
fullManualNumber?: string | null
|
||||
}
|
||||
|
||||
/** Extrait la partie date `YYYY-MM-DD` d'une chaîne ISO (datetime back) — null si absente. */
|
||||
function isoDateOnly(value: string | null | undefined): string | null {
|
||||
return value ? value.slice(0, 10) : null
|
||||
}
|
||||
|
||||
/** Crée l'état initial d'un bloc de pesée (date = aujourd'hui, RG-5.07). */
|
||||
function emptyBlock(today: string): WeighingBlockState {
|
||||
return {
|
||||
@@ -137,6 +163,44 @@ export function useWeighingTicketForm() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pré-remplit le formulaire à partir du détail d'un ticket existant (écran
|
||||
* Modification, ERP-190). Le numéro et le site sont immuables (RG-5.09) →
|
||||
* non repris dans l'état éditable (affichés en lecture seule par l'écran).
|
||||
* Les dates ISO du back (datetime) sont ramenées à `YYYY-MM-DD` pour MalioDate.
|
||||
*/
|
||||
function hydrate(detail: WeighingTicketHydration): void {
|
||||
ticketId.value = detail.id
|
||||
counterpartyType.value = detail.counterpartyType ?? null
|
||||
clientIri.value = detail.client?.['@id'] ?? null
|
||||
supplierIri.value = detail.supplier?.['@id'] ?? null
|
||||
otherLabel.value = detail.otherLabel ?? null
|
||||
immatriculation.value = detail.immatriculation ?? null
|
||||
plateFreeFormat.value = detail.plateFreeFormat ?? false
|
||||
|
||||
empty.date = isoDateOnly(detail.emptyDate) ?? today
|
||||
empty.weight = detail.emptyWeight ?? null
|
||||
empty.dsd = detail.emptyDsd ?? null
|
||||
empty.mode = detail.emptyMode ?? null
|
||||
empty.manualNumber = detail.emptyManualNumber ?? null
|
||||
|
||||
full.date = isoDateOnly(detail.fullDate) ?? today
|
||||
full.weight = detail.fullWeight ?? null
|
||||
full.dsd = detail.fullDsd ?? null
|
||||
full.mode = detail.fullMode ?? null
|
||||
full.manualNumber = detail.fullManualNumber ?? null
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
*/
|
||||
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
|
||||
@@ -172,7 +236,9 @@ export function useWeighingTicketForm() {
|
||||
applyReading,
|
||||
// workflow
|
||||
ticketId,
|
||||
hydrate,
|
||||
buildCreatePayload,
|
||||
buildFullPayload,
|
||||
buildUpdatePayload,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user