fix: appliquer les règles d'automatisation (ventilation) lors de l'import email
This commit is contained in:
@@ -13,6 +13,7 @@ import { extractInvoicesWithMistral, generateMetadataJSON } from "./invoiceExtra
|
||||
import { localStoragePut, generateStorageKey } from "./localStorage";
|
||||
import { sendImportNotification } from "./notificationService";
|
||||
import { getOffice365ImapToken, buildXOAuth2String } from "./office365OAuth";
|
||||
import { applyAutomationRules } from "./automationEngine";
|
||||
|
||||
interface EmailImportConfig {
|
||||
userId: number;
|
||||
@@ -155,7 +156,7 @@ async function processEmailAttachment(
|
||||
);
|
||||
|
||||
// Create invoice record
|
||||
await createInvoice({
|
||||
const newInvoice = await createInvoice({
|
||||
userId,
|
||||
sourceFileId: sourceFile.id,
|
||||
invoiceIndexInFile: i + 1,
|
||||
@@ -177,6 +178,18 @@ async function processEmailAttachment(
|
||||
status: "completed",
|
||||
});
|
||||
|
||||
// Apply automation rules (ventilation, typeAchat, serviceConcerne)
|
||||
try {
|
||||
const { updateInvoice } = await import("./db");
|
||||
const automationUpdates = await applyAutomationRules(userId, newInvoice);
|
||||
if (Object.keys(automationUpdates).length > 0) {
|
||||
await updateInvoice(newInvoice.id, automationUpdates);
|
||||
console.log(`[EmailImport] Automation rules applied to invoice ${newInvoice.id}: ${Object.keys(automationUpdates).join(', ')}`);
|
||||
}
|
||||
} catch (autoError: any) {
|
||||
console.error(`[EmailImport] Error applying automation rules:`, autoError.message);
|
||||
}
|
||||
|
||||
importedCount++;
|
||||
} catch (error: any) {
|
||||
errorsCount++;
|
||||
|
||||
Reference in New Issue
Block a user