fix(logistique) : corrections review ticket de pesée (ERP-208)
- Édition : listes contrepartie filtrées sur le site DU TICKET (immuable), chargées après hydrate, sans purge de la contrepartie persistée (injection de l'option si absente) → corrige la perte silencieuse / race. - Entité : constantes COUNTERPARTY_* (Assert\Choice + validation + getCounterpartyName) ; libellé FR du type déplacé du Domain vers le template. - PDF : cartouche conditionné sur le type (nom à l'intérieur), layout Dompdf-safe (largeurs de cellules, cartouche en bloc, nom long renvoyé à la ligne).
This commit is contained in:
@@ -8,12 +8,13 @@ const mockFetchTicket = vi.hoisted(() => vi.fn())
|
||||
const mockPatch = vi.hoisted(() => vi.fn())
|
||||
const mockPush = vi.hoisted(() => vi.fn())
|
||||
const mockOpen = vi.hoisted(() => vi.fn())
|
||||
const mockRefLoad = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.mock('~/modules/logistique/composables/useWeighingTicket', () => ({
|
||||
useWeighingTicket: () => ({ fetchTicket: mockFetchTicket }),
|
||||
}))
|
||||
vi.mock('~/modules/logistique/composables/useWeighingTicketReferentials', () => ({
|
||||
useWeighingTicketReferentials: () => ({ clients: ref([]), suppliers: ref([]), load: vi.fn().mockResolvedValue(undefined) }),
|
||||
useWeighingTicketReferentials: () => ({ clients: ref([]), suppliers: ref([]), load: mockRefLoad }),
|
||||
}))
|
||||
vi.mock('~/modules/logistique/composables/useWeighbridge', () => ({
|
||||
useWeighbridge: () => ({ triggerAuto: vi.fn(), triggerManual: vi.fn(), extractWeighbridgeError: () => 'err' }),
|
||||
@@ -28,8 +29,6 @@ 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() }))
|
||||
// Site courant (ERP-208) : nécessaire depuis que l'écran filtre les référentiels par site.
|
||||
vi.stubGlobal('useCurrentSite', () => ({ currentSite: ref({ id: 7, name: 'Site 7', color: '#000000' }) }))
|
||||
globalThis.open = mockOpen
|
||||
|
||||
const EditPage = (await import('../weighing-tickets/[id]/edit.vue')).default
|
||||
@@ -102,6 +101,7 @@ describe('Écran Modification ticket de pesée (page /weighing-tickets/{id}/edit
|
||||
mockPatch.mockReset().mockResolvedValue({})
|
||||
mockPush.mockReset()
|
||||
mockOpen.mockReset()
|
||||
mockRefLoad.mockReset().mockResolvedValue(undefined)
|
||||
})
|
||||
|
||||
it('charge le ticket au montage (pré-remplissage via hydrate)', async () => {
|
||||
@@ -109,6 +109,12 @@ describe('Écran Modification ticket de pesée (page /weighing-tickets/{id}/edit
|
||||
expect(mockFetchTicket).toHaveBeenCalledWith('9')
|
||||
})
|
||||
|
||||
it('filtre les référentiels sur le SITE DU TICKET, pas le site courant (ERP-208)', async () => {
|
||||
await mountPage()
|
||||
// DETAIL.site.id = 1 → les listes sont chargées pour le site du ticket (immuable).
|
||||
expect(mockRefLoad).toHaveBeenCalledWith(1)
|
||||
})
|
||||
|
||||
it('ticket validé : action principale « Enregistrer » + « Imprimer » (pas « Valider »)', async () => {
|
||||
const wrapper = await mountPage()
|
||||
// DETAIL.status = VALIDATED → l'action principale s'intitule « Enregistrer ».
|
||||
|
||||
@@ -186,10 +186,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useWeighingTicketForm, type WeighingBlockState } from '~/modules/logistique/composables/useWeighingTicketForm'
|
||||
import { useWeighbridge } from '~/modules/logistique/composables/useWeighbridge'
|
||||
import { useWeighingTicket } from '~/modules/logistique/composables/useWeighingTicket'
|
||||
import { useWeighingTicket, type WeighingTicketDetail } from '~/modules/logistique/composables/useWeighingTicket'
|
||||
import { useWeighingTicketReferentials, type RefOption } from '~/modules/logistique/composables/useWeighingTicketReferentials'
|
||||
import { NUMERIC_MASK, PLATE_MASK, FREE_PLATE_MASK } from '~/modules/logistique/utils/weighingMasks'
|
||||
import { mapViolationsToRecord } from '~/shared/utils/api'
|
||||
@@ -404,28 +404,34 @@ function printTicket(): void {
|
||||
window.open(`/api/weighing_tickets/${ticketId}/print.pdf`, '_blank')
|
||||
}
|
||||
|
||||
const { currentSite } = useCurrentSite()
|
||||
|
||||
/**
|
||||
* Recharge les référentiels Client/Fournisseur pour le site donné, puis purge le
|
||||
* tiers sélectionné s'il n'appartient plus à la liste du nouveau site (ERP-208).
|
||||
* Garantit que la contrepartie DÉJÀ ENREGISTRÉE (hydratée depuis le ticket) reste
|
||||
* affichée même si la liste filtrée par site ne la contient pas (ticket antérieur
|
||||
* à ERP-208, droits restreints sur /clients, contrepartie hors site…) : on injecte
|
||||
* son option plutôt que de la purger. Évite toute perte silencieuse de la
|
||||
* contrepartie en édition (ERP-208, retour review).
|
||||
*/
|
||||
async function reloadReferentials(siteId: number | null): Promise<void> {
|
||||
await referentials.load(siteId)
|
||||
if (form.clientIri.value && !referentials.clients.value.some(o => o.value === form.clientIri.value)) {
|
||||
form.clientIri.value = null
|
||||
function ensureSelectedOptionPresent(detail: WeighingTicketDetail): void {
|
||||
const client = detail.client
|
||||
if (client && !referentials.clients.value.some(o => o.value === client['@id'])) {
|
||||
referentials.clients.value.push({ value: client['@id'], label: client.companyName })
|
||||
}
|
||||
if (form.supplierIri.value && !referentials.suppliers.value.some(o => o.value === form.supplierIri.value)) {
|
||||
form.supplierIri.value = null
|
||||
const supplier = detail.supplier
|
||||
if (supplier && !referentials.suppliers.value.some(o => o.value === supplier['@id'])) {
|
||||
referentials.suppliers.value.push({ value: supplier['@id'], label: supplier.companyName })
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
reloadReferentials(currentSite.value?.id ?? null).catch(() => {})
|
||||
try {
|
||||
const detail = await fetchTicket(ticketId)
|
||||
ticketNumber.value = detail.number ?? ''
|
||||
form.hydrate(detail)
|
||||
// Listes filtrées sur le SITE DU TICKET (immuable, RG-5.09) — pas le site
|
||||
// courant — et chargées APRÈS hydrate pour ne jamais purger la sélection
|
||||
// existante (pas de race load/hydrate, ERP-208).
|
||||
await referentials.load(detail.site?.id ?? null)
|
||||
ensureSelectedOptionPresent(detail)
|
||||
}
|
||||
catch {
|
||||
error.value = true
|
||||
@@ -434,9 +440,4 @@ onMounted(async () => {
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
|
||||
// Changement de site pendant l'édition → recharge les listes du nouveau site (ERP-208).
|
||||
watch(() => currentSite.value?.id, (siteId) => {
|
||||
reloadReferentials(siteId ?? null).catch(() => {})
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user