From 6733a50cfbde5e7a8ca9941e6ec933ec4115494f Mon Sep 17 00:00:00 2001 From: Nils-Johan Gynther Date: Sat, 2 May 2026 20:32:50 +0200 Subject: [PATCH] fix(receipt-import): route egg items away from allergy dairy --- .../receipt-import/receipt-import.service.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/backend/src/receipt-import/receipt-import.service.ts b/backend/src/receipt-import/receipt-import.service.ts index c83462c3..7e6066c7 100644 --- a/backend/src/receipt-import/receipt-import.service.ts +++ b/backend/src/receipt-import/receipt-import.service.ts @@ -515,6 +515,28 @@ export class ReceiptImportService { if (fallbackHit) return fallbackHit; } + // ── Regel: Ägg (saknar egen L2/L3 i nuvarande träd) ──────────────── + const hasEggSignal = + /\bagg\b/.test(normalized) || + /\begg\b/.test(normalized) || + /\binne\b/.test(normalized) || + /\b24p\b/.test(normalized); + + if (hasEggSignal) { + const l1DairyEgg = categories.find( + (c) => c.path.toLowerCase() === 'mejeri, ost & ägg', + ); + if (l1DairyEgg) { + return { + categoryId: l1DairyEgg.id, + categoryName: l1DairyEgg.name, + path: l1DairyEgg.path, + confidence: 'high', + usedFallback: false, + }; + } + } + // ── Regel: Te ──────────────────────────────────────────────────────── const isTea = /\bte\b/.test(normalized) || @@ -693,6 +715,30 @@ export class ReceiptImportService { } } + const hasEggSignal = + /\bagg\b/.test(normalized) || + /\begg\b/.test(normalized) || + /\binne\b/.test(normalized) || + /\b24p\b/.test(normalized); + + if (hasEggSignal && suggestion.path.toLowerCase().includes('allergi mejeri')) { + const l1DairyEgg = categories.find( + (c) => c.path.toLowerCase() === 'mejeri, ost & ägg', + ); + if (l1DairyEgg) { + this.logger.log( + `AI contradiction-guard: "${rawName}" remappas från "${suggestion.path}" till "${l1DairyEgg.path}"`, + ); + return { + categoryId: l1DairyEgg.id, + categoryName: l1DairyEgg.name, + path: l1DairyEgg.path, + confidence: 'high', + usedFallback: true, + }; + } + } + const hasCreamSignal = /\bvispgradde\b/.test(normalized) || /\bmatlagningsgradde\b/.test(normalized) ||