Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f12a378126 | |||
| 04008f97a9 | |||
| 086be7b4f0 |
+1
-1
@@ -1,2 +1,2 @@
|
||||
parameters:
|
||||
app.version: '0.1.153'
|
||||
app.version: '0.1.154'
|
||||
|
||||
@@ -0,0 +1,353 @@
|
||||
# ERP-208 — Fix ticket de pesée — Plan d'implémentation
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: superpowers:subagent-driven-development ou superpowers:executing-plans. Étapes en cases à cocher (`- [ ]`).
|
||||
|
||||
**Goal:** Ajouter le nom du tiers dans un cartouche bordé en haut à droite du bon de pesée PDF, et filtrer les listes Client/Fournisseur du formulaire de ticket sur le site courant (avec recharge au changement de site).
|
||||
|
||||
**Architecture:** Le filtre back `?siteId[]=` existe déjà sur `/clients` et `/suppliers` (joint adresses→sites) → point 2 = front uniquement. Point 1 = une méthode entité `getCounterpartyName()` + refonte du header du template Twig en table 2 colonnes (Dompdf = CSS 2.1).
|
||||
|
||||
**Tech Stack:** PHP 8.4 / Symfony / API Platform / Doctrine / Twig + Dompdf ; Nuxt 4 / Vue 3 / Vitest.
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- `declare(strict_types=1);` en tête de tout fichier PHP.
|
||||
- Commentaires en **français**, code (noms) en anglais.
|
||||
- Front : `useApi()` uniquement, composants `Malio*`, 4 espaces, TS strict.
|
||||
- Dompdf : **CSS 2.1 uniquement** (pas de flex/grid) → mise en page par tableaux.
|
||||
- **Aucun commit sans demande explicite de Tristan** (les étapes « commit » sont différées en fin de chantier, sur demande).
|
||||
- Vérif finale : `make test` + `make nuxt-test` + `make php-cs-fixer-allow-risky`. Pas d'E2E.
|
||||
|
||||
---
|
||||
|
||||
### Task 1 : `WeighingTicket::getCounterpartyName()` (back)
|
||||
|
||||
**Files:**
|
||||
- Modify: `src/Module/Logistique/Domain/Entity/WeighingTicket.php` (ajout méthode près de `getOtherLabel`, ~ligne 449)
|
||||
- Test: `tests/Module/Logistique/Domain/WeighingTicketCounterpartyNameTest.php` (create)
|
||||
|
||||
**Interfaces:**
|
||||
- Produces: `WeighingTicket::getCounterpartyName(): ?string` — companyName du client/fournisseur ou otherLabel selon `counterpartyType`, null sinon. Consommé par le template Twig (Task 2).
|
||||
|
||||
- [ ] **Step 1 : test qui échoue**
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Module\Logistique\Domain;
|
||||
|
||||
use App\Module\Commercial\Domain\Entity\Client;
|
||||
use App\Module\Commercial\Domain\Entity\Supplier;
|
||||
use App\Module\Logistique\Domain\Entity\WeighingTicket;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class WeighingTicketCounterpartyNameTest extends TestCase
|
||||
{
|
||||
public function testReturnsClientCompanyNameForClientCounterparty(): void
|
||||
{
|
||||
$client = (new Client())->setCompanyName('Ferme du Pré');
|
||||
$ticket = (new WeighingTicket())->setCounterpartyType('CLIENT')->setClient($client);
|
||||
|
||||
self::assertSame('Ferme du Pré', $ticket->getCounterpartyName());
|
||||
}
|
||||
|
||||
public function testReturnsSupplierCompanyNameForSupplierCounterparty(): void
|
||||
{
|
||||
$supplier = (new Supplier())->setCompanyName('Coop Sud');
|
||||
$ticket = (new WeighingTicket())->setCounterpartyType('FOURNISSEUR')->setSupplier($supplier);
|
||||
|
||||
self::assertSame('Coop Sud', $ticket->getCounterpartyName());
|
||||
}
|
||||
|
||||
public function testReturnsOtherLabelForOtherCounterparty(): void
|
||||
{
|
||||
$ticket = (new WeighingTicket())->setCounterpartyType('AUTRE')->setOtherLabel('Particulier');
|
||||
|
||||
self::assertSame('Particulier', $ticket->getCounterpartyName());
|
||||
}
|
||||
|
||||
public function testReturnsNullWhenNoCounterparty(): void
|
||||
{
|
||||
self::assertNull((new WeighingTicket())->getCounterpartyName());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 2 : lancer le test → échec**
|
||||
|
||||
`make test` filtré : `docker exec php-starseed-fpm php bin/phpunit tests/Module/Logistique/Domain/WeighingTicketCounterpartyNameTest.php`
|
||||
Attendu : FAIL (`getCounterpartyName` n'existe pas). Vérifier au passage que `Client`/`Supplier` ont bien un constructeur sans argument et `setCompanyName` (sinon adapter l'instanciation du test au pattern existant des entités).
|
||||
|
||||
- [ ] **Step 3 : implémentation minimale**
|
||||
|
||||
Dans `WeighingTicket.php`, après `getOtherLabel()`/`setOtherLabel()` :
|
||||
|
||||
```php
|
||||
/**
|
||||
* Nom du tiers à afficher (bon de pesée PDF, ERP-208) : raison sociale du
|
||||
* client/fournisseur ou libellé libre selon le type de contrepartie (RG-5.03).
|
||||
* Null si aucune contrepartie cohérente (brouillon).
|
||||
*/
|
||||
public function getCounterpartyName(): ?string
|
||||
{
|
||||
return match ($this->counterpartyType) {
|
||||
'CLIENT' => $this->client?->getCompanyName(),
|
||||
'FOURNISSEUR' => $this->supplier?->getCompanyName(),
|
||||
'AUTRE' => $this->otherLabel,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 4 : lancer le test → succès**
|
||||
|
||||
`docker exec php-starseed-fpm php bin/phpunit tests/Module/Logistique/Domain/WeighingTicketCounterpartyNameTest.php` → PASS.
|
||||
|
||||
---
|
||||
|
||||
### Task 2 : Cartouche tiers dans le template PDF
|
||||
|
||||
**Files:**
|
||||
- Modify: `templates/logistique/weighing_ticket_print.html.twig`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `ticket.counterpartyName` (Task 1).
|
||||
|
||||
- [ ] **Step 1 : ajouter le style du cartouche + header 2 colonnes**
|
||||
|
||||
Dans le `<style>`, ajouter :
|
||||
|
||||
```css
|
||||
.header { width: 100%; border-collapse: collapse; }
|
||||
.header td { vertical-align: top; }
|
||||
.header .h-right { text-align: right; }
|
||||
.party-box { display: inline-block; border: 1px solid #000; padding: 8px 12px; min-width: 160px; text-align: center; font-weight: bold; font-size: 12px; }
|
||||
```
|
||||
|
||||
- [ ] **Step 2 : remplacer le bloc logo + identité par une table 2 colonnes**
|
||||
|
||||
Remplacer (logo + 3 lignes company) par :
|
||||
|
||||
```twig
|
||||
<table class="header">
|
||||
<tr>
|
||||
<td>
|
||||
{% if logoSrc %}
|
||||
<div class="logo"><img src="{{ logoSrc }}" alt="LPC LIOT"></div>
|
||||
{% endif %}
|
||||
<div class="company-name">SA LIOT Châtellerault</div>
|
||||
<div class="company-line">Email : lpc.contacts@lpc-liot.fr</div>
|
||||
<div class="company-line">RCS Châtellerault B 339 505 612</div>
|
||||
</td>
|
||||
<td class="h-right">
|
||||
{% if ticket.counterpartyName %}
|
||||
<div class="party-box">{{ ticket.counterpartyName }}</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
```
|
||||
|
||||
(Le `.title` « Ticket de pesée » et la suite restent inchangés, sous la table.)
|
||||
|
||||
- [ ] **Step 3 : vérifier le rendu PDF**
|
||||
|
||||
Le test existant `WeighingTicketPrintApiTest` doit rester vert :
|
||||
`docker exec php-starseed-fpm php bin/phpunit tests/Module/Logistique/Api/WeighingTicketPrintApiTest.php` → PASS (`%PDF`, content-type, disposition inchangés).
|
||||
|
||||
---
|
||||
|
||||
### Task 3 : `useWeighingTicketReferentials.load(siteId?)` (front)
|
||||
|
||||
**Files:**
|
||||
- Modify: `frontend/modules/logistique/composables/useWeighingTicketReferentials.ts`
|
||||
- Test: `frontend/modules/logistique/composables/__tests__/useWeighingTicketReferentials.spec.ts` (create)
|
||||
|
||||
**Interfaces:**
|
||||
- Produces: `load(siteId?: number | null): Promise<void>` — passe `siteId[]=<siteId>` aux fetch `/clients` et `/suppliers` quand `siteId` est fourni ; sinon comportement actuel (liste complète).
|
||||
|
||||
- [ ] **Step 1 : test qui échoue**
|
||||
|
||||
```ts
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
const getMock = vi.fn()
|
||||
vi.stubGlobal('useApi', () => ({ get: getMock }))
|
||||
|
||||
import { useWeighingTicketReferentials } from '~/modules/logistique/composables/useWeighingTicketReferentials'
|
||||
|
||||
describe('useWeighingTicketReferentials', () => {
|
||||
beforeEach(() => {
|
||||
getMock.mockReset()
|
||||
getMock.mockResolvedValue({ member: [] })
|
||||
})
|
||||
|
||||
it('passe siteId[] aux deux endpoints quand un site est fourni', async () => {
|
||||
const { load } = useWeighingTicketReferentials()
|
||||
await load(7)
|
||||
|
||||
const clientsCall = getMock.mock.calls.find(c => c[0] === '/clients')
|
||||
const suppliersCall = getMock.mock.calls.find(c => c[0] === '/suppliers')
|
||||
expect(clientsCall?.[1]).toMatchObject({ pagination: 'false', 'siteId[]': [7] })
|
||||
expect(suppliersCall?.[1]).toMatchObject({ pagination: 'false', 'siteId[]': [7] })
|
||||
})
|
||||
|
||||
it('ne passe pas siteId[] quand aucun site (liste complète)', async () => {
|
||||
const { load } = useWeighingTicketReferentials()
|
||||
await load(null)
|
||||
|
||||
const clientsCall = getMock.mock.calls.find(c => c[0] === '/clients')
|
||||
expect(clientsCall?.[1]).not.toHaveProperty('siteId[]')
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
- [ ] **Step 2 : lancer → échec**
|
||||
|
||||
`make nuxt-test` (ou ciblé) → FAIL (`load` n'accepte pas d'argument / `siteId[]` absent).
|
||||
|
||||
- [ ] **Step 3 : implémentation**
|
||||
|
||||
Modifier `fetchAll` et `load` :
|
||||
|
||||
```ts
|
||||
/** Récupère une collection complète (pagination désactivée) en Hydra, filtrée site si fourni. */
|
||||
async function fetchAll(url: string, siteId?: number | null): Promise<PartyMember[]> {
|
||||
const query: Record<string, unknown> = { pagination: 'false' }
|
||||
// Filtre par site courant (ERP-208) : un tiers est rattaché à un site via
|
||||
// les sites de ses adresses. Param `siteId[]` déjà géré par les providers M1/M2.
|
||||
if (siteId !== null && siteId !== undefined) {
|
||||
query['siteId[]'] = [siteId]
|
||||
}
|
||||
const res = await api.get<{ member?: PartyMember[] }>(
|
||||
url,
|
||||
query,
|
||||
{ headers: LD_JSON_HEADERS, toast: false },
|
||||
)
|
||||
return res.member ?? []
|
||||
}
|
||||
|
||||
async function load(siteId?: number | null): Promise<void> {
|
||||
await Promise.allSettled([
|
||||
fetchAll('/clients', siteId).then((list) => {
|
||||
clients.value = list.map(c => ({ value: c['@id'], label: c.companyName }))
|
||||
}),
|
||||
fetchAll('/suppliers', siteId).then((list) => {
|
||||
suppliers.value = list.map(s => ({ value: s['@id'], label: s.companyName }))
|
||||
}),
|
||||
])
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 4 : lancer → succès**
|
||||
|
||||
`make nuxt-test` ciblé sur le spec → PASS.
|
||||
|
||||
---
|
||||
|
||||
### Task 4 : Brancher site courant + recharge dans new.vue et edit.vue (front)
|
||||
|
||||
**Files:**
|
||||
- Modify: `frontend/modules/logistique/pages/weighing-tickets/new.vue`
|
||||
- Modify: `frontend/modules/logistique/pages/weighing-tickets/[id]/edit.vue`
|
||||
- Test: `frontend/modules/logistique/pages/__tests__/weighingTicketNew.spec.ts` (étendre)
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `useCurrentSite().currentSite` (ref `Site | null`), `useWeighingTicketReferentials().load(siteId?)`, `form.clientIri` / `form.supplierIri` / `referentials.clients` / `referentials.suppliers`.
|
||||
|
||||
- [ ] **Step 1 : helper de reset partagé**
|
||||
|
||||
Logique commune aux deux pages : après recharge, vider le tiers sélectionné s'il n'est plus dans les options. Implémenté inline dans chaque page (2 lignes) — pas de nouveau composable pour si peu.
|
||||
|
||||
- [ ] **Step 2 : new.vue — brancher currentSite + watch**
|
||||
|
||||
Remplacer le bloc `onMounted` final :
|
||||
|
||||
```ts
|
||||
const { currentSite } = useCurrentSite()
|
||||
|
||||
/** Recharge les référentiels pour le site donné puis purge le tiers devenu hors-site (ERP-208). */
|
||||
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
|
||||
}
|
||||
if (form.supplierIri.value && !referentials.suppliers.value.some(o => o.value === form.supplierIri.value)) {
|
||||
form.supplierIri.value = null
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
reloadReferentials(currentSite.value?.id ?? null).catch(() => {})
|
||||
})
|
||||
|
||||
// Changement de site pendant la saisie → recharge les listes du nouveau site (ERP-208).
|
||||
watch(() => currentSite.value?.id, (siteId) => {
|
||||
reloadReferentials(siteId ?? null).catch(() => {})
|
||||
})
|
||||
```
|
||||
|
||||
Ajouter `watch` à l'import `vue` et `useCurrentSite` (auto-importé Nuxt — sinon import explicite `~/modules/sites/composables/useCurrentSite`).
|
||||
|
||||
- [ ] **Step 3 : edit.vue — même branchement**
|
||||
|
||||
Adapter le `onMounted` async existant (qui fait aussi `fetchTicket`/`hydrate`) :
|
||||
|
||||
```ts
|
||||
const { currentSite } = useCurrentSite()
|
||||
|
||||
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
|
||||
}
|
||||
if (form.supplierIri.value && !referentials.suppliers.value.some(o => o.value === form.supplierIri.value)) {
|
||||
form.supplierIri.value = null
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
reloadReferentials(currentSite.value?.id ?? null).catch(() => {})
|
||||
try {
|
||||
const detail = await fetchTicket(ticketId)
|
||||
ticketNumber.value = detail.number ?? ''
|
||||
form.hydrate(detail)
|
||||
}
|
||||
catch {
|
||||
error.value = true
|
||||
}
|
||||
finally {
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
|
||||
watch(() => currentSite.value?.id, (siteId) => {
|
||||
reloadReferentials(siteId ?? null).catch(() => {})
|
||||
})
|
||||
```
|
||||
|
||||
- [ ] **Step 4 : étendre le spec front**
|
||||
|
||||
Dans `weighingTicketNew.spec.ts`, ajouter un cas vérifiant que `load` est appelé avec l'id du site courant au montage (mock `useCurrentSite` retournant un `currentSite` avec `id`). Adapter au style de mock déjà en place dans le fichier.
|
||||
|
||||
- [ ] **Step 5 : lancer les tests front**
|
||||
|
||||
`make nuxt-test` → PASS (specs new/edit + referentials).
|
||||
|
||||
---
|
||||
|
||||
## Vérification finale
|
||||
|
||||
- [ ] `make test` (back) — vert.
|
||||
- [ ] `make nuxt-test` (front) — vert.
|
||||
- [ ] `make php-cs-fixer-allow-risky` — pas de diff non voulu.
|
||||
- [ ] **STOP** : remettre la main à Tristan pour les tests manuels (impression PDF + switch de site). Commits différés jusqu'à sa demande.
|
||||
|
||||
## Self-review (couverture spec)
|
||||
|
||||
- Point 1 (cartouche PDF nom seul) → Task 1 + Task 2. ✓
|
||||
- Point 2 (filtre site + recharge au switch + reset-si-absent) → Task 3 + Task 4. ✓
|
||||
- Définition « lié au site » via adresses → param `siteId[]` (back déjà OK). ✓
|
||||
- Portée ticket-seulement (pas de modif répertoires) → on n'édite que le composable du ticket + ses pages. ✓
|
||||
- Pas de migration / RBAC / E2E. ✓
|
||||
@@ -0,0 +1,124 @@
|
||||
# ERP-208 — Fix ticket de pesée
|
||||
|
||||
> Module : **Logistique (M5)** — écrans « Ajouter / Modifier un ticket de pesée » + bon de pesée imprimé (PDF).
|
||||
> Branche : `fix/erp-208-ticket-pesee`.
|
||||
> Date : 2026-06-25.
|
||||
|
||||
## 1. Contexte
|
||||
|
||||
Le ticket de pesée (M5) est implémenté (ERP-181 → ERP-193). Deux retours client sont
|
||||
regroupés dans ce fix :
|
||||
|
||||
1. **Bon de pesée PDF** : il manque un **cartouche bordé en haut à droite** de la
|
||||
page contenant le **nom du tiers** (client / fournisseur / champ « autre »). Le
|
||||
PDF actuel n'affiche que l'identité société (SA LIOT) en haut à gauche.
|
||||
2. **Écran de saisie** : quand l'utilisateur a **plusieurs sites autorisés**, les
|
||||
listes déroulantes Client / Fournisseur doivent être **filtrées sur le site
|
||||
courant** (le tiers est rattaché à un site via les sites de ses adresses), et
|
||||
**rechargées si l'utilisateur change de site** en restant sur la page.
|
||||
|
||||
## 2. État du code existant (constats de cadrage)
|
||||
|
||||
- **Le tiers n'a pas de site en propre.** Client (M1) et Supplier (M2) sont
|
||||
rattachés à un site **via les sites de leurs adresses** (`getSites()` agrège ;
|
||||
RG-2.06). « Lié au site » = a au moins une adresse rattachée à ce site.
|
||||
- **Le filtre back existe déjà.** `ClientProvider` / `SupplierProvider` lisent un
|
||||
filtre répétable `?siteId[]=<id>` (drawers des répertoires M1/M2) et le délèguent
|
||||
à `createListQueryBuilder(..., array $siteIds, ...)` → `applySiteIds()` qui joint
|
||||
`addresses → sites` (`site3.id IN (:siteIds)` / `site4.id IN (:siteIds)`).
|
||||
**Aucun travail back n'est nécessaire pour le filtre.**
|
||||
- **La donnée du PDF est déjà chargée.** `DoctrineWeighingTicketRepository::findById()`
|
||||
fetch-joine `client` et `supplier` ; le `WeighingTicketPrintProvider` charge le
|
||||
ticket par cette méthode. Le template a donc accès au nom du tiers.
|
||||
- **Le changement de site est global** (`SiteSelector` header → `useCurrentSite.switchSite`
|
||||
→ `PATCH /me/current-site` + `loadSidebar()` + `refreshNuxtData()`). `currentSite`
|
||||
est un ref singleton de module. Les référentiels du ticket sont chargés en
|
||||
`onMounted` **uniquement** (pas via `useAsyncData`) → ils ne se rechargent pas au
|
||||
switch : **c'est le bug du point 2.**
|
||||
- Le template PDF (`templates/logistique/weighing_ticket_print.html.twig`) est rendu
|
||||
par Dompdf → **CSS 2.1 uniquement (pas de flexbox/grid)**, mise en page par tableaux.
|
||||
|
||||
## 3. Décisions (validées avec Tristan)
|
||||
|
||||
| Sujet | Décision |
|
||||
|---|---|
|
||||
| Définition « lié au site » | Tiers ayant ≥ 1 adresse rattachée au site sélectionné (via les adresses). |
|
||||
| Portée du filtre | **Ticket de pesée seulement.** On ne modifie PAS le comportement des répertoires M1/M2 (déjà validés). On réutilise le param `?siteId[]=` existant côté front. |
|
||||
| Switch de site avec tiers sélectionné | **Reset si absent** : après rechargement, si le tiers sélectionné n'est plus dans la liste du nouveau site, on vide sa valeur (le type de contrepartie reste). S'il y est encore, on le garde. |
|
||||
| Contenu du cartouche PDF | **Nom seul** (pas de libellé « Client » / « Fournisseur » au-dessus). |
|
||||
|
||||
## 4. Conception
|
||||
|
||||
### 4.1 Point 1 — Cartouche tiers sur le bon de pesée (back + template)
|
||||
|
||||
**a. Résolution du nom — `WeighingTicket::getCounterpartyName(): ?string`**
|
||||
|
||||
Nouvelle méthode sur l'entité qui retourne, selon `counterpartyType` :
|
||||
- `CLIENT` → `client?->getCompanyName()`
|
||||
- `FOURNISSEUR` → `supplier?->getCompanyName()`
|
||||
- `AUTRE` → `otherLabel`
|
||||
- défaut → `null`
|
||||
|
||||
Rationale : garde le Twig « bête » (un seul `{{ ticket.counterpartyName }}`) et rend
|
||||
la logique testable unitairement, sans toucher le provider ni le renderer.
|
||||
|
||||
**b. Template `weighing_ticket_print.html.twig`**
|
||||
|
||||
Passer le bloc d'en-tête en **table 2 colonnes** (contrainte Dompdf CSS 2.1) :
|
||||
- colonne gauche (`width:auto`, `vertical-align:top`) : logo + identité société
|
||||
(contenu **inchangé**) ;
|
||||
- colonne droite (`text-align:right`, `vertical-align:top`) : un cartouche
|
||||
`border:1px solid #000; padding:8px;` (largeur fixe, ~200px) contenant
|
||||
`{{ ticket.counterpartyName }}` (nom seul, en gras).
|
||||
|
||||
Le reste du template (titre, table des pesées, poids net) est inchangé.
|
||||
|
||||
Cas `counterpartyName` null : en pratique l'impression a lieu après validation, où la
|
||||
contrepartie est requise (groupe `finalize`). Par robustesse, si null → ne pas rendre
|
||||
le cartouche (pas de cadre vide).
|
||||
|
||||
**c. Provider / renderer** : aucun changement (relations déjà fetch-jointes).
|
||||
|
||||
### 4.2 Point 2 — Listes filtrées par site + recharge au switch (front uniquement)
|
||||
|
||||
**a. `useWeighingTicketReferentials.ts`**
|
||||
|
||||
`load()` accepte un identifiant de site optionnel et l'injecte comme `siteId[]` dans
|
||||
les requêtes `/clients` et `/suppliers` (en plus de `pagination=false`) :
|
||||
- site fourni → `{ pagination: 'false', 'siteId[]': [siteId] }` ;
|
||||
- site absent (`null`) → comportement actuel (liste complète, dégradé gracieux).
|
||||
|
||||
**b. Pages `weighing-tickets/new.vue` et `weighing-tickets/[id]/edit.vue`**
|
||||
|
||||
- récupèrent `currentSite` via `useCurrentSite()` ;
|
||||
- `onMounted` → `referentials.load(currentSite.value?.id ?? null)` ;
|
||||
- `watch(currentSite)` (sur l'id) → `referentials.load(newId)` puis **reset-si-absent** :
|
||||
- si `form.clientIri` est défini et absent de `referentials.clients` → `form.clientIri = null` ;
|
||||
- si `form.supplierIri` est défini et absent de `referentials.suppliers` → `form.supplierIri = null` ;
|
||||
- `counterpartyType` et `otherLabel` ne sont pas touchés.
|
||||
|
||||
Note : le reset s'appuie sur les options (IRI `@id`) renvoyées par le référentiel ;
|
||||
la comparaison se fait sur `value` (l'IRI Hydra).
|
||||
|
||||
**c. Cohérence avec la liste des tickets** : la liste `/weighing_tickets` est déjà
|
||||
cloisonnée par site (provider M5). Filtrer les selects sur le site courant aligne la
|
||||
saisie sur la liste.
|
||||
|
||||
## 5. Tests & vérification
|
||||
|
||||
| Niveau | Test | Contenu |
|
||||
|---|---|---|
|
||||
| Back (PHPUnit) | unitaire `WeighingTicket::getCounterpartyName()` | 3 cas : CLIENT → companyName, FOURNISSEUR → companyName, AUTRE → otherLabel ; + null si type absent. |
|
||||
| Back | `WeighingTicketPrintApiTest` (existant) | reste vert (`%PDF`, content-type, disposition). |
|
||||
| Front (Vitest) | `weighingTicketNew.spec.ts` / `weighingTicketEdit.spec.ts` | `load` passe `siteId[]` quand un site courant existe ; au changement de `currentSite` → rechargement + reset-si-absent du tiers sélectionné. |
|
||||
|
||||
Commandes : `make test` + `make nuxt-test` + `make php-cs-fixer-allow-risky`.
|
||||
Pas de test E2E (règle d'or : Vitest privilégié).
|
||||
|
||||
## 6. Hors périmètre / non-objectifs
|
||||
|
||||
- Pas de modification du comportement des répertoires Clients / Fournisseurs (M1/M2).
|
||||
- Pas de nouvelle permission RBAC, pas de migration, pas de changement de schéma.
|
||||
- Pas de cloisonnement par site « global » sur `/clients` et `/suppliers` (rejeté :
|
||||
on garde le filtre opt-in via `?siteId[]`).
|
||||
- L'identité société du PDF reste fixe (décision ERP-192, ne change pas selon le site).
|
||||
@@ -1020,6 +1020,37 @@
|
||||
"duplicate": "Une catégorie nommée « {name} » existe déjà.",
|
||||
"typesLoadFailed": "Impossible de charger les types de catégorie. Réessayez."
|
||||
}
|
||||
},
|
||||
"products": {
|
||||
"title": "Catalogue produit",
|
||||
"add": "Ajouter",
|
||||
"export": "Exporter",
|
||||
"empty": "Aucun produit pour l'instant.",
|
||||
"column": {
|
||||
"name": "Nom",
|
||||
"code": "Numéro",
|
||||
"category": "Catégorie"
|
||||
},
|
||||
"state": {
|
||||
"PURCHASE": "Acheté",
|
||||
"SALE": "Vendu",
|
||||
"OTHER": "Autre"
|
||||
},
|
||||
"filters": {
|
||||
"title": "Filtres",
|
||||
"search": "Recherche",
|
||||
"category": "Catégorie",
|
||||
"categoryAll": "Toutes les catégories",
|
||||
"state": "État",
|
||||
"stateAll": "Tous les états",
|
||||
"site": "Sites",
|
||||
"apply": "Voir les résultats",
|
||||
"reset": "Réinitialiser"
|
||||
},
|
||||
"toast": {
|
||||
"error": "Une erreur est survenue. Réessayez.",
|
||||
"exportError": "L'export du catalogue produit a échoué. Réessayez."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,272 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
import { defineComponent, h, ref } from 'vue'
|
||||
|
||||
// ── Auto-imports Nuxt stubbes globalement ───────────────────────────────────
|
||||
// La page ne les importe pas (auto-import) : on les expose en globals pour le
|
||||
// runtime de test (happy-dom). Meme philosophie que les specs M1→M5.
|
||||
const mockPush = vi.hoisted(() => vi.fn())
|
||||
const mockApiGet = vi.hoisted(() => vi.fn())
|
||||
const mockCan = vi.hoisted(() => vi.fn())
|
||||
const mockSetFilters = vi.hoisted(() => vi.fn())
|
||||
const mockFetch = vi.hoisted(() => vi.fn())
|
||||
const mockToastError = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||
vi.stubGlobal('useHead', () => undefined)
|
||||
vi.stubGlobal('useApi', () => ({ get: mockApiGet }))
|
||||
vi.stubGlobal('useRouter', () => ({ push: mockPush }))
|
||||
vi.stubGlobal('useToast', () => ({ error: mockToastError, success: vi.fn() }))
|
||||
vi.stubGlobal('usePermissions', () => ({ can: mockCan }))
|
||||
// usePaginatedList est l'auto-import pilotant la liste : on controle items +
|
||||
// setFilters + fetch. La ligne reproduit le contrat JSON reel (§ 4.0.bis).
|
||||
vi.stubGlobal('usePaginatedList', () => ({
|
||||
items: ref<Array<Record<string, unknown>>>([
|
||||
{
|
||||
id: 34,
|
||||
code: 'BLE-TENDRE-01',
|
||||
name: 'Blé tendre',
|
||||
states: ['PURCHASE', 'SALE'],
|
||||
manufactured: true,
|
||||
containsMolasses: true,
|
||||
category: { id: 12, name: 'Céréales', code: 'CEREALES' },
|
||||
sites: [{ id: 1, name: 'Chatellerault', code: '86' }],
|
||||
storageTypes: [{ id: 9, code: 'TAS', label: 'Tas' }],
|
||||
},
|
||||
]),
|
||||
totalItems: ref(1),
|
||||
currentPage: ref(1),
|
||||
itemsPerPage: ref(10),
|
||||
itemsPerPageOptions: ref([10, 25, 50]),
|
||||
fetch: mockFetch,
|
||||
goToPage: vi.fn(),
|
||||
setItemsPerPage: vi.fn(),
|
||||
setFilters: mockSetFilters,
|
||||
}))
|
||||
|
||||
// happy-dom n'implemente pas createObjectURL : on ajoute les methodes statiques
|
||||
// sur la classe URL existante (sans la remplacer — sinon `new URL()` casse).
|
||||
globalThis.URL.createObjectURL = vi.fn(() => 'blob:fake')
|
||||
globalThis.URL.revokeObjectURL = vi.fn()
|
||||
|
||||
// Import APRES les stubs (la page resout les auto-imports au top-level du module).
|
||||
const ProductsIndex = (await import('../admin/products.vue')).default
|
||||
|
||||
// ── Stubs de composants ──────────────────────────────────────────────────────
|
||||
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 DataTableStub = defineComponent({
|
||||
props: { items: { type: Array, default: () => [] } },
|
||||
emits: ['row-click', 'update:page', 'update:per-page'],
|
||||
setup(props, { emit }) {
|
||||
return () => h('div', { 'data-testid': 'datatable' },
|
||||
(props.items as Array<Record<string, unknown>>).map(it =>
|
||||
h('tr', {
|
||||
'data-row-id': it.id,
|
||||
'data-name': it.name,
|
||||
'data-code': it.code,
|
||||
'data-category': it.categoryName,
|
||||
'onClick': () => emit('row-click', it),
|
||||
}),
|
||||
),
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
const DrawerStub = defineComponent({
|
||||
props: { modelValue: { type: Boolean, default: false } },
|
||||
setup(_, { slots }) {
|
||||
return () => h('div', {}, [slots.header?.(), slots.default?.(), slots.footer?.()])
|
||||
},
|
||||
})
|
||||
|
||||
const SlotStub = defineComponent({ setup(_, { slots }) { return () => h('div', {}, slots.default?.()) } })
|
||||
|
||||
const PageHeaderStub = defineComponent({
|
||||
setup(_, { slots }) { return () => h('div', {}, [slots.default?.(), slots.actions?.()]) },
|
||||
})
|
||||
|
||||
const CheckboxStub = defineComponent({
|
||||
props: { id: { type: String, default: '' }, modelValue: { type: Boolean, default: false } },
|
||||
emits: ['update:model-value'],
|
||||
setup(props, { emit }) {
|
||||
return () => h('input', {
|
||||
'type': 'checkbox',
|
||||
'data-id': props.id,
|
||||
'onChange': (e: Event) => emit('update:model-value', (e.target as HTMLInputElement).checked),
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
const SelectStub = defineComponent({
|
||||
props: {
|
||||
modelValue: { type: [String, Number, null] as unknown as () => string | number | null, default: null },
|
||||
options: { type: Array, default: () => [] },
|
||||
emptyOptionLabel: { type: String, default: '' },
|
||||
},
|
||||
emits: ['update:model-value'],
|
||||
setup(props, { emit }) {
|
||||
return () => h('select', {
|
||||
'data-empty-label': props.emptyOptionLabel,
|
||||
'onChange': (e: Event) => emit('update:model-value', (e.target as HTMLSelectElement).value),
|
||||
}, (props.options as Array<{ value: string | number, label: string }>).map(o =>
|
||||
h('option', { value: o.value }, o.label),
|
||||
))
|
||||
},
|
||||
})
|
||||
|
||||
const InputTextStub = defineComponent({ setup() { return () => h('input') } })
|
||||
|
||||
function mountPage() {
|
||||
return mount(ProductsIndex, {
|
||||
global: {
|
||||
stubs: {
|
||||
PageHeader: PageHeaderStub,
|
||||
MalioButton: ButtonStub,
|
||||
MalioDataTable: DataTableStub,
|
||||
MalioDrawer: DrawerStub,
|
||||
MalioAccordion: SlotStub,
|
||||
MalioAccordionItem: SlotStub,
|
||||
MalioInputText: InputTextStub,
|
||||
MalioSelect: SelectStub,
|
||||
MalioCheckbox: CheckboxStub,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
describe('Catalogue produit (page /admin/products)', () => {
|
||||
beforeEach(() => {
|
||||
mockPush.mockReset()
|
||||
mockApiGet.mockReset().mockImplementation((url: string) => {
|
||||
if (url === '/categories') {
|
||||
return Promise.resolve({ member: [{ '@id': '/api/categories/12', id: 12, name: 'Céréales' }] })
|
||||
}
|
||||
if (url === '/sites') {
|
||||
return Promise.resolve({ member: [{ id: 1, name: 'Chatellerault' }] })
|
||||
}
|
||||
return Promise.resolve({ member: [] })
|
||||
})
|
||||
mockCan.mockReset().mockReturnValue(true)
|
||||
mockSetFilters.mockReset()
|
||||
mockFetch.mockReset()
|
||||
mockToastError.mockReset()
|
||||
})
|
||||
|
||||
it('charge la liste au montage', async () => {
|
||||
mountPage()
|
||||
await flushPromises()
|
||||
expect(mockFetch).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('mappe les colonnes Nom / Numéro / Catégorie sur le JSON réel (§ 4.0.bis)', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
const row = wrapper.find('tr[data-row-id="34"]')
|
||||
expect(row.attributes('data-name')).toBe('Blé tendre')
|
||||
expect(row.attributes('data-code')).toBe('BLE-TENDRE-01')
|
||||
expect(row.attributes('data-category')).toBe('Céréales')
|
||||
})
|
||||
|
||||
it('affiche « + Ajouter » uniquement avec la permission manage', async () => {
|
||||
mockCan.mockImplementation((perm: string) => perm === 'catalog.products.manage')
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
expect(wrapper.find('[data-label="admin.products.add"]').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('masque « + Ajouter » sans la permission manage (view seul)', async () => {
|
||||
mockCan.mockImplementation((perm: string) => perm === 'catalog.products.view')
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
expect(wrapper.find('[data-label="admin.products.add"]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('navigue vers l\'édition au clic sur une ligne', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
await wrapper.find('tr[data-row-id="34"]').trigger('click')
|
||||
expect(mockPush).toHaveBeenCalledWith('/admin/products/34/edit')
|
||||
})
|
||||
|
||||
it('navigue vers la création au clic sur « + Ajouter »', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
await wrapper.find('[data-label="admin.products.add"]').trigger('click')
|
||||
expect(mockPush).toHaveBeenCalledWith('/admin/products/new')
|
||||
})
|
||||
|
||||
it('appelle l\'export XLSX sur /products/export.xlsx en blob', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
await wrapper.find('[data-label="admin.products.export"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(mockApiGet).toHaveBeenCalledWith(
|
||||
'/products/export.xlsx',
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseType: 'blob', toast: false }),
|
||||
)
|
||||
})
|
||||
|
||||
it('répercute les sites cochés dans setFilters (filtre multi, clé siteId[])', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('input[data-id="filter-site-1"]').setValue(true)
|
||||
await wrapper.find('[data-label="admin.products.filters.apply"]').trigger('click')
|
||||
|
||||
expect(mockSetFilters).toHaveBeenLastCalledWith(
|
||||
{ 'siteId[]': ['1'] },
|
||||
{ replace: true },
|
||||
)
|
||||
// Etat 100 % local (regle n°6) : aucune navigation/query string declenchee.
|
||||
expect(mockPush).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('répercute l\'état sélectionné dans setFilters (param state)', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('select[data-empty-label="admin.products.filters.stateAll"]').setValue('SALE')
|
||||
await wrapper.find('[data-label="admin.products.filters.apply"]').trigger('click')
|
||||
|
||||
expect(mockSetFilters).toHaveBeenLastCalledWith(
|
||||
{ state: 'SALE' },
|
||||
{ replace: true },
|
||||
)
|
||||
})
|
||||
|
||||
it('répercute la catégorie sélectionnée dans setFilters (param categoryId)', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('select[data-empty-label="admin.products.filters.categoryAll"]').setValue('12')
|
||||
await wrapper.find('[data-label="admin.products.filters.apply"]').trigger('click')
|
||||
|
||||
expect(mockSetFilters).toHaveBeenLastCalledWith(
|
||||
{ categoryId: '12' },
|
||||
{ replace: true },
|
||||
)
|
||||
})
|
||||
|
||||
it('badge filtres actifs + Réinitialiser vide l\'état appliqué', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('input[data-id="filter-site-1"]').setValue(true)
|
||||
await wrapper.find('[data-label="admin.products.filters.apply"]').trigger('click')
|
||||
|
||||
// Le libelle du bouton Filtrer porte le compteur (1 filtre actif).
|
||||
expect(wrapper.find('[data-label="admin.products.filters.title (1)"]').exists()).toBe(true)
|
||||
|
||||
// Réinitialiser → query propre (setFilters avec objet vide).
|
||||
await wrapper.find('[data-label="admin.products.filters.reset"]').trigger('click')
|
||||
expect(mockSetFilters).toHaveBeenLastCalledWith({}, { replace: true })
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,377 @@
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader>
|
||||
{{ t('admin.products.title') }}
|
||||
<template #actions>
|
||||
<!-- gap-8 = 32px d'espacement entre Filtrer et Ajouter (meme
|
||||
design que le Repertoire transporteurs / la Gestion des categories). -->
|
||||
<div class="flex items-center gap-8">
|
||||
<!-- Bouton Filtrer a GAUCHE d'Ajouter. Le compteur reflete les filtres actifs. -->
|
||||
<MalioButton
|
||||
v-if="canView"
|
||||
variant="tertiary"
|
||||
:label="filterButtonLabel"
|
||||
icon-name="mdi:tune"
|
||||
icon-position="left"
|
||||
icon-size="24"
|
||||
@click="openFilters"
|
||||
/>
|
||||
<MalioButton
|
||||
v-if="canManage"
|
||||
variant="secondary"
|
||||
:label="t('admin.products.add')"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
@click="goToCreate"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</PageHeader>
|
||||
|
||||
<!-- Datatable branchee sur usePaginatedList : pagination serveur, tri
|
||||
name ASC par defaut (cote back, § 4.1). Colonnes Nom / Numero /
|
||||
Categorie (docx p.3). -->
|
||||
<MalioDataTable
|
||||
:columns="columns"
|
||||
:items="rows"
|
||||
:total-items="totalItems"
|
||||
:page="currentPage"
|
||||
:per-page="itemsPerPage"
|
||||
:per-page-options="itemsPerPageOptions"
|
||||
row-clickable
|
||||
:empty-message="t('admin.products.empty')"
|
||||
@row-click="onRowClick"
|
||||
@update:page="goToPage"
|
||||
@update:per-page="setItemsPerPage"
|
||||
/>
|
||||
|
||||
<div class="flex justify-center mt-4">
|
||||
<MalioButton
|
||||
v-if="canView"
|
||||
variant="primary"
|
||||
:label="t('admin.products.export')"
|
||||
:disabled="exporting"
|
||||
@click="exportXlsx"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Drawer de filtres : etat BROUILLON, applique uniquement au clic sur
|
||||
« Voir les résultats ». Meme pattern que les repertoires M1→M5.
|
||||
Etat 100 % local, jamais dans l'URL (regle ABSOLUE n°6). -->
|
||||
<MalioDrawer
|
||||
v-model="filterDrawerOpen"
|
||||
drawer-class="max-w-[450px]"
|
||||
body-class="p-0"
|
||||
footer-class="justify-between border-t border-black p-6"
|
||||
>
|
||||
<template #header>
|
||||
<h2 class="text-[24px] font-bold uppercase">{{ t('admin.products.filters.title') }}</h2>
|
||||
</template>
|
||||
|
||||
<MalioAccordion>
|
||||
<!-- Recherche : code + nom (param `search`, partiel insensible a la casse). -->
|
||||
<MalioAccordionItem :title="t('admin.products.filters.search')" value="search">
|
||||
<MalioInputText
|
||||
v-model="draftSearch"
|
||||
icon-name="mdi:magnify"
|
||||
/>
|
||||
</MalioAccordionItem>
|
||||
|
||||
<!-- Categorie : select simple (param `categoryId`). Referentiel borne
|
||||
aux categories de type PRODUIT (RG-6.05). -->
|
||||
<MalioAccordionItem :title="t('admin.products.filters.category')" value="category">
|
||||
<MalioSelect
|
||||
:model-value="draftCategoryId"
|
||||
:options="categoryOptions"
|
||||
:empty-option-label="t('admin.products.filters.categoryAll')"
|
||||
@update:model-value="(v: string | number | null) => draftCategoryId = v === null || v === '' ? null : Number(v)"
|
||||
/>
|
||||
</MalioAccordionItem>
|
||||
|
||||
<!-- Etat : select simple (param `state`, enum PURCHASE / SALE / OTHER). -->
|
||||
<MalioAccordionItem :title="t('admin.products.filters.state')" value="state">
|
||||
<MalioSelect
|
||||
:model-value="draftState"
|
||||
:options="stateOptions"
|
||||
:empty-option-label="t('admin.products.filters.stateAll')"
|
||||
@update:model-value="(v: string | number | null) => draftState = v === null || v === '' ? null : String(v)"
|
||||
/>
|
||||
</MalioAccordionItem>
|
||||
|
||||
<!-- Site(s) : cases a cocher (multi, param `siteId[]`). Un produit
|
||||
remonte s'il est disponible sur AU MOINS UN des sites coches. -->
|
||||
<MalioAccordionItem :title="t('admin.products.filters.site')" value="site">
|
||||
<div class="flex flex-col">
|
||||
<MalioCheckbox
|
||||
v-for="opt in siteOptions"
|
||||
:id="`filter-site-${opt.value}`"
|
||||
:key="opt.value"
|
||||
:label="opt.label"
|
||||
:model-value="draftSiteIds.includes(opt.value)"
|
||||
@update:model-value="(val: boolean) => toggleSite(opt.value, val)"
|
||||
/>
|
||||
</div>
|
||||
</MalioAccordionItem>
|
||||
</MalioAccordion>
|
||||
|
||||
<template #footer>
|
||||
<MalioButton
|
||||
variant="tertiary"
|
||||
:label="t('admin.products.filters.reset')"
|
||||
button-class="w-m-btn-action"
|
||||
@click="resetFilters"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('admin.products.filters.apply')"
|
||||
button-class="w-[170px]"
|
||||
@click="applyFilters"
|
||||
/>
|
||||
</template>
|
||||
</MalioDrawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import type { Product } from '~/modules/catalog/types/product'
|
||||
|
||||
interface FilterOption {
|
||||
value: number
|
||||
label: string
|
||||
}
|
||||
|
||||
const { t } = useI18n()
|
||||
const api = useApi()
|
||||
const router = useRouter()
|
||||
const toast = useToast()
|
||||
const { can } = usePermissions()
|
||||
|
||||
useHead({ title: t('admin.products.title') })
|
||||
|
||||
// Catalogue produit admin-only (docx p.3) : « + Ajouter » reserve a `manage`.
|
||||
// « Filtrer » / « Exporter » suivent `view` (gate page-level). L'item sidebar
|
||||
// est deja masque cote back pour les roles sans `view` (RBAC § 5.2).
|
||||
const canManage = computed(() => can('catalog.products.manage'))
|
||||
const canView = computed(() => can('catalog.products.view'))
|
||||
|
||||
// Pagination serveur via le composable partage. Le ProductProvider applique
|
||||
// deja name ASC (§ 4.1) — pas de defaultSort cote front tant qu'aucun
|
||||
// OrderFilter n'est expose.
|
||||
const {
|
||||
items: products,
|
||||
totalItems,
|
||||
currentPage,
|
||||
itemsPerPage,
|
||||
itemsPerPageOptions,
|
||||
fetch: loadProducts,
|
||||
goToPage,
|
||||
setItemsPerPage,
|
||||
setFilters,
|
||||
} = usePaginatedList<Product>({ url: '/products' })
|
||||
|
||||
// Mappe les produits en objets « plats » pour MalioDataTable (items typees
|
||||
// Record<string, unknown>[]) : un objet litteral porte une signature d'index
|
||||
// implicite, contrairement a l'interface Product. Meme pattern que M1→M5.
|
||||
const rows = computed(() => products.value.map(product => ({
|
||||
id: product.id,
|
||||
name: product.name,
|
||||
code: product.code,
|
||||
categoryName: product.category?.name ?? '',
|
||||
})))
|
||||
|
||||
const columns = [
|
||||
{ key: 'name', label: t('admin.products.column.name') },
|
||||
{ key: 'code', label: t('admin.products.column.code') },
|
||||
{ key: 'categoryName', label: t('admin.products.column.category') },
|
||||
]
|
||||
|
||||
/** Clic sur une ligne → ecran d'edition (route imbriquee /admin/products/{id}/edit). */
|
||||
function onRowClick(item: Record<string, unknown>): void {
|
||||
router.push(`/admin/products/${item.id}/edit`)
|
||||
}
|
||||
|
||||
function goToCreate(): void {
|
||||
router.push('/admin/products/new')
|
||||
}
|
||||
|
||||
// ── Referentiels des filtres ─────────────────────────────────────────────────
|
||||
// Charges une fois (pagination desactivee, referentiels bornes). Categories
|
||||
// filtrees au type PRODUIT (RG-6.05) ; sites = tous les sites actifs.
|
||||
const categoryOptions = ref<FilterOption[]>([])
|
||||
const siteOptions = ref<FilterOption[]>([])
|
||||
|
||||
// Etats produit (miroir de l'enum back Product::STATE_*). Le libelle est resolu
|
||||
// par i18n. Select simple cote filtre (`?state=` n'accepte qu'une valeur).
|
||||
const PRODUCT_STATES = ['PURCHASE', 'SALE', 'OTHER'] as const
|
||||
|
||||
const stateOptions = computed(() =>
|
||||
PRODUCT_STATES.map(code => ({ value: code, label: t(`admin.products.state.${code}`) })),
|
||||
)
|
||||
|
||||
interface HydraMember { '@id': string, id: number, name?: string, postalCode?: string }
|
||||
|
||||
/** Recupere une collection complete (pagination desactivee) en Hydra. */
|
||||
async function fetchAll<T extends HydraMember>(
|
||||
url: string,
|
||||
query: Record<string, string> = {},
|
||||
): Promise<T[]> {
|
||||
const res = await api.get<{ member?: T[] }>(
|
||||
url,
|
||||
{ pagination: 'false', ...query },
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
return res.member ?? []
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge les referentiels des filtres en parallele et de maniere resiliente :
|
||||
* un referentiel en echec (403/500) reste vide sans casser l'autre.
|
||||
*/
|
||||
async function loadFilterReferentials(): Promise<void> {
|
||||
await Promise.allSettled([
|
||||
fetchAll('/categories', { typeCode: 'PRODUIT' })
|
||||
.then((cats) => { categoryOptions.value = cats.map(c => ({ value: c.id, label: c.name ?? '' })) }),
|
||||
fetchAll('/sites')
|
||||
.then((sitesList) => { siteOptions.value = sitesList.map(s => ({ value: s.id, label: s.name ?? '' })) }),
|
||||
])
|
||||
}
|
||||
|
||||
// ── Filtres (drawer) ─────────────────────────────────────────────────────────
|
||||
// Deux niveaux d'etat (pattern repertoires M1→M5) :
|
||||
// - APPLIED : pilote la liste/l'export + le compteur du bouton. Modifie
|
||||
// uniquement au clic « Voir les résultats » / « Réinitialiser ».
|
||||
// - DRAFT : edite librement dans le drawer ; recopie vers applied a la validation.
|
||||
const filterDrawerOpen = ref(false)
|
||||
|
||||
const draftSearch = ref('')
|
||||
const draftCategoryId = ref<number | null>(null)
|
||||
const draftState = ref<string | null>(null)
|
||||
const draftSiteIds = ref<number[]>([])
|
||||
|
||||
const appliedSearch = ref('')
|
||||
const appliedCategoryId = ref<number | null>(null)
|
||||
const appliedState = ref<string | null>(null)
|
||||
const appliedSiteIds = ref<number[]>([])
|
||||
|
||||
const activeFilterCount = computed(() => {
|
||||
let count = 0
|
||||
if (appliedSearch.value.trim() !== '') count++
|
||||
if (appliedCategoryId.value !== null) count++
|
||||
if (appliedState.value !== null) count++
|
||||
if (appliedSiteIds.value.length > 0) count++
|
||||
return count
|
||||
})
|
||||
|
||||
const filterButtonLabel = computed(() => {
|
||||
const base = t('admin.products.filters.title')
|
||||
return activeFilterCount.value > 0 ? `${base} (${activeFilterCount.value})` : base
|
||||
})
|
||||
|
||||
// Recopie l'etat applique vers le brouillon puis ouvre le drawer : la reouverture
|
||||
// reflete les filtres actifs.
|
||||
function openFilters(): void {
|
||||
draftSearch.value = appliedSearch.value
|
||||
draftCategoryId.value = appliedCategoryId.value
|
||||
draftState.value = appliedState.value
|
||||
draftSiteIds.value = [...appliedSiteIds.value]
|
||||
filterDrawerOpen.value = true
|
||||
}
|
||||
|
||||
/** Coche / decoche un site dans le brouillon (filtre multi). */
|
||||
function toggleSite(id: number, selected: boolean): void {
|
||||
draftSiteIds.value = selected
|
||||
? [...draftSiteIds.value, id]
|
||||
: draftSiteIds.value.filter(s => s !== id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Construit le payload de filtres serveur a partir de l'etat applique. Cle
|
||||
* `siteId[]` pour que PHP la parse en tableau (OR cote back). Les filtres vides
|
||||
* sont omis pour une query propre.
|
||||
*/
|
||||
function buildFilterPayload(): Record<string, string | string[]> {
|
||||
const payload: Record<string, string | string[]> = {}
|
||||
if (appliedSearch.value.trim() !== '') payload.search = appliedSearch.value.trim()
|
||||
if (appliedCategoryId.value !== null) payload.categoryId = String(appliedCategoryId.value)
|
||||
if (appliedState.value !== null) payload.state = appliedState.value
|
||||
if (appliedSiteIds.value.length > 0) payload['siteId[]'] = appliedSiteIds.value.map(String)
|
||||
return payload
|
||||
}
|
||||
|
||||
// « Voir les résultats » : recopie brouillon → applied, pousse les filtres
|
||||
// (retombe en page 1 via usePaginatedList) et ferme le drawer.
|
||||
function applyFilters(): void {
|
||||
appliedSearch.value = draftSearch.value.trim()
|
||||
appliedCategoryId.value = draftCategoryId.value
|
||||
appliedState.value = draftState.value
|
||||
appliedSiteIds.value = [...draftSiteIds.value]
|
||||
|
||||
setFilters(buildFilterPayload(), { replace: true })
|
||||
filterDrawerOpen.value = false
|
||||
}
|
||||
|
||||
// « Réinitialiser » : vide brouillon ET applied, recharge la liste complete.
|
||||
// Le drawer reste ouvert pour montrer le formulaire vide.
|
||||
function resetFilters(): void {
|
||||
draftSearch.value = ''
|
||||
draftCategoryId.value = null
|
||||
draftState.value = null
|
||||
draftSiteIds.value = []
|
||||
|
||||
appliedSearch.value = ''
|
||||
appliedCategoryId.value = null
|
||||
appliedState.value = null
|
||||
appliedSiteIds.value = []
|
||||
|
||||
setFilters({}, { replace: true })
|
||||
}
|
||||
|
||||
// ── Export XLSX ──────────────────────────────────────────────────────────────
|
||||
// Memes filtres que la vue : l'export reflete exactement ce que l'utilisateur voit.
|
||||
const exporting = ref(false)
|
||||
|
||||
async function exportXlsx(): Promise<void> {
|
||||
if (exporting.value) {
|
||||
return
|
||||
}
|
||||
exporting.value = true
|
||||
try {
|
||||
// useApi type ses options en JSON ; l'export renvoie un binaire, donc on
|
||||
// force responseType:'blob' (transmis tel quel a ofetch au runtime). Cast
|
||||
// contenu faute d'overload blob sur le client partage (meme pattern M2→M5).
|
||||
const blob = await api.get<Blob>('/products/export.xlsx', buildFilterPayload(), {
|
||||
responseType: 'blob',
|
||||
toast: false,
|
||||
} as unknown as Parameters<typeof api.get>[2])
|
||||
|
||||
triggerDownload(blob, 'catalogue-produits.xlsx')
|
||||
}
|
||||
catch {
|
||||
toast.error({
|
||||
title: t('admin.products.toast.error'),
|
||||
message: t('admin.products.toast.exportError'),
|
||||
})
|
||||
}
|
||||
finally {
|
||||
exporting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** Declenche le telechargement d'un blob via un lien temporaire. */
|
||||
function triggerDownload(blob: Blob, filename: string): void {
|
||||
const url = URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = filename
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadProducts()
|
||||
loadFilterReferentials()
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Types front du module Catalog (M6 — Catalogue produit).
|
||||
*
|
||||
* Contrats API consommes :
|
||||
* - GET /api/products → HydraCollection<Product>
|
||||
* - GET /api/products/{id} → Product
|
||||
* - GET /api/products/export.xlsx → binaire XLSX (export complet, filtres actifs)
|
||||
*
|
||||
* Notes (cf. spec-back § 4.0.bis, contrat JSON capture en ERP-203) :
|
||||
* - `category` est embarque (objet, pas IRI) ; idem `sites` / `storageTypes`
|
||||
* (tableaux d'objets bornes). On n'a besoin que de `category.name` en liste.
|
||||
* - `states` est un tableau de chaines (PURCHASE / SALE / OTHER).
|
||||
* - `skip_null_values` actif cote back : ne pas presumer la presence des nulls.
|
||||
*/
|
||||
|
||||
/** Type de categorie embarque dans `category.categoryTypes` (RG-6.05). */
|
||||
export interface ProductCategoryType {
|
||||
id: number
|
||||
code: string
|
||||
label: string
|
||||
}
|
||||
|
||||
/** Categorie embarquee dans un produit (lecture seule, sous-ensemble utile au front). */
|
||||
export interface ProductCategory {
|
||||
id: number
|
||||
name: string
|
||||
code: string
|
||||
categoryTypes?: ProductCategoryType[]
|
||||
}
|
||||
|
||||
/** Site de disponibilite embarque dans un produit (groupe `site:read`). */
|
||||
export interface ProductSite {
|
||||
id: number
|
||||
name: string
|
||||
code: string
|
||||
postalCode: string
|
||||
city: string
|
||||
color: string
|
||||
fullAddress: string
|
||||
}
|
||||
|
||||
/** Type de stockage embarque dans un produit (referentiel borne, § 2.4). */
|
||||
export interface ProductStorageType {
|
||||
id: number
|
||||
code: string
|
||||
label: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Produit metier — tel qu'il est lu depuis l'API. L'entite porte le pattern
|
||||
* Timestampable+Blamable (cf. spec-back § 2.8).
|
||||
*/
|
||||
export interface Product {
|
||||
id: number
|
||||
code: string
|
||||
name: string
|
||||
/** Etats : sous-ensemble de PURCHASE / SALE / OTHER (RG-6.02). */
|
||||
states: string[]
|
||||
manufactured: boolean
|
||||
containsMolasses: boolean
|
||||
category: ProductCategory | null
|
||||
sites: ProductSite[]
|
||||
storageTypes: ProductStorageType[]
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { useWeighingTicketReferentials } from '../useWeighingTicketReferentials'
|
||||
|
||||
const mockApiGet = vi.hoisted(() => vi.fn())
|
||||
vi.stubGlobal('useApi', () => ({ get: mockApiGet }))
|
||||
|
||||
/**
|
||||
* Tests des référentiels Client/Fournisseur de l'écran ticket de pesée (M5).
|
||||
* Contrat couvert (ERP-208) : `load(siteId)` filtre les deux endpoints par site
|
||||
* courant via `siteId[]` ; sans site → listes complètes (param absent).
|
||||
*/
|
||||
describe('useWeighingTicketReferentials', () => {
|
||||
beforeEach(() => {
|
||||
mockApiGet.mockReset()
|
||||
mockApiGet.mockResolvedValue({ member: [] })
|
||||
})
|
||||
|
||||
it('passe siteId[] aux deux endpoints quand un site courant est fourni', async () => {
|
||||
const { load } = useWeighingTicketReferentials()
|
||||
await load(7)
|
||||
|
||||
const clientsCall = mockApiGet.mock.calls.find(c => c[0] === '/clients')
|
||||
const suppliersCall = mockApiGet.mock.calls.find(c => c[0] === '/suppliers')
|
||||
expect(clientsCall?.[1]).toMatchObject({ pagination: 'false', 'siteId[]': [7] })
|
||||
expect(suppliersCall?.[1]).toMatchObject({ pagination: 'false', 'siteId[]': [7] })
|
||||
})
|
||||
|
||||
it('ne passe pas siteId[] quand aucun site (liste complète)', async () => {
|
||||
const { load } = useWeighingTicketReferentials()
|
||||
await load(null)
|
||||
|
||||
const clientsCall = mockApiGet.mock.calls.find(c => c[0] === '/clients')
|
||||
expect(clientsCall?.[1]).not.toHaveProperty('siteId[]')
|
||||
expect(clientsCall?.[1]).toMatchObject({ pagination: 'false' })
|
||||
})
|
||||
|
||||
it('mappe les membres Hydra en options { value: @id, label: companyName }', async () => {
|
||||
mockApiGet.mockResolvedValue({ member: [{ '@id': '/api/clients/3', companyName: 'ACME' }] })
|
||||
const { load, clients } = useWeighingTicketReferentials()
|
||||
await load(7)
|
||||
|
||||
expect(clients.value).toEqual([{ value: '/api/clients/3', label: 'ACME' }])
|
||||
})
|
||||
})
|
||||
@@ -32,11 +32,19 @@ export function useWeighingTicketReferentials() {
|
||||
const clients = ref<RefOption[]>([])
|
||||
const suppliers = ref<RefOption[]>([])
|
||||
|
||||
/** Récupère une collection complète (pagination désactivée) en Hydra. */
|
||||
async function fetchAll(url: string): Promise<PartyMember[]> {
|
||||
/**
|
||||
* Récupère une collection complète (pagination désactivée) en Hydra. Filtre par
|
||||
* site courant si `siteId` est fourni (ERP-208) : un tiers est rattaché à un site
|
||||
* via les sites de ses adresses — param `siteId[]` déjà géré par les providers M1/M2.
|
||||
*/
|
||||
async function fetchAll(url: string, siteId?: number | null): Promise<PartyMember[]> {
|
||||
const query: Record<string, unknown> = { pagination: 'false' }
|
||||
if (siteId !== null && siteId !== undefined) {
|
||||
query['siteId[]'] = [siteId]
|
||||
}
|
||||
const res = await api.get<{ member?: PartyMember[] }>(
|
||||
url,
|
||||
{ pagination: 'false' },
|
||||
query,
|
||||
{ headers: LD_JSON_HEADERS, toast: false },
|
||||
)
|
||||
return res.member ?? []
|
||||
@@ -45,14 +53,15 @@ export function useWeighingTicketReferentials() {
|
||||
/**
|
||||
* Charge en parallèle clients + fournisseurs (résilient : un référentiel en
|
||||
* échec — ex. 403 selon le rôle — laisse simplement son select vide sans
|
||||
* faire échouer l'autre).
|
||||
* faire échouer l'autre). `siteId` (site courant) filtre les listes par site
|
||||
* (ERP-208) ; absent → listes complètes.
|
||||
*/
|
||||
async function load(): Promise<void> {
|
||||
async function load(siteId?: number | null): Promise<void> {
|
||||
await Promise.allSettled([
|
||||
fetchAll('/clients').then((list) => {
|
||||
fetchAll('/clients', siteId).then((list) => {
|
||||
clients.value = list.map(c => ({ value: c['@id'], label: c.companyName }))
|
||||
}),
|
||||
fetchAll('/suppliers').then((list) => {
|
||||
fetchAll('/suppliers', siteId).then((list) => {
|
||||
suppliers.value = list.map(s => ({ value: s['@id'], label: s.companyName }))
|
||||
}),
|
||||
])
|
||||
|
||||
@@ -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' }),
|
||||
@@ -100,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 () => {
|
||||
@@ -107,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 ».
|
||||
|
||||
@@ -7,9 +7,10 @@ const mockPost = 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/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' }),
|
||||
@@ -23,6 +24,8 @@ 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) : id 7 → les référentiels doivent être chargés filtrés sur ce site.
|
||||
vi.stubGlobal('useCurrentSite', () => ({ currentSite: ref({ id: 7, name: 'Site 7', color: '#000000' }) }))
|
||||
globalThis.open = mockOpen
|
||||
|
||||
const NewPage = (await import('../weighing-tickets/new.vue')).default
|
||||
@@ -70,6 +73,12 @@ describe('Écran Ajouter ticket de pesée (page /weighing-tickets/new)', () => {
|
||||
mockPatch.mockReset().mockResolvedValue({})
|
||||
mockPush.mockReset()
|
||||
mockOpen.mockReset()
|
||||
mockRefLoad.mockReset().mockResolvedValue(undefined)
|
||||
})
|
||||
|
||||
it('charge les référentiels filtrés sur le site courant au montage (ERP-208)', async () => {
|
||||
await mountPage()
|
||||
expect(mockRefLoad).toHaveBeenCalledWith(7)
|
||||
})
|
||||
|
||||
it('un seul bouton « Valider » (pas de « Enregistrer » séparé)', async () => {
|
||||
|
||||
@@ -189,7 +189,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 { 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,12 +404,34 @@ function printTicket(): void {
|
||||
window.open(`/api/weighing_tickets/${ticketId}/print.pdf`, '_blank')
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
*/
|
||||
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 })
|
||||
}
|
||||
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 () => {
|
||||
referentials.load().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
|
||||
|
||||
@@ -176,7 +176,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref, watch } 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'
|
||||
@@ -375,7 +375,28 @@ async function submitValidate(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
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).
|
||||
*/
|
||||
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
|
||||
}
|
||||
if (form.supplierIri.value && !referentials.suppliers.value.some(o => o.value === form.supplierIri.value)) {
|
||||
form.supplierIri.value = null
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
referentials.load().catch(() => {})
|
||||
reloadReferentials(currentSite.value?.id ?? null).catch(() => {})
|
||||
})
|
||||
|
||||
// Changement de site pendant la saisie → recharge les listes du nouveau site (ERP-208).
|
||||
watch(() => currentSite.value?.id, (siteId) => {
|
||||
reloadReferentials(siteId ?? null).catch(() => {})
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -175,6 +175,15 @@ class WeighingTicket implements TimestampableInterface, BlamableInterface
|
||||
/** Valide : contrepartie + immatriculation + 2 pesees OK, numero attribue (« Terminée »). */
|
||||
public const string STATUS_VALIDATED = 'VALIDATED';
|
||||
|
||||
/** Contrepartie « Client » (M1) — RG-5.03. */
|
||||
public const string COUNTERPARTY_CLIENT = 'CLIENT';
|
||||
|
||||
/** Contrepartie « Fournisseur » (M2) — RG-5.03. */
|
||||
public const string COUNTERPARTY_FOURNISSEUR = 'FOURNISSEUR';
|
||||
|
||||
/** Contrepartie « Autre » (libelle libre) — RG-5.03. */
|
||||
public const string COUNTERPARTY_AUTRE = 'AUTRE';
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
@@ -195,7 +204,7 @@ class WeighingTicket implements TimestampableInterface, BlamableInterface
|
||||
/** CLIENT | FOURNISSEUR | AUTRE (RG-5.03) — null tant que brouillon, requis a la validation. Pilote le champ associe obligatoire. */
|
||||
#[ORM\Column(name: 'counterparty_type', length: 12, nullable: true)]
|
||||
#[Assert\NotBlank(message: 'La contrepartie (Client / Fournisseur / Autre) est obligatoire.', groups: ['finalize'])]
|
||||
#[Assert\Choice(choices: ['CLIENT', 'FOURNISSEUR', 'AUTRE'], message: 'Type de contrepartie invalide.')]
|
||||
#[Assert\Choice(choices: [self::COUNTERPARTY_CLIENT, self::COUNTERPARTY_FOURNISSEUR, self::COUNTERPARTY_AUTRE], message: 'Type de contrepartie invalide.')]
|
||||
#[Groups(['weighing_ticket:read', 'weighing_ticket:write'])]
|
||||
private ?string $counterpartyType = null;
|
||||
|
||||
@@ -313,7 +322,7 @@ class WeighingTicket implements TimestampableInterface, BlamableInterface
|
||||
public function validateCounterpartyConsistency(ExecutionContextInterface $context): void
|
||||
{
|
||||
switch ($this->counterpartyType) {
|
||||
case 'CLIENT':
|
||||
case self::COUNTERPARTY_CLIENT:
|
||||
if (null === $this->client) {
|
||||
$context->buildViolation('Le client est obligatoire pour une contrepartie « Client ».')
|
||||
->atPath('client')
|
||||
@@ -323,7 +332,7 @@ class WeighingTicket implements TimestampableInterface, BlamableInterface
|
||||
|
||||
break;
|
||||
|
||||
case 'FOURNISSEUR':
|
||||
case self::COUNTERPARTY_FOURNISSEUR:
|
||||
if (null === $this->supplier) {
|
||||
$context->buildViolation('Le fournisseur est obligatoire pour une contrepartie « Fournisseur ».')
|
||||
->atPath('supplier')
|
||||
@@ -333,7 +342,7 @@ class WeighingTicket implements TimestampableInterface, BlamableInterface
|
||||
|
||||
break;
|
||||
|
||||
case 'AUTRE':
|
||||
case self::COUNTERPARTY_AUTRE:
|
||||
if (null === $this->otherLabel || '' === trim($this->otherLabel)) {
|
||||
$context->buildViolation('Le libellé est obligatoire pour une contrepartie « Autre ».')
|
||||
->atPath('otherLabel')
|
||||
@@ -458,6 +467,21 @@ class WeighingTicket implements TimestampableInterface, BlamableInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nom du tiers à afficher (cartouche du bon de pesée PDF, ERP-208) : raison
|
||||
* sociale du client/fournisseur ou libellé libre selon le type de contrepartie
|
||||
* (RG-5.03). Null si aucune contrepartie cohérente (brouillon).
|
||||
*/
|
||||
public function getCounterpartyName(): ?string
|
||||
{
|
||||
return match ($this->counterpartyType) {
|
||||
self::COUNTERPARTY_CLIENT => $this->client?->getCompanyName(),
|
||||
self::COUNTERPARTY_FOURNISSEUR => $this->supplier?->getCompanyName(),
|
||||
self::COUNTERPARTY_AUTRE => $this->otherLabel,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
public function getImmatriculation(): ?string
|
||||
{
|
||||
return $this->immatriculation;
|
||||
|
||||
@@ -27,6 +27,19 @@
|
||||
.company-name { font-weight: bold; font-size: 12px; }
|
||||
.company-line { font-size: 12px; }
|
||||
|
||||
/* En-tête 2 colonnes (Dompdf = CSS 2.1, pas de flex/grid) : identité
|
||||
société à gauche, cartouche du tiers à droite (ERP-208). Largeurs
|
||||
fixes par cellule + cartouche en bloc (pas d'inline-block/min-width,
|
||||
mal supportés par Dompdf) : le cartouche occupe la colonne de droite
|
||||
et un nom long passe à la ligne au lieu de déborder. */
|
||||
.header { width: 100%; border-collapse: collapse; }
|
||||
.header td { vertical-align: top; }
|
||||
.header .h-left { width: 62%; }
|
||||
.header .h-right { width: 38%; }
|
||||
.party-box { border: 1px solid #000; padding: 8px 12px; }
|
||||
.party-label { font-weight: bold; font-size: 14px; margin-bottom: 4px; }
|
||||
.party-name { font-size: 11px; word-wrap: break-word; }
|
||||
|
||||
.title { font-size: 22px; font-weight: bold; margin: 22px 0 18px; }
|
||||
|
||||
/* Lignes des deux pesées : tableau sans bordure, colonnes alignées. */
|
||||
@@ -41,13 +54,34 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
{% if logoSrc %}
|
||||
<div class="logo"><img src="{{ logoSrc }}" alt="LPC LIOT"></div>
|
||||
{% endif %}
|
||||
{# Libellé FR du type de contrepartie (couche de rendu, pas le Domain — ERP-208). #}
|
||||
{% set counterpartyLabels = { 'CLIENT': 'Client', 'FOURNISSEUR': 'Fournisseur', 'AUTRE': 'Autre' } %}
|
||||
|
||||
<div class="company-name">SA LIOT Châtellerault</div>
|
||||
<div class="company-line">Email : lpc.contacts@lpc-liot.fr</div>
|
||||
<div class="company-line">RCS Châtellerault B 339 505 612</div>
|
||||
<table class="header">
|
||||
<tr>
|
||||
<td class="h-left">
|
||||
{% if logoSrc %}
|
||||
<div class="logo"><img src="{{ logoSrc }}" alt="LPC LIOT"></div>
|
||||
{% endif %}
|
||||
<div class="company-name">SA LIOT Châtellerault</div>
|
||||
<div class="company-line">Email : lpc.contacts@lpc-liot.fr</div>
|
||||
<div class="company-line">RCS Châtellerault B 339 505 612</div>
|
||||
</td>
|
||||
{# Cartouche tiers (ERP-208) : type (libellé) + nom du client / fournisseur /
|
||||
« autre ». Conditionné sur le TYPE : un brouillon sans type n'affiche rien ;
|
||||
un type sans nom (cas limite) affiche au moins le libellé. #}
|
||||
<td class="h-right">
|
||||
{% if ticket.counterpartyType %}
|
||||
<div class="party-box">
|
||||
<div class="party-label">{{ counterpartyLabels[ticket.counterpartyType] ?? ticket.counterpartyType }} :</div>
|
||||
{% if ticket.counterpartyName %}
|
||||
<div class="party-name">{{ ticket.counterpartyName }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div class="title">Ticket de pesée</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Module\Logistique\Domain;
|
||||
|
||||
use App\Module\Commercial\Domain\Entity\Client;
|
||||
use App\Module\Commercial\Domain\Entity\Supplier;
|
||||
use App\Module\Logistique\Domain\Entity\WeighingTicket;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Couvre WeighingTicket::getCounterpartyName() (ERP-208) : nom du tiers affiché
|
||||
* dans le cartouche du bon de pesée selon le type de contrepartie (RG-5.03).
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class WeighingTicketCounterpartyNameTest extends TestCase
|
||||
{
|
||||
public function testReturnsClientCompanyNameForClientCounterparty(): void
|
||||
{
|
||||
$client = new Client()->setCompanyName('Ferme du Pré');
|
||||
$ticket = new WeighingTicket()->setCounterpartyType('CLIENT')->setClient($client);
|
||||
|
||||
self::assertSame('Ferme du Pré', $ticket->getCounterpartyName());
|
||||
}
|
||||
|
||||
public function testReturnsSupplierCompanyNameForSupplierCounterparty(): void
|
||||
{
|
||||
$supplier = new Supplier()->setCompanyName('Coop Sud');
|
||||
$ticket = new WeighingTicket()->setCounterpartyType('FOURNISSEUR')->setSupplier($supplier);
|
||||
|
||||
self::assertSame('Coop Sud', $ticket->getCounterpartyName());
|
||||
}
|
||||
|
||||
public function testReturnsOtherLabelForOtherCounterparty(): void
|
||||
{
|
||||
$ticket = new WeighingTicket()->setCounterpartyType('AUTRE')->setOtherLabel('Particulier');
|
||||
|
||||
self::assertSame('Particulier', $ticket->getCounterpartyName());
|
||||
}
|
||||
|
||||
public function testReturnsNullWhenNoCounterparty(): void
|
||||
{
|
||||
self::assertNull(new WeighingTicket()->getCounterpartyName());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user