actualbudget / actualbudget/actual

[Bug]: Rollover budget categories with overspending don't carry deficit to next month

Abierto
#8,615 2 comentarios 1 reacción 0 asignados Ver en GitHub
needs info
Lenguaje dominante
TypeScript
Estrellas
28.7k
Forks
3k
Merge medio
2 d 11 h
PR fusionados (30 d)
65

Descripción

## What happened?

When a category has **Rollover (carryover)** enabled and has an overspend in one month, the deficit does not properly carry forward to reduce the budget in the next month. Instead, the overspending amount appears only at the month-level summary ("Overspent in Jul") without being deducted from the individual category's budget.

## Example (Real Case)

**July Medical:**
- Budgeted: $200.00
- Spent: $286.42
- Balance: -$35.85 (overspent by $35.85)
- Rollover enabled: YES

**August Medical (Expected):**
- Should calculate as: $50 (new budget) - $35.85 (July deficit) = **$14.15 available**

**August Medical (Actual):**
- Shows: $50 balance (fresh allocation)
- The $35.85 deficit does NOT carry to the category level
- Instead appears only as "Overspent in Jul: -$35.85" at month summary level

## Root Cause

In `/packages/loot-core/src/server/budget/envelope.ts` lines 137-154, the `last-month-overspent` calculation explicitly skips categories with `carryover: true`:

```typescript
sheet.get().createDynamic(sheetName, last-month-overspent, {
initialValue: 0,
dependencies: flatten2(
expenseCategories.map(cat => [
`${prevSheetName}!leftover-${cat.id}`,
`${prevSheetName}!carryover-${cat.id}`,
]),
),
run: (...data) => {
data = unflatten2(data);
return safeNumber(
data.reduce((total, [leftover, carryover]) => {
if (carryover) {
return total; // ← BUG: Skips rollover categories!
}
return total + Math.min(0, number(leftover));
}, 0),
);
},
});
```

When `carryover` is `true`, the overspending is not included in the month-level deficit calculation. This causes the deficit to "float" at the month level instead of being carried to the category's balance in the next month.

## Expected Behavior

When a category with rollover enabled has an overspend (negative balance), that deficit should automatically:
1. Carry forward to the next month's balance for that category
2. Reduce the available budget for that category in the next month
3. Require reallocation or covering before the category can be spent again

## Related Issues
- #6780: Feature request describing the desired behavior
- #8494: Similar issue with budget automations not accounting for current month overspending

## Environment
- Server version: v26.7.0 (but bug exists in current master)
- Files affected: `/packages/loot-core/src/server/budget/envelope.ts`

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.