feat: add unit mapping functionality and confirmation dialog for unit changes in import process
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:
@@ -215,7 +215,7 @@ export class ReceiptImportService {
|
||||
],
|
||||
}
|
||||
: { isGlobal: true };
|
||||
const [aliases, products] = await Promise.all([
|
||||
const [aliases, products, unitMappings] = await Promise.all([
|
||||
this.prisma.receiptAlias.findMany({
|
||||
where: aliasFilter,
|
||||
orderBy: [
|
||||
@@ -228,6 +228,10 @@ export class ReceiptImportService {
|
||||
where: productFilter,
|
||||
select: { id: true, name: true, canonicalName: true, categoryId: true, categoryRef: { select: { id: true, name: true } } },
|
||||
}),
|
||||
this.prisma.unitMapping.findMany({
|
||||
where: { userId: userId },
|
||||
select: { productId: true, originalUnit: true, preferredUnit: true },
|
||||
}),
|
||||
]);
|
||||
|
||||
return items.map((item) => {
|
||||
@@ -251,11 +255,17 @@ export class ReceiptImportService {
|
||||
if (!suggestion) {
|
||||
return { ...item };
|
||||
}
|
||||
|
||||
// Kontrollera om det finns en enhetsmappning för produkten och användaren
|
||||
const unitMapping = unitMappings.find((um) => um.productId === suggestion.id && um.originalUnit === item.unit);
|
||||
const preferredUnit = unitMapping ? unitMapping.preferredUnit : item.unit;
|
||||
|
||||
const cat = suggestion.categoryRef;
|
||||
return {
|
||||
...item,
|
||||
suggestedProductId: suggestion.id,
|
||||
suggestedProductName: suggestion.canonicalName ?? suggestion.name,
|
||||
unit: preferredUnit,
|
||||
...(cat ? { categorySuggestion: { categoryId: cat.id, categoryName: cat.name, path: cat.name, confidence: 'medium' as const, usedFallback: false } } : {}),
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user