Add/docs skv mcp (#494)

* feat: add "book directly" functionality for invoice inbox items

- Extend JournalEntrySourceTypeSchema to include 'inbox_item'.
- Introduce BookInboxItemDirectlySchema for direct journal entry creation.
- Update InvoiceInboxItem type to include matched_transaction_id and created_journal_entry_id.
- Implement BookDirectlyDialog component for user interaction.
- Create API route for booking directly from inbox items with appropriate validations.
- Add SQL migration to support new journal entry references in the invoice inbox items table.
- Implement tests for the new booking functionality and ensure proper error handling.

* fix(invoice-inbox): update status handling for resolved inbox items

* feat: enforce unique journal entry constraint for invoice inbox items
This commit is contained in:
Mattsson
2026-05-15 00:49:59 +02:00
committed by GitHub
parent 523a8650cc
commit b0890c7c79
9 changed files with 1271 additions and 10 deletions
@@ -0,0 +1,17 @@
-- Invoice inbox: support "book directly" flow for kontantmetoden users.
--
-- Cash-method users (and accrual users dealing with personal expenses,
-- cash receipts, etc.) need to be able to turn an inbox item directly
-- into a manual journal entry without going through a supplier invoice.
-- This column gives the inbox the third terminal status, symmetric with
-- `created_supplier_invoice_id` and `matched_transaction_id`.
ALTER TABLE public.invoice_inbox_items
ADD COLUMN IF NOT EXISTS created_journal_entry_id uuid
REFERENCES public.journal_entries(id) ON DELETE SET NULL;
CREATE INDEX IF NOT EXISTS idx_inbox_items_created_journal_entry
ON public.invoice_inbox_items(company_id, created_journal_entry_id)
WHERE created_journal_entry_id IS NOT NULL;
NOTIFY pgrst, 'reload schema';
@@ -0,0 +1,17 @@
-- Invoice inbox: enforce one journal entry per inbox item.
--
-- The book-direct route does a check-then-write (409 guard on
-- created_journal_entry_id, then createJournalEntry, then update).
-- Without a UNIQUE constraint, two concurrent calls for the same
-- inbox item can both pass the guard, both insert a journal entry,
-- and the second update overwrites the FK — orphaning the first
-- entry in an immutable ledger with no inbox reference.
--
-- PostgreSQL treats NULLs as distinct in UNIQUE constraints by
-- default, so unbooked items (NULL) remain unconstrained.
ALTER TABLE public.invoice_inbox_items
ADD CONSTRAINT invoice_inbox_items_journal_entry_unique
UNIQUE (created_journal_entry_id);
NOTIFY pgrst, 'reload schema';