Forecast - #10
Merged
Merged
Forecast#10
Conversation
Allow `get_combined_stats` to use an injected `now` value, fetch transactions through the last completed bucket, and compute top-category spending from both the current and preceding periods correctly. Updated tests to match the new time window and percentage-change behavior.
Update spendoo/statistics/service.py to set curr_end = now (instead of _get_next_bucket_start) and last_completed_end = min(end_date, now) (instead of _get_next_bucket_start). This prevents end boundaries from being advanced to the next bucket (which can be in the future) and ensures in-progress and last-completed buckets do not extend past the current time.
Joseph-Sameh-0
approved these changes
Jun 28, 2026
When summing empty sequences of Decimal values, the sum() function returns an integer 0 instead of a Decimal type, causing type mismatch issues. Added Decimal("0.00") as the start value to sum() calls to ensure consistent Decimal return types.
Also added a test to verify calculate_combined_stats handles empty transactions correctly.
Budget status bucket generation now stops at the provided `now` (or the current time) so future periods are excluded from status calculations. Added coverage for budget status and combined stats to verify the cutoff behavior.
Fix/statistics combined
Rename CombinedForecastBucketDto.predicted_status -> status and update ForecastService to rely on StatisticsService helpers for bucket boundaries. History/future date computation and horizon calculation were reorganized, calculate_combined_stats now receives now, and predicted bucket status is derived via stats_service._determine_budget_status. Removed the local _get_last_completed_bucket_start helper and cleaned up forecasting steps and minor formatting.
Split the combined forecast into nested financial stats, budget status, and top categories responses. Also updated forecast service return paths to populate the new response structure consistently when forecasting succeeds or falls back to historical data. Co-Authored-By: Salmamohamedd <125445879+Salmamohamedd@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.