* fix: prevent credit notes from entering payment flow * fix: persist and display customer personal numbers * feat: configure automatic invoice reminder days * fix: issue credit notes through send flow * chore: add repository agent guidance * feat(mcp): route tools across user companies * fix(articles): delete unused register entries * feat(invoices): improve issued invoice actions * feat(supplier-invoices): retain uploaded source documents * docs: record implementation decisions * feat: enhance customer personal number handling and validation - Updated CustomerForm to allow personal numbers in the format of "********-1234" for individual customers. - Added validation to ensure personal numbers are only accepted for individual customers in CreateCustomerSchema. - Implemented masking and encryption for personal numbers to enhance data protection. - Introduced new utility functions for masking and encrypting personal numbers. - Added database migration to enforce unique constraints on credit note relationships and prevent duplicate entries. - Enhanced error handling and logging for credit note issuance and invoice processing. - Updated tests to cover new credit note creation guards and personal number handling. * test: enhance list companies test with supabase query mocks
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { buildCreditNoteItem } from '@/lib/invoices/build-credit-note-item'
|
|
import type { InvoiceItem } from '@/types'
|
|
|
|
function item(overrides: Partial<InvoiceItem> = {}): InvoiceItem {
|
|
return {
|
|
id: 'item-1',
|
|
invoice_id: 'invoice-1',
|
|
sort_order: 0,
|
|
description: 'Arbete',
|
|
quantity: 2,
|
|
unit: 'tim',
|
|
unit_price: 1000,
|
|
line_total: 2000,
|
|
vat_rate: 25,
|
|
vat_amount: 500,
|
|
created_at: '2026-07-14T00:00:00Z',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
describe('buildCreditNoteItem', () => {
|
|
it('negates amounts and preserves ROT/RUT, account, accrual, and dimension metadata', () => {
|
|
const result = buildCreditNoteItem('credit-1', item({
|
|
deduction_type: 'rot',
|
|
deduction_amount: 600,
|
|
labor_hours: 2,
|
|
work_type: 'BYGG',
|
|
housing_designation: 'Test 1:2',
|
|
revenue_account: '3041',
|
|
accrual_period_start: '2026-07-01',
|
|
accrual_period_end: '2026-12-31',
|
|
accrual_balance_account: '2970',
|
|
dimensions: { '6': 'P001' },
|
|
}))
|
|
|
|
expect(result).toMatchObject({
|
|
invoice_id: 'credit-1',
|
|
quantity: -2,
|
|
line_total: -2000,
|
|
vat_amount: -500,
|
|
deduction_type: 'rot',
|
|
deduction_amount: -600,
|
|
labor_hours: 2,
|
|
work_type: 'BYGG',
|
|
housing_designation: 'Test 1:2',
|
|
revenue_account: '3041',
|
|
accrual_period_start: '2026-07-01',
|
|
accrual_period_end: '2026-12-31',
|
|
accrual_balance_account: '2970',
|
|
dimensions: { '6': 'P001' },
|
|
})
|
|
})
|
|
})
|