Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backend/app/services/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ async def get_revenue_summary(property_id: str, tenant_id: str) -> Dict[str, Any
"""
Fetches revenue summary, utilizing caching to improve performance.
"""
cache_key = f"revenue:{property_id}"
# cache_key = f"revenue:{property_id}"
# The cache key is fixed 112233
cache_key = f"revenue:{tenant_id}:{property_id}"

# Try to get from cache
cached = await redis_client.get(cache_key)
Expand Down
14 changes: 13 additions & 1 deletion backend/app/services/reservations.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,22 @@ async def calculate_total_revenue(property_id: str, tenant_id: str) -> Dict[str,
# Use SQLAlchemy text for raw SQL
from sqlalchemy import text

# query = text("""
# SELECT
# property_id,
# SUM(total_amount) as total_revenue,
# COUNT(*) as reservation_count
# FROM reservations
# WHERE property_id = :property_id AND tenant_id = :tenant_id
# GROUP BY property_id
# """)

# Small rounding error fixed 112233

query = text("""
SELECT
property_id,
SUM(total_amount) as total_revenue,
SUM(ROUND(total_amount, 2)) as total_revenue,
COUNT(*) as reservation_count
FROM reservations
WHERE property_id = :property_id AND tenant_id = :tenant_id
Expand Down