feat: implement user-scoped receipt aliases with global fallback; enhance alias management in admin panel
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
This commit is contained in:
@@ -463,10 +463,13 @@ class _ReceiptImportTabState extends ConsumerState<ReceiptImportTab> {
|
||||
int merged = 0;
|
||||
int pantryAdded = 0;
|
||||
int pantrySkipped = 0;
|
||||
int aliasesLearned = 0;
|
||||
try {
|
||||
final token = await ref.read(authStateProvider.future);
|
||||
final invRepo = ref.read(inventoryRepositoryProvider);
|
||||
final pantryRepo = ref.read(pantryRepositoryProvider);
|
||||
final adminRepo = ref.read(adminRepositoryProvider);
|
||||
final canManageAliases = ref.read(isAdminProvider);
|
||||
|
||||
for (final i in toAdd) {
|
||||
final edit = _edits[i]!;
|
||||
@@ -514,6 +517,24 @@ class _ReceiptImportTabState extends ConsumerState<ReceiptImportTab> {
|
||||
created++;
|
||||
}
|
||||
}
|
||||
|
||||
final normalizedReceiptName = item.rawName.trim().toLowerCase();
|
||||
final shouldLearnAlias =
|
||||
canManageAliases &&
|
||||
normalizedReceiptName.isNotEmpty &&
|
||||
item.matchedProductId != pid;
|
||||
if (shouldLearnAlias) {
|
||||
try {
|
||||
await adminRepo.upsertReceiptAlias(
|
||||
receiptName: normalizedReceiptName,
|
||||
productId: pid,
|
||||
);
|
||||
aliasesLearned++;
|
||||
} catch (e, st) {
|
||||
debugPrint('ReceiptImportTab alias upsert failed: $e');
|
||||
debugPrintStack(stackTrace: st);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
@@ -522,6 +543,7 @@ class _ReceiptImportTabState extends ConsumerState<ReceiptImportTab> {
|
||||
if (merged > 0) '$merged ${merged == 1 ? 'sammanslagen' : 'sammanslagna'} i inventarie',
|
||||
if (pantryAdded > 0) '$pantryAdded tillagd${pantryAdded == 1 ? '' : 'a'} i baslager',
|
||||
if (pantrySkipped > 0) '$pantrySkipped fanns redan i baslager',
|
||||
if (aliasesLearned > 0) '$aliasesLearned alias inlärda',
|
||||
];
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(parts.join(', ') + '.')),
|
||||
|
||||
Reference in New Issue
Block a user