Skip to content

feat: add occupancy percentage widget to dashboard#207

Open
errbchile wants to merge 1 commit intooscarchapp:mainfrom
errbchile:feature/dashboard-occupancy
Open

feat: add occupancy percentage widget to dashboard#207
errbchile wants to merge 1 commit intooscarchapp:mainfrom
errbchile:feature/dashboard-occupancy

Conversation

@errbchile
Copy link
Copy Markdown

feat: add occupancy percentage widget to dashboard

What

Adds a 5th widget to the dashboard showing the current occupancy rate: the percentage of rooms that have an active confirmed booking.

How

  • Formula: confirmed_bookings / total_rooms * 100, rounded to 1 decimal place
  • State filter: only Booking.NEW bookings are counted — cancelled ones (Booking.DELETED) are excluded
  • Division-by-zero guard: returns 0.0 when no rooms exist

Files changed

File Change
pms/views.py Occupancy calculation in DashboardView.get(); datetime import moved to top-level
pms/templates/dashboard.html 5th widget card (purple) rendering {{ dashboard.occupancy }}%
pms/tests.py DashboardOccupancyTest — 5 tests

Tests

Test Covers
test_occupancy_is_zero_when_no_rooms_exist Division-by-zero guard
test_occupancy_is_zero_when_no_confirmed_bookings Rooms exist, no active bookings
test_occupancy_partial_percentage 1 of 2 rooms booked → 50.0%
test_occupancy_is_100_when_all_rooms_booked All rooms booked → 100.0%
test_cancelled_bookings_not_counted DEL bookings excluded

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