Fix tenant-safe monthly revenue reporting - #134
Open
giriss wants to merge 5 commits into
Open
Conversation
- round aggregated revenue to cents using ROUND_HALF_UP - return revenue totals as fixed-point strings - reuse the shared database pool
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.
Loom Videos
Part 1 - 5 minutes: https://www.loom.com/share/202407d70af847e2a917966c1956ed99
Part 2 - 4 minutes: https://www.loom.com/share/05bbcb4e47f2437e85055fa0d9ebbe14
Sorry my Loom free version only allows up to 5 minutes videos, so I had to do it in 2 parts.
Overview
This PR fixes the revenue dashboard issues reported by Sunset Properties, Ocean Rentals, and the finance team.
The changes focus on three areas:
What changed
Tenant-safe caching
Revenue cache keys now include all relevant report dimensions:
This prevents properties with the same ID in different tenants from sharing cached revenue data.
Timezone-aware monthly reporting
The dashboard API now accepts a month in
YYYY-MMformat and calculates revenue using the property’s configured timezone.The query uses local calendar-month boundaries with a half-open interval:
This ensures reservations near UTC month boundaries are assigned to the correct local reporting month.
For example, Sunset’s reservation at
2024-02-29 23:30 UTCoccurs on March 1 in Paris and is therefore included in the March report.Exact financial totals
Revenue remains a
Decimalafter database aggregation and is rounded once to cents usingROUND_HALF_UP.The API returns a fixed-point string such as:
{ "total_revenue": "2250.00" }The frontend displays this value directly instead of applying JavaScript floating-point arithmetic.
Dashboard filters
The dashboard now includes month and currency filters and passes them through the API client to the backend.
The previous client-controlled simulated tenant header has also been removed.
Expected results
For Sunset Properties,
prop-001in March 2024 now reports:Revenue cache entries are isolated by tenant and reporting period, and totals retain consistent decimal precision across the backend and frontend.
Test plan
prop-001returns2250.00with 4 reservationsImplementation notes
The solution keeps the existing architecture and introduces no additional frontend dependencies. PostgreSQL handles timezone boundaries, while Python
Decimalremains the source of truth for financial rounding.Screenshot:

