Supp/invoice bfl errors (#390)
* feat(accounting): update accounting method validation and messaging for aktiebolag and enskild firma * Remove AI subsystem and related code - Deleted AI proposals and requests persistence logic from `lib/ai/proposals/persist.ts`. - Removed re-validation logic for proposals in `lib/ai/proposals/re-validate.ts`. - Cleaned up schemas related to AI flows in `lib/api/schemas.ts`. - Removed AI-related fields from bookkeeping engine in `lib/bookkeeping/engine.ts`. - Eliminated AI event types from `lib/events/types.ts`. - Updated tests to reflect the removal of AI-related functionality in `lib/extensions/__tests__/sectors.test.ts`. - Adjusted initialization logic in `lib/init.ts` to exclude AI proposal handler registration. - Cleaned up transaction ingestion logic in `lib/transactions/ingest.ts` to remove AI flow checks. - Updated helper functions in `tests/helpers.ts` to remove AI-related settings. - Removed AI-related types and interfaces from `types/index.ts`. - Added migration script to drop AI-related tables and settings from the database. * fix(migrations): ensure foreign key constraint is dropped before removing AI tables * feat(invoice-inbox): implement deterministic invoice field extraction and inbox provisioning - Added `extract-invoice-fields.ts` for extracting fields from PDF invoices using regex and pdfjs-dist, replacing the previous AI classifier. - Introduced `inbox-provisioning.ts` to manage company inbox addresses and rotation of inboxes using Supabase RPCs. - Created `resend-inbound.ts` for handling inbound email events and attachments via the Resend API. - Defined the extension manifest for the invoice inbox, specifying required environment variables and descriptions. - Migrated database schema to remove AI-related columns and tighten the status enum in `invoice_inbox_items`. * feat(invoice-inbox): remove AI-specific columns and tighten status enum * fix(skattekonto): remove manual entry creation reference from transaction input * fix(schemas): remove accounting method validation for aktiebolag in UpdateSettingsSchema
This commit is contained in:
@@ -404,8 +404,6 @@ describe('ingestTransactions', () => {
|
||||
enqueue({ data: [], error: null })
|
||||
// Transaction 1: insert OK
|
||||
enqueue({ data: inserted1, error: null })
|
||||
// AI flow flag lookup (lazy, fires once on first auto-categorize branch)
|
||||
enqueue({ data: { ai_flow_enabled: false }, error: null })
|
||||
// Transaction 2: insert OK
|
||||
enqueue({ data: inserted2, error: null })
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { SupabaseClient } from '@supabase/supabase-js'
|
||||
import { evaluateMappingRules } from '@/lib/bookkeeping/mapping-engine'
|
||||
import { createTransactionJournalEntry } from '@/lib/bookkeeping/transaction-entries'
|
||||
import { isAutoBookEnabled } from '@/lib/ai/feature-flag'
|
||||
import { upsertCounterpartyTemplate } from '@/lib/bookkeeping/counterparty-templates'
|
||||
import { getBestInvoiceMatch } from '@/lib/invoices/invoice-matching'
|
||||
import { findSupplierInvoiceMatch } from '@/lib/invoices/supplier-invoice-matching'
|
||||
@@ -119,28 +118,6 @@ export async function ingestTransactions(
|
||||
// by incoming enable_banking rows to avoid blocking unrelated CSV imports.
|
||||
const existingMaps = await buildExistingTransactionMaps(supabase, companyId, rawTransactions)
|
||||
|
||||
// AI agent gate: when the company has opted into the agent flow, every
|
||||
// uncategorized transaction becomes a review proposal — no silent auto-book.
|
||||
// Matching/suggestion still runs (it only sets potential_*_id fields), but
|
||||
// the mapping-rule auto-categorize branch below is disabled. Fetched lazily
|
||||
// the first time the auto-categorize branch is about to run, and cached for
|
||||
// the rest of the batch so we don't hit the DB per-transaction.
|
||||
let aiFlowEnabledCache: boolean | null = null
|
||||
const isAiFlowEnabled = async (): Promise<boolean> => {
|
||||
if (aiFlowEnabledCache !== null) return aiFlowEnabledCache
|
||||
try {
|
||||
const { data: aiSettings } = await supabase
|
||||
.from('company_settings')
|
||||
.select('ai_flow_enabled')
|
||||
.eq('company_id', companyId)
|
||||
.maybeSingle()
|
||||
aiFlowEnabledCache = Boolean(aiSettings?.ai_flow_enabled)
|
||||
} catch {
|
||||
aiFlowEnabledCache = false
|
||||
}
|
||||
return aiFlowEnabledCache
|
||||
}
|
||||
|
||||
// When rawInsertOnly is set (viewer imports), skip pre-fetching supplier
|
||||
// invoices and exchange rates — they are not used.
|
||||
let unpaidSupplierInvoices: SupplierInvoice[] = []
|
||||
@@ -363,12 +340,11 @@ export async function ingestTransactions(
|
||||
}
|
||||
|
||||
// 4. Evaluate mapping rules for auto-categorization
|
||||
// Production-disabled: auto-booking only runs in local dev (isAutoBookEnabled).
|
||||
// Production-disabled: auto-booking only runs in local dev (and tests).
|
||||
// Users must explicitly book each transaction on the deployed app.
|
||||
// Also skipped when the company has opted into the AI agent flow (proposals)
|
||||
// and when SIE-imported entries overlap the sync range (prevents double-book).
|
||||
// Reconciliation (step 2.5) still links transactions to existing GL lines.
|
||||
if (isAutoBookEnabled() && !options?.skipAutoCategorization && !(await isAiFlowEnabled())) {
|
||||
const autoBookEnabled = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'
|
||||
if (autoBookEnabled && !options?.skipAutoCategorization) {
|
||||
try {
|
||||
const mappingResult = await evaluateMappingRules(
|
||||
supabase,
|
||||
|
||||
Reference in New Issue
Block a user