Bokföring och redovisning
I korthet
Bokforing och redovisning is the double-entry bookkeeping core: balanced AccountingEntry vouchers backed by per-tenant chart-of-accounts mapping, exports to Fortnox semicolon CSV, Visma eEkonomi tab text, Xero international CSV, Bokio direct REST API and SIE4 with #KTYP, #IB, #UB and #RES, season-snapshot financial statements with optional period lock on finalisation, consolidated income-statement and balance-sheet reports broken down per OrgNode and an immutable FinancialAuditLog covering every operation including export generation.
Så fungerar det
Every booked transaction lives as an AccountingEntry voucher with debit and credit lines balanced to zero. ChartOfAccountsMapping is a tenant-scoped collection that translates internal BAS account categories into external provider accounts; one active mapping per provider per tenant is enforced (duplicate creation returns 409). Exports are provider-specific: Fortnox via /accounting-export/fortnox writes semicolon-separated CSV with VER, Serie, Vernr, Datum, Text, Konto, Debet, Kredit columns and Swedish decimal format (comma); Xero via /accounting-export/xero writes comma-separated CSV with star-prefixed required columns and international decimal format (period); Visma eEkonomi via /accounting-export/visma writes tab-separated text with VER plus Projekt and Resultatenhet, Swedish decimal format, and supports API push via /accounting-integrations/{id}/sync/{entry_id}.
SIE4 export at /accounting-export/sie4 includes header lines #KTYP for account types, #IB for opening balances, #UB for closing balances and #RES for income-statement accounts, encoded CP437 per Swedish standard. Bokio has its own variant with UTF-8 BOM, CRLF line endings, BAS-2024 validation (1000-8999) and mandatory #ORGNR at /accounting/bokio/export/sie4, plus a direct REST API integration with OAuth2 onboarding at /accounting/bokio/configure, idempotency-key vouchers, token refresh five minutes before expiry, and error handling per status (401 retry, 409 ignore, 422 fail, 429 backoff). A sync job runs every 15 minutes (or on demand), POSTing entries with synced_to_bokio_at = None to Bokio with up to three retries on exponential backoff and writing the external reference back.
Financial statements are season snapshots stored at /financial-statements/ with income-statement and balance-sheet snapshots, totals (total_revenue, total_expenses, net_result, total_assets, total_liabilities, total_equity) and a draft -> finalized lifecycle with optional period lock on finalisation. Period locks at /period-locks/ block entry create, post and void within the locked date range, refuse overlapping locks (409) and can be unlocked with a reason. Consolidated reports at /accounting-reports/consolidated-income-statement and /consolidated-balance-sheet break down by org_node_id with a quarter filter and an as_of_date filter for the balance sheet.
Every operation appends to FinancialAuditLog.
Centrala funktioner
- AccountingEntry double-entry vouchers with chart-of-accounts mapping per tenant per provider
- Provider exports for Fortnox, Visma eEkonomi, Xero, Bokio and SIE4 with IB, UB and RES
- Bokio direct API integration with OAuth2, idempotency keys, token refresh and 15-minute sync job
- Season financial statements with income-statement and balance-sheet snapshots and finalisation lock
- Period locks that block entry create, post and void within a locked range and reject overlap
- Consolidated income statement and balance sheet per OrgNode with quarter and as-of-date filters
- Immutable FinancialAuditLog and export_generated trace on every export
I praktiken
After year-end the federation accountant opens /financial-statements/, generates a draft statement for fiscal 2026 — the system snapshots the income statement and balance sheet from posted vouchers — and reviews the totals. Satisfied, she finalises with create_period_lock=true; /period-locks/ writes a lock for 2026-01-01 to 2026-12-31 and any further attempts to post or void in that window return 409. She then runs /accounting-export/sie4 with fiscal_year, company_name and org_number; the auditor receives a CP437-encoded file with #KTYP, #IB, #UB and #RES sections.
In parallel she has Bokio configured for direct API push; the 15-minute sync job picks up the last unsynced vouchers, retries one 429 with exponential backoff, succeeds and writes external_refs.bokio back to each entry — the FinancialAuditLog records every step.
Features i detta subsystem
12| ID | Status | Funktioner |
|---|---|---|
| F08.10.01 | Levererad | Sverige - Fortnox-export — semikolonseparerad CSV med VER/Serie/Vernr/Datum/Text/Konto/Debet/Kredit. Svenskt decimalformat (komma). Exporterar endast bokförda verifikationer. Använder per-tenant kontoplansmappning. ✅ PL-F0810a |
| F08.10.02 | Levererad | International - Xero-export — kommaseparerad CSV med *Date/*Description/*AccountCode/*Debit/*Credit/TaxType/Reference. Internationellt decimalformat (punkt). Per-tenant kontoplansmappning. ✅ PL-F0810a |
| F08.10.03 | Levererad | Sverige - Visma eEkonomi-export — tabbseparerad textfil med VER/Serie/Vernr/Datum/Text/Konto/Debet/Kredit/Projekt/Resultatenhet. Svenskt decimalformat. Stödjer API-synkronisering via integrationsconfig. ✅ PL-F0810a |
| F08.10.04 | Levererad | Per-tenant chart of accounts mapping — ChartOfAccountsMapping-samling tenant-scopad. Översätter interna BAS-konton till externa leverantörskonton. En aktiv mappning per provider per tenant. CRUD med duplikatskydd (409). ✅ PL-F0810a |
| F08.10.05 | Levererad | SIE4-export med IB/UB/RES — utökad SIE4-export (GET /accounting-export/sie4) med #KTYP kontotyper, #IB ingående balanser, #UB utgående balanser, #RES resultaträkningskonton. CP437-encoding, fiscal_year/company_name/org_number-parametrar. ✅ PL-F0810b |
| F08.10.06 | Levererad | Bokslut per säsong — generering av bokslut (financial statements) med resultaträkning- och balansräkningsögonblicksbilder. Status draft→finalized livscykel. Valfri periodlåsning vid finalisering. CRUD /financial-statements/. ✅ PL-F0810b |
| F08.10.07 | Levererad | Revisionsspår och låsning av perioder — periodlåsning förhindrar skapande/bokföring/makulering av verifikationer inom låst datumintervall. CRUD + check + unlock /period-locks/. Överlappande lås avvisas. Komplett audit trail via FinancialAuditLog. ✅ PL-F0810b |
| F08.10.08 | Levererad | Resultaträkning och balansräkning per OrgNode — konsoliderade rapporter per kostnadställe. GET /accounting-reports/consolidated-income-statement och /consolidated-balance-sheet med org_node_id-nedbrytning. Kvartalsfilter. ✅ PL-F0810b |
| F08.10.09 | Levererad | Bokio SIE4-export — Bokio-specifik SIE4-variant med UTF-8 BOM, CRLF-radslut, BAS-2024-validering (1000–8999), obligatoriskt #ORGNR. GET /accounting/bokio/export/sie4. ✅ PL-T078 |
| F08.10.10 | Levererad | Bokio direkt-API — OAuth2-onboarding + synkron/batch-POST av verifikationer till Bokio REST API med idempotency-nycklar. Token-refresh 5 min före expiry. Error-hantering: 401 retry, 409 ignore, 422 fail, 429 backoff. ✅ PL-T078 |
| F08.10.11 | Levererad | Bokio sync-jobb — batch-sync var 15 min (eller on-demand), plockar entries med synced_to_bokio_at is None, POST till Bokio per entry, markerar synced med external_refs.bokio. Max 3 retries med exponentiell backoff. ✅ PL-T078 |
| F08.10.12 | Levererad | Bokio onboarding-flow — POST /accounting/bokio/configure (company_id, sync_mode api/sie4_only), OAuth-URL för API-läge, test-connection via get_fiscal_years(). Admin-vy med provider-kort, Sync Now-knapp, SIE4-nedladdning. ✅ PL-T078 |