Open-source personal finance manager. Self-hosted, privacy-first.
fix(transactions): keep the cents when repeating a typed amount as installments (#1078)
Mayurif9770678c10b
diff --git a/frontend/src/components/transaction-dialog-installments.test.tsx b/frontend/src/components/transaction-dialog-installments.test.tsxnew file mode 100644index 00000000..e6332d12--- /dev/null+++ b/frontend/src/components/transaction-dialog-installments.test.tsx@@ -0,0 +1,90 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { screen, waitFor, within } from '@testing-library/react'++import { TransactionDialog } from '@/components/transaction-dialog'+import { currencies, payees, settings } from '@/lib/api'+import { renderWithProviders, t } from '@/test/utils'++vi.mock('@/hooks/use-display-locale', () => ({+ useDateLocale: () => 'en-US',+ useDisplayLocale: () => 'de-DE',+}))++vi.mock('@/hooks/use-privacy-mode', () => ({+ usePrivacyMode: () => ({ privacyMode: false, MASK: '••••' }),+}))++vi.mock('@/contexts/auth-context', async (importOriginal) => ({+ ...(await importOriginal<typeof import('@/contexts/auth-context')>()),+ useAuth: () => ({ user: null }),+}))++vi.mock('@/lib/api', async (importOriginal) => ({+ ...(await importOriginal<typeof import('@/lib/api')>()),+ currencies: { list: vi.fn() },+ payees: { list: vi.fn() },+ settings: { attachments: vi.fn() },+}))++describe('TransactionDialog with comma decimals', () => {+ beforeEach(() => {+ vi.mocked(currencies.list).mockResolvedValue([])+ vi.mocked(payees.list).mockResolvedValue([])+ vi.mocked(settings.attachments).mockResolvedValue({+ allowed_extensions: ['pdf'],+ max_file_size_mb: 10,+ max_attachments_per_transaction: 10,+ })+ })++ afterEach(() => {+ vi.resetAllMocks()+ })++ async function saveNewTransaction(typedAmount: string, repeatAsInstallments: boolean) {+ const onSave = vi.fn()+ const { user } = renderWithProviders(+ <TransactionDialog+ open+ onClose={vi.fn()}+ transaction={null}+ categories={[]}+ categoryGroups={[]}+ accounts={[{ id: 'acct-1', name: 'Checking', currency: 'EUR' }]}+ defaultAccountId="acct-1"+ onSave={onSave}+ loading={false}+ error={null}+ />,+ )+ const dialog = await screen.findByRole('dialog')+ await user.type(dialog.querySelector('input[required]:not([inputmode])')!, 'Notebook')+ await user.type(dialog.querySelector('input[inputmode="decimal"]')!, typedAmount)+ if (repeatAsInstallments) {+ await user.click(within(dialog).getByLabelText(t('transactions.makeInstallment')))+ }+ await user.click(within(dialog).getByRole('button', { name: t('common.save') }))+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1))+ return onSave.mock.calls[0]+ }++ it.each([+ ['50,25', 50.25],+ ['1.234,56', 1234.56],+ ])('saves %s as %d', async (typedAmount, expected) => {+ const [data, , installmentData] = await saveNewTransaction(typedAmount, false)++ expect(data.amount).toBe(expected)+ expect(installmentData).toBeUndefined()+ })++ it.each([+ ['50,25', 50.25],+ ['1.234,56', 1234.56],+ ])('repeats %s as installments of %d', async (typedAmount, expected) => {+ const [data, , installmentData] = await saveNewTransaction(typedAmount, true)++ expect(data.amount).toBe(expected)+ expect(installmentData.base.amount).toBe(expected)+ })+})diff --git a/frontend/src/components/transaction-dialog.tsx b/frontend/src/components/transaction-dialog.tsxindex 3570a3a4..eca8f69e 100644--- a/frontend/src/components/transaction-dialog.tsx+++ b/frontend/src/components/transaction-dialog.tsx@@ -835,13 +835,13 @@ function TransactionForm({const recurringData = isCreating && isRecurring? { frequency, end_date: endDate || undefined }: undefined- const installmentData = isCreating && isInstallment && !isSynced+ const installmentData = isCreating && isInstallment && !isSynced && parsedAmount != null? buildInstallmentSeriesInput({accountId,categoryId,payeeId,description,- amount,+ amount: parsedAmount,date,type,currency,diff --git a/frontend/src/lib/installment-series.test.ts b/frontend/src/lib/installment-series.test.tsindex 78c3373e..c8cdda99 100644--- a/frontend/src/lib/installment-series.test.ts+++ b/frontend/src/lib/installment-series.test.ts@@ -12,7 +12,7 @@ const base: InstallmentSeriesFormInput = {categoryId: 'cat-1',payeeId: null,description: 'Notebook',- amount: '150.00',+ amount: 150,date: '2026-08-06',type: 'debit',currency: 'BRL',diff --git a/frontend/src/lib/installment-series.ts b/frontend/src/lib/installment-series.tsindex a4ed17aa..830816db 100644--- a/frontend/src/lib/installment-series.ts+++ b/frontend/src/lib/installment-series.ts@@ -15,7 +15,7 @@ export interface InstallmentSeriesFormInput {categoryId: string | nullpayeeId: string | nulldescription: string- amount: string+ amount: numberdate: stringtype: 'debit' | 'credit'currency?: string@@ -78,7 +78,7 @@ export function buildInstallmentSeriesInput(category_id: input.categoryId || null,payee_id: input.payeeId || null,description: input.description,- amount: parseFloat(input.amount),+ amount: input.amount,date: input.date,type: input.type,...(input.currency ? { currency: input.currency } : {}),