feat(receipt-import): add function to ignore specific receipt names and filter out ignored items
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -32,6 +32,22 @@ function tokenize(value: string): string[] {
|
||||
.filter((w) => w.length >= 3);
|
||||
}
|
||||
|
||||
function isIgnoredReceiptName(value: string | null | undefined): boolean {
|
||||
const normalized = (value ?? '').trim().toLowerCase();
|
||||
if (!normalized) return false;
|
||||
|
||||
if (/^rabatt\b/.test(normalized)) return true;
|
||||
if (/^summa\b/.test(normalized)) return true;
|
||||
if (/^moms\b/.test(normalized)) return true;
|
||||
if (/^pant\b/.test(normalized)) return true;
|
||||
if (/^att\s+betala\b/.test(normalized)) return true;
|
||||
if (/^totalt\b/.test(normalized)) return true;
|
||||
if (/^kort\b/.test(normalized)) return true;
|
||||
if (/^kontant\b/.test(normalized)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function normalizeToken(s: string): string {
|
||||
return s.replace(/å/g, 'a').replace(/ä/g, 'a').replace(/ö/g, 'o').replace(/é/g, 'e').replace(/è/g, 'e');
|
||||
}
|
||||
@@ -177,7 +193,8 @@ export class ReceiptImportService {
|
||||
throw new BadRequestException(message);
|
||||
}
|
||||
|
||||
return response.json() as Promise<ParsedReceiptItem[]>;
|
||||
const items = (await response.json()) as ParsedReceiptItem[];
|
||||
return items.filter((item) => !isIgnoredReceiptName(item.rawName));
|
||||
}
|
||||
|
||||
private async matchProducts(
|
||||
|
||||
Reference in New Issue
Block a user