diff --git a/frontend/components/reception/update-weight.vue b/frontend/components/reception/update-weight.vue
index 7fa5d20..b9acf6b 100644
--- a/frontend/components/reception/update-weight.vue
+++ b/frontend/components/reception/update-weight.vue
@@ -4,29 +4,23 @@
-
-
@@ -64,13 +58,38 @@ const form = reactive({
{id: 0, type: 'gross' as const, weight: 0, dsd: null, weighedAt: null}
]
})
+// DSD et date de pesée sont partagés entre tare et gross dans l'UI.
+const sharedWeightMeta = reactive<{
+ dsd: number | string | null
+ weighedAt: string | null
+}>({
+ dsd: null,
+ weighedAt: null
+})
+
+const getWeightLabel = (type: 'tare' | 'gross'): string => {
+ return type === 'tare' ? 'Pesée à vide' : 'Pesée à plein'
+}
const hydrateFromReception = (reception: ReceptionFormWeight) => {
- const tare = reception.weights.find(weight => weight.type === 'tare')
- const gross = reception.weights.find(weight => weight.type === 'gross')
+ // On hydrate chaque ligne par son type (tare/gross), sans dépendre d'un index.
+ for (const receptionWeight of reception.weights) {
+ const formWeight = form.weights.find(weight => weight.type === receptionWeight.type)
+ if (formWeight) {
+ Object.assign(formWeight, receptionWeight)
+ }
+ }
- if (tare) form.weights[0] = {...form.weights[0], ...tare}
- if (gross) form.weights[1] = {...form.weights[1], ...gross}
+ // On récupère une valeur existante pour préremplir les champs partagés.
+ const weightWithMeta = reception.weights.find(weight =>
+ (weight.dsd !== null && weight.dsd !== undefined)
+ || (weight.weighedAt !== null && weight.weighedAt !== undefined && weight.weighedAt !== '')
+ )
+
+ if (weightWithMeta) {
+ sharedWeightMeta.dsd = weightWithMeta.dsd ?? null
+ sharedWeightMeta.weighedAt = weightWithMeta.weighedAt ?? null
+ }
}
onMounted(async () => {
@@ -80,14 +99,13 @@ onMounted(async () => {
async function validate() {
const sharedDsd =
- form.weights[0].dsd === null || form.weights[0].dsd === undefined || form.weights[0].dsd === ''
+ sharedWeightMeta.dsd === null || sharedWeightMeta.dsd === undefined || sharedWeightMeta.dsd === ''
? null
- : Number(form.weights[0].dsd)
+ : Number(sharedWeightMeta.dsd)
const sharedWeighedAt =
- form.weights[0].weighedAt === null || form.weights[0].weighedAt === undefined || form.weights[0].weighedAt === ''
+ sharedWeightMeta.weighedAt === null || sharedWeightMeta.weighedAt === undefined || sharedWeightMeta.weighedAt === ''
? null
- : form.weights[0].weighedAt
-
+ : sharedWeightMeta.weighedAt
for (const weight of form.weights) {
if (weight.id) {
await updateWeight(weight.id, {
diff --git a/frontend/services/dto/weight-data.ts b/frontend/services/dto/weight-data.ts
index d4af0a1..2349a1d 100644
--- a/frontend/services/dto/weight-data.ts
+++ b/frontend/services/dto/weight-data.ts
@@ -2,4 +2,5 @@ export interface WeightData {
weight: number | null
dsd: number | null
weighedAt: string | null
+ type : string | null
}
diff --git a/src/Entity/Supplier.php b/src/Entity/Supplier.php
index 6ed64da..1fe346a 100644
--- a/src/Entity/Supplier.php
+++ b/src/Entity/Supplier.php
@@ -26,7 +26,7 @@ use Symfony\Component\Serializer\Attribute\Groups;
),
new GetCollection(
normalizationContext: ['groups' => ['supplier:read']],
- security: "is_granted('ROLE_USER')"
+ security: "is_granted('ROLE_ADMIN')"
),
new Post(
normalizationContext: ['groups' => ['supplier:read']],