Reuse Correct Expense Total Calculation #1699

Merged
JLambertazzo merged 1 commits from fix/1663-consistent-expense-totals into main 2025-01-27 22:29:50 +08:00
JLambertazzo commented 2025-01-27 01:51:15 +08:00 (Migrated from github.com)

fixes #1663

Root Cause:

  • "Spent" and "Expenses" values on the budget page are being calculated by different functions

  • The value under "Spent" is calculated with budget.actual_spending, which does not include Uncategorized spending

    • in #1663, notice that 62% of the $3007 is missing
    • was able to recreate this locally
      Screenshot 2025-01-26 110409
  • This is because Uncategorized category is not present on the budget_categories array in the budget class
    Screenshot 2025-01-26 222721

Proposed Fix:

  • Reuse expense_categories_with_totals.total_money which already calculates monthly expense totals, including Uncategorized spending
  • Convert Money to amount to stay consistent with expected return type of actual_spending

Alternatively

Could fix by explicit inclusion of uncategorized expenses in actual_spending, but expense_categories_with_totals.total_money already calculates the desired value, and from the issue it seems we do expect the results to be the same, so I implemented the proposal above instead in this PR.

Results

After implementing the fix, the totals are consistent
Screenshot 2025-01-26 124105

fixes #1663 ## Root Cause: * "Spent" and "Expenses" values on the budget page are being calculated by different functions * The value under "Spent" is calculated with `budget.actual_spending`, which does not include Uncategorized spending * in #1663, notice that `62%` of the `$3007` is missing * was able to recreate this locally ![Screenshot 2025-01-26 110409](https://github.com/user-attachments/assets/993bf159-cbbe-407d-b128-90c006c504e9) * This is because Uncategorized category is not present on the `budget_categories` array in the `budget` class ![Screenshot 2025-01-26 222721](https://github.com/user-attachments/assets/6d74c8ed-082d-4e11-bce7-fb844ed560fc) ## Proposed Fix: * Reuse `expense_categories_with_totals.total_money` which already calculates monthly expense totals, including Uncategorized spending * Convert `Money` to `amount` to stay consistent with expected return type of `actual_spending` ### Alternatively Could fix by explicit inclusion of uncategorized expenses in `actual_spending`, but `expense_categories_with_totals.total_money` already calculates the desired value, and from the issue it seems we do expect the results to be the same, so I implemented the proposal above instead in this PR. ## Results After implementing the fix, the totals are consistent ![Screenshot 2025-01-26 124105](https://github.com/user-attachments/assets/eb9a007b-00f4-47b9-98e2-45e4c01932dc)
zachgoll (Migrated from github.com) approved these changes 2025-01-27 22:29:42 +08:00
zachgoll (Migrated from github.com) left a comment

Nice, thanks for tracking this down! I think your chosen solution makes sense here.

Nice, thanks for tracking this down! I think your chosen solution makes sense here.
Sign in to join this conversation.