Open-source personal finance manager. Self-hosted, privacy-first.
fix(dashboard): include pending spend in category widget (#742)
Leonardo Zanivand68c07dbd1d0
diff --git a/backend/tests/test_credit_card_accounting_mode.py b/backend/tests/test_credit_card_accounting_mode.pyindex 04f76ff7..f0a2cc96 100644--- a/backend/tests/test_credit_card_accounting_mode.py+++ b/backend/tests/test_credit_card_accounting_mode.py@@ -487,6 +487,35 @@ class TestDashboardSummary:class TestSpendingByCategory:+ @pytest.mark.asyncio+ @pytest.mark.parametrize("mode", ["cash", "accrual"])+ async def test_pending_credit_card_spend_is_available_in_projected_total(+ self, session, test_user, test_workspace, cc_account, test_categories, mode+ ):+ """The dashboard category widget can include pending card spend.++ ``total`` remains the settled-only value used by the actual/forecast+ split, while ``projected_total`` is the all-in value that must match+ the dashboard drill-down.+ """+ food = test_categories[0]+ today = date.today()+ pending = await _make_tx(+ session, test_user.id, cc_account.id, today,+ Decimal("100"), effective_date=today, category_id=food.id,+ )+ pending.status = "pending"+ await session.commit()+ await _set_mode(session, mode)++ spending = await dashboard_service.get_spending_by_category(+ session, test_workspace.id, test_user.id, month=today.replace(day=1)+ )+ food_row = next(row for row in spending if row.category_id == str(food.id))++ assert food_row.total == 0.0+ assert food_row.projected_total == 100.0+@pytest.mark.asyncioasync def test_category_breakdown_follows_mode(self, session, test_user, test_workspace, cc_account, test_categoriesdiff --git a/backend/tests/test_dashboard_api.py b/backend/tests/test_dashboard_api.pyindex e01d547a..76810871 100644--- a/backend/tests/test_dashboard_api.py+++ b/backend/tests/test_dashboard_api.py@@ -367,10 +367,10 @@ async def test_pending_and_future_rows_are_current_vs_projected("""Pending and future rows affect the forecast, never a manual current balance."""today = date.today()future_date = today + timedelta(days=3)-+# Keep the queried month aligned with the future row at month boundaries.forecast_month = future_date.replace(day=1).isoformat()-+acc_resp = await client.post("/api/accounts",json={"name": "Forecast split", "type": "checking", "balance": 1000.00, "currency": "BRL"},diff --git a/frontend/src/pages/dashboard.tsx b/frontend/src/pages/dashboard.tsxindex 9d57bd1f..20733efd 100644--- a/frontend/src/pages/dashboard.tsx+++ b/frontend/src/pages/dashboard.tsx@@ -424,8 +424,13 @@ export default function DashboardPage() {.filter(s => s.category_id !== null).map(s => {const budget = s.category_id ? budgetMap.get(s.category_id) : undefined- const actual = s.total- const prevAmount = budget ? Number(budget.prev_month_amount) : 0+ // The category widget must show the same spend set as its drill-down:+ // settled transactions plus pending/future rows and recurring+ // projections. The API keeps `total` as settled-only for callers that+ // need the actual/forecast split, while `projected_total` is the+ // user-visible all-in amount.+ const actual = s.projected_total+ const prevAmount = budget ? Number(budget.projected_prev_month_amount) : 0let momPct: number | null = nullif (prevAmount > 0) {momPct = ((actual - prevAmount) / prevAmount) * 100diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.tsindex 5b7985e0..f50036db 100644--- a/frontend/src/types/index.ts+++ b/frontend/src/types/index.ts@@ -684,6 +684,7 @@ export interface SpendingByCategory {category_icon: stringcategory_color: stringtotal: number+ projected_total: numberpercentage: number}