Typing "0" into Betalningsvillkor on a customer made the form silently unsavable: the form schema had min(1) and no error was rendered for the field, so the user saw nothing happen. 0 days is a real value (betalning direkt / vid mottagande), and the invoice schema already accepted it. Customer and supplier forms now validate whole days 0-365 and show the rule under the field; the API schemas (customer create/update, supplier) accept 0 the same way; and every `|| 30` fallback that would have turned a stored 0 back into 30 on edit or create is `?? 30`. Closes #2070 Claude-Session: https://claude.ai/code/session_01VnConrmMCxJRQ5kfiPPWyy 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:
co-authored by
Jakob Wennberg
Claude Fable 5.1
parent
5eac2a492c
commit
1150930cb9
@@ -704,8 +704,13 @@ describe('CreateCustomerSchema', () => {
|
||||
expect(result.success).toBe(false)
|
||||
})
|
||||
|
||||
it('rejects zero payment terms', () => {
|
||||
it('accepts zero payment terms (betalning direkt, issue #2070)', () => {
|
||||
const result = CreateCustomerSchema.safeParse(validCustomer({ default_payment_terms: 0 }))
|
||||
expect(result.success).toBe(true)
|
||||
})
|
||||
|
||||
it('rejects payment terms above 365 days', () => {
|
||||
const result = CreateCustomerSchema.safeParse(validCustomer({ default_payment_terms: 366 }))
|
||||
expect(result.success).toBe(false)
|
||||
})
|
||||
|
||||
|
||||
+6
-3
@@ -1003,7 +1003,8 @@ export const CreateCustomerSchema = z.object({
|
||||
.optional()
|
||||
.nullable(),
|
||||
language: z.enum(['sv', 'en']).optional(),
|
||||
default_payment_terms: z.number().int().positive().optional(),
|
||||
// Whole days 0-365; 0 = betalning direkt / vid mottagande (issue #2070).
|
||||
default_payment_terms: z.number().int().min(0).max(365).optional(),
|
||||
notes: z.string().optional(),
|
||||
}).superRefine((customer, ctx) => {
|
||||
if (customer.personal_number && customer.customer_type !== 'individual') {
|
||||
@@ -1145,7 +1146,8 @@ export const UpdateCustomerSchema = z.object({
|
||||
.nullable()
|
||||
.optional(),
|
||||
language: z.enum(['sv', 'en']).optional(),
|
||||
default_payment_terms: z.number().int().positive().optional(),
|
||||
// Whole days 0-365; 0 = betalning direkt / vid mottagande (issue #2070).
|
||||
default_payment_terms: z.number().int().min(0).max(365).optional(),
|
||||
notes: z.string().optional(),
|
||||
}).superRefine((customer, ctx) => {
|
||||
if (
|
||||
@@ -1200,7 +1202,8 @@ export const CreateSupplierSchema = z.object({
|
||||
clearing_number: z.string().optional(),
|
||||
account_number: z.string().optional(),
|
||||
default_expense_account: emptyStringAsUndefined(accountNumber),
|
||||
default_payment_terms: z.number().int().positive().optional(),
|
||||
// Whole days 0-365; 0 = betalning direkt / vid mottagande (issue #2070).
|
||||
default_payment_terms: z.number().int().min(0).max(365).optional(),
|
||||
default_currency: CurrencySchema.nullable().optional(),
|
||||
notes: z.string().optional(),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user