feat: add rematch functionality for recipe ingredients and enhance inventory management
Test Suite / test (24.15.0) (push) Has been cancelled

- Added a new API path for rematching recipe ingredients in `api_paths.dart`.
- Implemented a manual product creation dialog in `inventory_screen.dart` to allow users to create new products directly.
- Integrated the rematch functionality in `recipe_repository.dart` to handle rematching of recipe ingredients.
- Updated the recipe detail screen to include a button for triggering the rematch process.
- Introduced a new `RecipeMatchingService` in the backend to handle ingredient matching logic.
- Added database migration to include `aiEngineEnabled` column in the User table.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Nils-Johan Gynther
2026-05-06 09:20:31 +02:00
parent 9fe85a719c
commit 04b1fc3024
53 changed files with 1420 additions and 652 deletions
+16 -5
View File
@@ -141,7 +141,7 @@ let ReceiptImportService = ReceiptImportService_1 = class ReceiptImportService {
async parseReceipt(file, _isPremium = false, userId) {
const rawItems = await this.parseReceiptViaImporter(file);
const matched = await this.matchProducts(rawItems, userId);
return this.enrichWithAiCategories(matched);
return this.enrichWithAiCategories(matched, userId);
}
async parseReceiptViaImporter(file) {
const form = new FormData();
@@ -283,7 +283,7 @@ let ReceiptImportService = ReceiptImportService_1 = class ReceiptImportService {
}
return best?.product;
}
async enrichWithAiCategories(items) {
async enrichWithAiCategories(items, userId) {
let categories;
try {
categories = await this.categoriesService.findFlattened();
@@ -291,6 +291,12 @@ let ReceiptImportService = ReceiptImportService_1 = class ReceiptImportService {
catch {
return items;
}
const user = userId
? await this.prisma.user.findUnique({
where: { id: userId },
select: { aiEngineEnabled: true },
})
: null;
const enriched = [];
for (const item of items) {
if (!item.rawName) {
@@ -347,9 +353,14 @@ let ReceiptImportService = ReceiptImportService_1 = class ReceiptImportService {
pushTrace(`rule fallback applied -> "${byRule.path}"`);
}
if (!nextSuggestion) {
pushTrace('ai invoked');
nextSuggestion = await this.aiService.suggestCategory(item.rawName, categories);
pushTrace(`ai result -> "${nextSuggestion.path}" (${nextSuggestion.confidence})`);
if (user?.aiEngineEnabled) {
pushTrace('ai invoked');
nextSuggestion = await this.aiService.suggestCategory(item.rawName, categories);
pushTrace(`ai result -> "${nextSuggestion.path}" (${nextSuggestion.confidence})`);
}
else {
pushTrace('ai skipped, feature disabled');
}
}
else {
pushTrace(`ai skipped, current -> "${nextSuggestion.path}"`);
File diff suppressed because one or more lines are too long