feat: enhance ProductPickerField and ParsedReceiptItem to support category filtering in receipt import

This commit is contained in:
Nils-Johan Gynther
2026-05-01 02:05:53 +02:00
parent 47801935e9
commit 84dfbc4a52
4 changed files with 35 additions and 9 deletions
@@ -98,14 +98,16 @@ class _EditDialogState extends State<_EditDialog> {
_productName = item.suggestedProductName;
});
} else if (aiCategory != null) {
// Öppna pickern med råtexten från kvittot som sökord — kategorinamnet
// matchar inte produktnamn, men rawName gör det troligtvis
// Öppna pickern filtrerad på AI-föreslagen kategori (categoryId).
// Visar bara produkter i den kategorin (eller rawName-sökning om kategorin är tom).
final catId = item.categorySuggestionId;
ProductPickerField.showSheet(
context,
products: widget.products,
value: _productId,
label: 'Produkt',
initialQuery: item.rawName,
categoryFilter: catId != null ? {catId} : null,
).then((id) {
if (id != null && mounted) {
setState(() {
@@ -276,7 +278,7 @@ class _ReceiptImportTabState extends ConsumerState<ReceiptImportTab> {
setState(() {
_products = list
.cast<Map<String, dynamic>>()
.map((e) => (id: e['id'] as int, name: e['name'] as String))
.map((e) => (id: e['id'] as int, name: e['name'] as String, categoryId: (e['categoryId'] as num?)?.toInt()))
.toList();
_loadingProducts = false;
});