Keep transfer input on a rejected submit and read comma rates

GF
1d ago
+804-63

Stacked on #5833: the base is a copy of that PR's branch, so the diff shows only this change. Once #5833 is merged, this PR's base moves to main.

Problem

  1. When a transfer was rejected (invalid date, missing exchange rate, same account on both sides, or a stale form), the form came back with To reset to "Select account". The date, the bank charges and the exchange rate were gone too. Everything except the source account and amount had to be entered again.
  2. The exchange rate in the transfer and transaction forms was still a type="number" input. In Chromium, 1,1 was submitted as 11.

Change

  • TransfersController#create redraws every rejection through one render_new_with_submitted_input. It keeps the destination account, the date, both fees, the tags and the exchange rate. A fee or rate that is not plain decimal text, such as a submit without JavaScript or exponent notation, is dropped rather than shown as a different number.
  • Model validation errors (for example, the same account on both sides) now redraw the form instead of raising. A zero rate or a negative fee is reported as an invalid amount, not as an invalid date. A stale form gets a fresh idempotency key, so the next submit is not rejected again.
  • The form selects the kept destination account and opens Bank charges when a fee was given. The exchange-rate controller keeps a redrawn rate on the lookup it starts on connect, instead of overwriting it with the market rate. A later lookup, after another account or date is picked, replaces it as before. On the calculate tab, a lookup recomputes the rate from the typed amounts.
  • The exchange rate in both forms is now a money field with no symbol and no rounding (step: "any"), so a comma decimal or an expression (1/0,92) works. Pasting 0,925 reads it as typed (0.925), because a rate has no currency to settle the separator. Unrounded amounts keep 15 significant digits, so tiny rates survive.
  • money_field accepts raw_value: for a value that is not a currency amount and must be shown as given. The transaction form uses it, so an invalid rate is shown as typed instead of raising in sprintf.

Screenshots

Before, the rate 1,1 was submitted as 11. After, it is 1.1, and a rejected submit keeps the destination, the date, the fees and the rate.

BeforeAfter
Rate 1,1 typedbeforeafter
After a rejected submitbeforeafter

Field sizes, left main, right this PR (calculator closed, then open):

New transfer

transfer_new closed
transfer_new open

No size changes against #5833.

Validation

  • Controller tests check that a rejected transfer keeps the destination, the date, the fees and the rate, and that a non-numeric fee or an exponent rate is dropped. They also cover the same account on both sides, a zero rate reported on the amounts, a stale form getting a fresh key, and a rejected transaction showing an invalid rate as entered.
  • A system test checks that a transfer's exchange rate reads a comma decimal: the destination shows 110.00 EUR and 1.1 is submitted.
  • JavaScript unit tests cover tiny rates and large unrounded amounts.
  • Checked in the transfer dialog of a local instance (screenshots above). A rejected submit keeps every field, and a rate of 1,1 converts 100 USD to 110.00 EUR.
  • No migrations.

How this fits together

The money field work is split into small PRs that build on each other. Review from the top of this list; each stacked PR's base is a stack/* copy of the PR below it, so its diff shows only its own change.

  1. #6032: bounds checked on the submitted amount, hints for ignored input, parentheses (fixes #5944). Base: main.
  2. #6033: operator bar docked above the on-screen keyboard. Base: #6032.
  3. #5833: every amount input uses the money field. Base: #6033.
  4. #5850: a rejected transfer keeps its input; comma exchange rates. Base: #5833.
  5. #5939: the remaining decimal fields (quantities, rates) read comma decimals. Base: #5850.
  6. #6035: plain-number fields without the calculator for settings, rates and rule/filter limits. Base: #5939.

Standalone: #6034 (phone layout of goal, vehicle and settings number rows). Base: main; it does not depend on the stack.


Summary by cubic

A rejected transfer submit now redraws the form with the destination account, date, fees and exchange rate intact, and the exchange rate reads comma decimals and expressions in both transfer and transaction forms.

  • A rejected submit opens bank charges when a fee was given and gets a fresh idempotency key only when the kept request signature proves it differs from the creating request; the creator raises its own InvalidAmountsError for a zero rate or a negative fee, so unrelated argument errors are not reported as invalid amounts, validation errors redraw the form instead of raising, and an overlong date is an invalid date rather than a 500.
  • The exchange rate is a money field with no symbol or rounding, so a comma decimal or an expression (1/0,92) works; a kept rate survives the first lookup, a failed lookup or a date without a market rate recomputes from typed amounts on the calculate tab, and a redrawn rate keeps the exact decimals an expression submitted (up to 60) as long as the money field reads it again — anything longer is dropped rather than left as an invalid form.
  • A converted-transfer retry now matches at the stored precision, and a day-long request signature identifies replays of the creating request (including a dateless one after midnight) and returns the transfer instead of a duplicate; a request that only matches an edit is stale and keeps the key, while a repeated tag id is still the same request.

Summary by CodeRabbit

  • New Features

    • Exchange-rate fields accept decimal commas and expressions, and display rates with greater precision.
    • Transfer fee details open automatically when fees are present.
    • Transfers without a submitted date use today’s date.
  • Bug Fixes

    • Transfer and transaction forms retain submitted values after validation errors, including account selections, dates, fees, and exchange rates.
    • Calculated rates remain visible after a date change when no market rate is available.
    • Amount formatting better preserves significant digits and reduces floating-point drift.
    • Invalid dates, amounts, and exchange rates display clearer validation messages.
    • Retrying a rejected transfer with changed details no longer reuses the same request key. Retries also account for saved rounding and edited transfers to help prevent duplicates.