Files
accounted/lib/invoices/__tests__/rounding.test.ts
T
Mattsson 0ee5219b6c feat(invoices): implement öresavrundning logic and next invoice numbe… (#429)
* feat(invoices): implement öresavrundning logic and next invoice number preview

- Added `getDisplayTotal` utility to handle rounding for SEK invoices based on company settings.
- Updated `InvoicesPage` to utilize the new rounding logic when displaying totals.
- Introduced `peek_next_invoice_number` function to allow previewing the next invoice number without consuming the sequence.
- Modified invoice number generation to remove the year prefix and prevent truncation of numbers exceeding three digits.
- Enhanced tests for invoice number generation and rounding functionality to ensure correctness.
- Updated PDF template to reflect new rounding logic for totals and display appropriate values.
- Adjusted company switcher to hide options in sandbox mode.
- Improved error handling and logging in sandbox seeding process.

* fix(skatteverket): remove unused scope labels from SCOPE_LABELS and DEFAULT_SCOPES
2026-05-10 14:21:26 +02:00

48 lines
1.5 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { getDisplayTotal } from '@/lib/invoices/rounding'
const inv = (total: number, currency: 'SEK' | 'EUR' = 'SEK') => ({ total, currency })
const co = (ore_rounding: boolean) => ({ ore_rounding })
describe('getDisplayTotal', () => {
it('rounds SEK with rounding enabled and a non-integer total', () => {
const r = getDisplayTotal(inv(1234.56), co(true))
expect(r.applies).toBe(true)
expect(r.displayed).toBe(1235)
expect(r.roundingDelta).toBe(0.44)
})
it('rounds down when fractional part < 0.5', () => {
const r = getDisplayTotal(inv(1234.4), co(true))
expect(r.applies).toBe(true)
expect(r.displayed).toBe(1234)
expect(r.roundingDelta).toBe(-0.4)
})
it('does not apply when setting is disabled', () => {
const r = getDisplayTotal(inv(1234.56), co(false))
expect(r.applies).toBe(false)
expect(r.displayed).toBe(1234.56)
expect(r.roundingDelta).toBe(0)
})
it('does not apply for non-SEK currencies', () => {
const r = getDisplayTotal(inv(1234.56, 'EUR'), co(true))
expect(r.applies).toBe(false)
expect(r.displayed).toBe(1234.56)
})
it('does not apply when total is already an integer', () => {
const r = getDisplayTotal(inv(1235), co(true))
expect(r.applies).toBe(false)
expect(r.displayed).toBe(1235)
expect(r.roundingDelta).toBe(0)
})
it('treats missing company settings as default-on', () => {
const r = getDisplayTotal(inv(99.99), null)
expect(r.applies).toBe(true)
expect(r.displayed).toBe(100)
})
})