feat: enhance receipt import matching logic to include category path resolution and improve edit handling
Test Suite / test (24.15.0) (push) Has been cancelled

This commit is contained in:
Nils-Johan Gynther
2026-05-09 16:06:19 +02:00
parent b09ea28ff0
commit b121000bf7
@@ -299,16 +299,18 @@ class _ReceiptImportTabState extends ConsumerState<ReceiptImportTab> {
final it = items[i]; final it = items[i];
final pid = it.matchedProductId ?? it.suggestedProductId; final pid = it.matchedProductId ?? it.suggestedProductId;
nextSelected[i] = pid != null; nextSelected[i] = pid != null;
if (pid != null) {
final inferred = inferPackageFields( final inferred = inferPackageFields(
rawName: it.rawName, rawName: it.rawName,
quantity: it.quantity, quantity: it.quantity,
unit: it.unit, unit: it.unit,
); );
final name = it.matchedProductName ?? it.suggestedProductName; final name = it.matchedProductName ?? it.suggestedProductName;
final resolvedCategoryId = it.categorySuggestionId ?? _categoryIdForProduct(pid); final resolvedCategoryId =
final resolvedCategoryPath = it.categorySuggestionPath ?? it.categorySuggestionId ?? (pid != null ? _categoryIdForProduct(pid) : null);
_lookup.pathFor(resolvedCategoryId); final resolvedCategoryPath =
it.categorySuggestionPath ?? _lookup.pathFor(resolvedCategoryId);
if (pid != null || resolvedCategoryPath != null) {
nextEdits[i] = _ItemEdit( nextEdits[i] = _ItemEdit(
productId: pid, productId: pid,
productName: name, productName: name,
@@ -833,6 +835,7 @@ class _ReceiptImportResultRow extends ConsumerWidget {
); );
final theme = Theme.of(context); final theme = Theme.of(context);
final hasProduct = edit?.productId != null; final hasProduct = edit?.productId != null;
final categoryPath = edit?.categoryPath ?? item.categorySuggestionPath;
final isMatched = item.matchedProductId != null; final isMatched = item.matchedProductId != null;
final isSuggested = final isSuggested =
item.suggestedProductId != null && item.matchedProductId == null; item.suggestedProductId != null && item.matchedProductId == null;
@@ -946,10 +949,10 @@ class _ReceiptImportResultRow extends ConsumerWidget {
style: theme.textTheme.bodySmall style: theme.textTheme.bodySmall
?.copyWith(color: theme.colorScheme.tertiary), ?.copyWith(color: theme.colorScheme.tertiary),
), ),
if (hasProduct && edit?.categoryPath != null) ...[ if (categoryPath != null) ...[
const SizedBox(height: 2), const SizedBox(height: 2),
Text( Text(
'Kategori: ${edit!.categoryPath!}', '${hasProduct ? 'Kategori' : 'Kategoriförslag'}: $categoryPath',
style: theme.textTheme.bodySmall?.copyWith( style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant, color: theme.colorScheme.onSurfaceVariant,
), ),