Fix/dependabot cus feedback (#946)
* feat(bookkeeping): per-account default VAT, oresavrundning momsfri Add a per-account "Standard moms" setting to the chart of accounts and use it to auto-fill the moms on a leverantorsfaktura-rad when that konto is picked. Oresavrundning (3740) ships as "Ingen moms", so a rounding line no longer inherits the 25 % rad-default and skews the moms. - chart_of_accounts.default_vat_rate (0/0.06/0.12/0.25, CHECK-constrained) - BEFORE INSERT trigger ships 3740 momsfri on every insert path; backfills existing 3740 rows - kontoplan editor: dead free-text momskod replaced with a Standard moms select - supplier-invoice rad auto-fills the rate from the konto default Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(supplier-invoices): configurable start number for the ankomstnummer series Add a company_settings.next_arrival_number start floor so a company can continue its leverantorsfaktura numbering from a previous system (e.g. Fortnox) instead of restarting the ankomstnummer at 1. get_next_arrival_number now floors the series via GREATEST(MAX(arrival_number)+1, next_arrival_number), so the floor can never move the series backwards or collide with the (company_id, arrival_number) unique index. The RPC is hardened while rewritten: SET search_path to empty, schema-qualified refs, and an auth.uid() membership check matching generate_invoice_number. Includes the settings UI field, sv/en strings, migration, and pg-real coverage. The CompanySettings type and Zod schema field for this feature landed earlier in 1bf3b641 (swept into the per-account VAT commit). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(dependabot): reduce open pull requests limit and group updates for better management --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
b1f85bc33e
commit
bacc5914af
@@ -1175,6 +1175,20 @@ describe('UpdateSettingsSchema', () => {
|
||||
expect(result.success).toBe(true)
|
||||
})
|
||||
|
||||
it('accepts a positive next_arrival_number (supplier-invoice start floor)', () => {
|
||||
const result = UpdateSettingsSchema.safeParse({ next_arrival_number: 248 })
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.data.next_arrival_number).toBe(248)
|
||||
}
|
||||
})
|
||||
|
||||
it('rejects a non-positive next_arrival_number', () => {
|
||||
expect(UpdateSettingsSchema.safeParse({ next_arrival_number: 0 }).success).toBe(false)
|
||||
expect(UpdateSettingsSchema.safeParse({ next_arrival_number: -5 }).success).toBe(false)
|
||||
expect(UpdateSettingsSchema.safeParse({ next_arrival_number: 1.5 }).success).toBe(false)
|
||||
})
|
||||
|
||||
it('accepts vat_registered: true with required vat_number and moms_period', () => {
|
||||
const result = UpdateSettingsSchema.safeParse({
|
||||
vat_registered: true,
|
||||
@@ -2030,6 +2044,25 @@ describe('UpdateAccountSchema', () => {
|
||||
const result = UpdateAccountSchema.safeParse({ is_active: 'yes' })
|
||||
expect(result.success).toBe(false)
|
||||
})
|
||||
|
||||
it('accepts a valid default_vat_rate (0/0.06/0.12/0.25/null)', () => {
|
||||
expect(UpdateAccountSchema.safeParse({ default_vat_rate: 0 }).success).toBe(true)
|
||||
expect(UpdateAccountSchema.safeParse({ default_vat_rate: 0.06 }).success).toBe(true)
|
||||
expect(UpdateAccountSchema.safeParse({ default_vat_rate: 0.12 }).success).toBe(true)
|
||||
expect(UpdateAccountSchema.safeParse({ default_vat_rate: 0.25 }).success).toBe(true)
|
||||
expect(UpdateAccountSchema.safeParse({ default_vat_rate: null }).success).toBe(true)
|
||||
})
|
||||
|
||||
it('rejects a default_vat_rate outside the allowed set', () => {
|
||||
expect(UpdateAccountSchema.safeParse({ default_vat_rate: 0.2 }).success).toBe(false)
|
||||
expect(CreateAccountSchema.safeParse({
|
||||
account_number: '3740',
|
||||
account_name: 'Öres- och kronutjämning',
|
||||
account_type: 'revenue',
|
||||
normal_balance: 'debit',
|
||||
default_vat_rate: 0.5,
|
||||
}).success).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
// ============================================================
|
||||
|
||||
@@ -1368,6 +1368,7 @@ export const UpdateSettingsSchema = z.object({
|
||||
accounting_method: AccountingMethodSchema.optional(),
|
||||
invoice_prefix: z.string().nullable().optional(),
|
||||
next_invoice_number: z.number().int().positive().optional(),
|
||||
next_arrival_number: z.number().int().positive().optional(),
|
||||
invoice_default_days: z.number().int().positive().optional(),
|
||||
invoice_default_notes: z.string().nullable().optional(),
|
||||
default_our_reference: z.string().max(200).nullable().optional(),
|
||||
@@ -1540,6 +1541,13 @@ export const CreateDeadlineSchema = z.object({
|
||||
// Account schemas
|
||||
// ============================================================
|
||||
|
||||
// Per-account default VAT rate: the sats the booking UI understands, as a
|
||||
// decimal fraction. Mirrors the DB CHECK on chart_of_accounts.default_vat_rate.
|
||||
const defaultVatRate = z
|
||||
.union([z.literal(0), z.literal(0.06), z.literal(0.12), z.literal(0.25)])
|
||||
.nullable()
|
||||
.optional()
|
||||
|
||||
export const CreateAccountSchema = z.object({
|
||||
account_number: accountNumber,
|
||||
account_name: z.string().min(1, 'Account name is required'),
|
||||
@@ -1548,6 +1556,7 @@ export const CreateAccountSchema = z.object({
|
||||
plan_type: z.enum(['k1', 'full_bas']).optional(),
|
||||
description: z.string().nullable().optional(),
|
||||
default_vat_code: z.string().nullable().optional(),
|
||||
default_vat_rate: defaultVatRate,
|
||||
sru_code: z.string().nullable().optional(),
|
||||
})
|
||||
|
||||
@@ -1556,6 +1565,7 @@ export const UpdateAccountSchema = z.object({
|
||||
is_active: z.boolean().optional(),
|
||||
description: z.string().nullable().optional(),
|
||||
default_vat_code: z.string().nullable().optional(),
|
||||
default_vat_rate: defaultVatRate,
|
||||
sru_code: z.string().nullable().optional(),
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user