feat(expenses): utlägg as an answer to "Vem betalade?" in Underlag, not a page (#2317)

An out-of-pocket purchase differs from any other receipt only in the
credit account, so the Underlag pane now asks one question for an
unmatched underlag (Företaget / Jag, privat / En anställd / Ingen ännu)
and books a privately paid receipt in place through POST
/api/expense-claims, replacing the "Andra sätt att bokföra" dropdown and
the deep link into the two-step wizard. The verifikat editor stays
reachable below as the escape hatch (BFL 5 kap 6-7 §).

The person owed surfaces in Att göra under a new Betala band, one row per
person (lib/worklist expense_payout, counted in the total and exposed to
agents through the attention resource). The Utlägg nav row is gated on
existing claims, the same hybrid gate as Körjournal, since the entry
point for a new utlägg is now the Underlag pane.


Claude-Session: https://claude.ai/code/session_01P8YsvPqjfGxGZUkGeBVUWQ

Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-09-05 15:57:14 +02:00
committed by GitHub
co-authored by Jakob Wennberg Claude Fable 5.1
parent bff44e5757
commit cbe5580886
17 changed files with 866 additions and 86 deletions
+15 -2
View File
@@ -12,6 +12,7 @@ vi.mock('../categories', () => ({
countDeadlinesNeedingAction: vi.fn().mockResolvedValue(1),
countPendingOperations: vi.fn().mockResolvedValue(2),
countReconciliationDue: vi.fn().mockResolvedValue(1),
countExpensePayoutsDue: vi.fn().mockResolvedValue(2),
}))
import { getWorklistCounts } from '../aggregate'
@@ -36,6 +37,7 @@ describe('getWorklistCounts', () => {
deadline_action: 1,
pending_operations: 2,
reconciliation_due: 1,
expense_payout: 2,
})
})
@@ -49,9 +51,20 @@ describe('getWorklistCounts', () => {
expect(countSuggestedMatches).not.toHaveBeenCalled()
})
it('takes the expense-payout count from a caller-supplied list instead of rescanning', async () => {
const { countExpensePayoutsDue } = await import('../categories')
const people = [{ key: 'owner:Anna' }, { key: 'emp-1' }, { key: 'emp-2' }] as never[]
const { counts } = await getWorklistCounts(supabase, 'company-1', {
expensePayoutsDue: Promise.resolve(people),
})
expect(counts.expense_payout).toBe(3)
expect(countExpensePayoutsDue).not.toHaveBeenCalled()
})
it('excludes suggested_match from the total (subset of book_transaction)', async () => {
const { total } = await getWorklistCounts(supabase, 'company-1')
// 4 + 7 + 6 + 1 + 3 + 5 + 1 + 2 + 1, without the 2 suggested matches.
expect(total).toBe(30)
// 4 + 7 + 6 + 1 + 3 + 5 + 1 + 2 + 1 + 2 (people owed for utlägg), without
// the 2 suggested matches.
expect(total).toBe(32)
})
})
+44
View File
@@ -12,6 +12,7 @@ import {
countUnbookedSkattekontoRows,
countUnbookedTransactions,
countVerifikatMissingDocument,
listExpensePayoutsDue,
listSuggestedMatches,
} from '../categories'
import {
@@ -539,3 +540,46 @@ describe('countReconciliationDue', () => {
await expect(countReconciliationDue(supabase, COMPANY, TODAY)).resolves.toBe(0)
})
})
describe('listExpensePayoutsDue', () => {
it('groups registered claims into one item per person, oldest debt first', async () => {
enqueue({
data: [
{ employee_id: null, claimant_name: 'Jakob', liability_account: '2893', amount_sek: '1240.00', expense_date: '2026-09-03' },
{ employee_id: 'emp-1', claimant_name: 'Anna Berg', liability_account: '2820', amount_sek: 1196, expense_date: '2026-09-02' },
{ employee_id: 'emp-1', claimant_name: 'Anna Berg', liability_account: '2820', amount_sek: 400, expense_date: '2026-09-06' },
// Same owner name twice: one person, one transfer.
{ employee_id: null, claimant_name: 'Jakob', liability_account: '2893', amount_sek: 0.1, expense_date: '2026-09-07' },
],
})
const people = await listExpensePayoutsDue(supabase, COMPANY)
expect(mockSupabase.from).toHaveBeenCalledWith('expense_claims')
expect(findCalls('expense_claims', 'eq')).toContainEqual(['status', 'registered'])
expect(people).toEqual([
{
key: 'emp-1',
employee_id: 'emp-1',
claimant_name: 'Anna Berg',
liability_account: '2820',
claim_count: 2,
total_sek: 1596,
oldest_expense_date: '2026-09-02',
},
{
key: 'owner:Jakob',
employee_id: null,
claimant_name: 'Jakob',
liability_account: '2893',
claim_count: 2,
// 1240 + 0.1 in öre-safe arithmetic, never 1240.1000000000001.
total_sek: 1240.1,
oldest_expense_date: '2026-09-03',
},
])
})
it('soft-fails to an empty list on query error', async () => {
enqueue({ error: { message: 'boom' } })
await expect(listExpensePayoutsDue(supabase, COMPANY)).resolves.toEqual([])
})
})