Skip to content

Fix tenant-safe monthly revenue dashboard - #245

Open
ismail710 wants to merge 1 commit into
Base360-AI:mainfrom
ismail710:codex/revenue-dashboard-fixes
Open

ismail710 wants to merge 1 commit into
Base360-AI:mainfrom
ismail710:codex/revenue-dashboard-fixes

Conversation

@ismail710

@ismail710 ismail710 commented Nov 18, 2026 •

Copy link
Copy Markdown

Summary

  • Load dashboard properties for the authenticated tenant and verify property ownership in the API.
  • Scope revenue cache keys by tenant, property, and month; remove fabricated revenue fallbacks.
  • Calculate monthly revenue using the property's local timezone and round totals to cents with Decimal.
  • Add a month selector and display the reporting timezone.
    Replace hardcoded Sunset/Ocean demo login and email-based tenant fallback with the parent project’s Supabase authentication and verified company membership flow. Wire Supabase settings into Docker Compose, add ignores for local secrets and generated files,.

Comment on lines +41 to +51
timezone_name = property_row.timezone or "UTC"
zone = ZoneInfo(timezone_name)

if month is None:
latest = (await session.execute(text("""
SELECT MAX(check_in_date) AS latest
FROM reservations
WHERE property_id = :property_id AND tenant_id = :tenant_id
"""), {"property_id": property_id, "tenant_id": tenant_id})).first()
latest_date = latest.latest if latest else None
month = latest_date.astimezone(zone).strftime("%Y-%m") if latest_date else datetime.now(zone).strftime("%Y-%m")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: ZoneInfo(timezone_name) can raise unhandled ZoneInfoNotFoundError outside the validation try block, causing a 503 instead of a 422 error on invalid database timezones.
Severity: LOW

Suggested Fix

Wrap the ZoneInfo(timezone_name) lookup and latest_date.astimezone(zone) call in a try...except ZoneInfoNotFoundError block and re-raise as a ValueError with an informative message.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: backend/app/services/reservations.py#L41-L51

Potential issue: In `backend/app/services/reservations.py`, `ZoneInfo(timezone_name)` is
initialized outside of a try block at line 42, and `latest_date.astimezone(zone)` is
called at line 51 without exception handling. If an invalid timezone string exists in
the database, `ZoneInfoNotFoundError` is raised directly. Since `ZoneInfoNotFoundError`
subclasses `KeyError` rather than `ValueError`, it bypasses the 422 `ValueError` handler
in `backend/app/api/v1/dashboard.py` and is caught by the generic 503 error handler.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant