From 09be89b5579776cd144ca266f1b05e87526d3ffd Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Wed, 18 Mar 2026 19:05:58 +0100 Subject: [PATCH] fix: query ventesProduits by codein array instead of code_fournisseur The old fournisseur code stored in ventesProduits may differ from the new API codefou (e.g. "AUXENCE" vs "A025"), causing zero results. Querying by codein = ANY(...) finds the classification data regardless of how the supplier was previously keyed. Co-Authored-By: Claude Sonnet 4.6 --- src/features/grid/api/get-product-rows.ts | 37 ++++++++++++----------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/features/grid/api/get-product-rows.ts b/src/features/grid/api/get-product-rows.ts index 134aba5..059a144 100644 --- a/src/features/grid/api/get-product-rows.ts +++ b/src/features/grid/api/get-product-rows.ts @@ -9,7 +9,7 @@ import { buildLast12MonthsRange, } from "@/lib/api-ff-client"; import { db } from "@/db"; -import { sessionSnapshots, ventesProduits } from "@/db/schema"; +import { sessionSnapshots } from "@/db/schema"; import { eq, desc, sql } from "drizzle-orm"; interface GetProductRowsInput { @@ -152,25 +152,28 @@ export async function getProductRows(input: GetProductRowsInput): Promise 0) { + const classifRows = await db.execute(sql` + SELECT DISTINCT ON (codein) + codein, code_gamme, code_gamme_init, code3, libelle3 + FROM ventes_produits + WHERE codein = ANY(${codeins}) + ORDER BY codein, updated_at DESC + `); + for (const row of classifRows.rows) { + const product = productMap.get(row.codein as string); + if (product) { + product.codeGamme = (row.code_gamme as string | null) ?? null; + product.codeGammeInit = (row.code_gamme_init as string | null) ?? null; + product.code3 = (row.code3 as string | null) ?? ""; + product.libelle3 = (row.libelle3 as string | null) ?? ""; + } } + console.log(`[getProductRows] Classification: ${classifRows.rows.length} lignes trouvées pour ${codeins.length} articles`); } - console.log(`[getProductRows] Classification chargée pour ${classifRows.rows.length} lignes`); } catch (classifErr) { console.warn("[getProductRows] ventesProduits classification non disponible:", classifErr); }