fix(balances): allow zero on CSV import reference + lock contract with tests

Extend the zero-balance fix to the CSV-import reference balance field (same
root cause; the compute path already gates on referenceBalance !== null, so an
explicit 0 is a valid anchor). Drop the now-orphaned 'Please enter a balance'
translation and add feature tests asserting a zero balance can be stored and
set as the current balance.
This commit is contained in:
Víctor Falcón 2026-07-10 14:30:45 +02:00
parent c9b09848be
commit fd132001d1
4 changed files with 41 additions and 3 deletions

View File

@ -1240,7 +1240,6 @@
"Pink": "Rosa",
"Platform": "Plataforma",
"Please describe the problem and what you were doing when it happened. Keep the details below — they help us debug.": "Describe el problema y qué estabas haciendo cuando ocurrió. Conserva los detalles de abajo: nos ayudan a depurar.",
"Please enter a balance": "Por favor, ingresa un balance",
"Please enter a bank name.": "Por favor, ingresa un nombre de banco.",
"Please enter an account name.": "Por favor, ingresa un nombre de cuenta.",
"Please enter your new password below": "Por favor ingresa tu nueva contraseña a continuación",

View File

@ -1199,7 +1199,6 @@
"Pink": "Rose",
"Platform": "Plate-forme",
"Please describe the problem and what you were doing when it happened. Keep the details below — they help us debug.": "Décrivez le problème et ce que vous faisiez lorsqu'il s'est produit. Conservez les détails ci-dessous : ils nous aident à déboguer.",
"Please enter a balance": "Veuillez saisir un solde",
"Please enter a bank name.": "Veuillez saisir un nom de banque.",
"Please enter an account name.": "Veuillez saisir un nom de compte.",
"Please enter your new password below": "Veuillez entrer votre nouveau mot de passe ci-dessous",

View File

@ -428,7 +428,6 @@ export function ImportStepMapping({
value={referenceBalance ?? 0}
onChange={onReferenceBalanceChange}
currencyCode={currencyCode}
required
/>
{referenceBalancePrefilled && (
<p className="text-xs text-muted-foreground">

View File

@ -280,6 +280,47 @@ it('can store balance without invested_amount', function () {
]);
});
it('can store a zero balance', function () {
$user = User::factory()->create();
$account = Account::factory()->for($user)->create();
$response = $this->actingAs($user)->postJson("/api/accounts/{$account->id}/balances", [
'balance' => 0,
'balance_date' => now()->subDays(5)->toDateString(),
]);
$response->assertStatus(201)
->assertJsonPath('data.balance', 0);
$this->assertDatabaseHas('account_balances', [
'account_id' => $account->id,
'balance' => 0,
]);
});
it('can update the current balance to zero', function () {
$user = User::factory()->create();
$account = Account::factory()->for($user)->create();
AccountBalance::factory()->for($account)->create([
'balance_date' => now()->toDateString(),
'balance' => 100000,
]);
$response = $this->actingAs($user)->putJson("/api/accounts/{$account->id}/balance/current", [
'balance' => 0,
]);
$response->assertSuccessful()
->assertJsonPath('data.balance', 0);
$this->assertDatabaseHas('account_balances', [
'account_id' => $account->id,
'balance_date' => now()->toDateString(),
'balance' => 0,
]);
});
it('validates store balance must be an integer', function () {
$user = User::factory()->create();
$account = Account::factory()->for($user)->create();