mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-11 17:26:32 +02:00
fix: use most recent artfou1 entry (no_id DESC) for supplier attribution
DISTINCT ON with ORDER BY no_id ASC was picking the oldest supplier entry (BAZAR 5000 historically), attributing CA to a supplier the store no longer uses. Changing to DESC picks the most recently inserted artfou1 row, which represents the current active supplier for each article. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
b420dc2a2b
commit
5436513e30
1 file changed
+3
-2
@@ -646,10 +646,11 @@ export async function pgGetCaByFournisseur(
|
||||
): Promise<CaByFournisseurRow[]> {
|
||||
const result = await pgNoParallel(sql`
|
||||
WITH art_fou AS (
|
||||
-- Un seul fournisseur par article (le plus ancien no_id = fournisseur principal)
|
||||
-- Un seul fournisseur par article : le plus récent (no_id DESC = entrée courante)
|
||||
-- no_id est une séquence croissante → DESC sélectionne le fournisseur actif actuel
|
||||
SELECT DISTINCT ON (art_no_id) art_no_id, code AS codefou
|
||||
FROM artfou1
|
||||
ORDER BY art_no_id, no_id
|
||||
ORDER BY art_no_id, no_id DESC
|
||||
)
|
||||
SELECT
|
||||
af.codefou AS code,
|
||||
|
||||
Reference in new issue
Block a user