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
6 changes: 4 additions & 2 deletions .idea/testbookingengine.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 23 additions & 20 deletions pms/templates/dashboard.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
{% extends "main.html"%}

{% block content %}
<h1>Dashboard</h1>
<div class="card">
<h1>Dashboard</h1>
<div class="card">
<h5 class="card-header">Hoy</h5>
<div class="d-flex justify-content-evenly pt-5 pb-5">
<div class="card text-white p-3 card-customization" style="background-color: #1000ff;">
<h5 class="small">Reservas hechas</h5>
<h1 class="dashboard-value">{{dashboard.new_bookings}}</h1>
</div>
<div class="card text-white p-3 card-customization" style="background-color: #00ab74;">
<h5 class="small">Huéspedes ingresando</h5>
<h1 class="dashboard-value">{{dashboard.incoming_guests}}</h1>
</div>
<div class="card text-white p-3 card-customization" style="background-color: #eeb258;">
<h5 class="small">Huéspedes saliendo</h5>
<h1 class="dashboard-value">{{dashboard.outcoming_guests}}</h1>
</div>

<div class="card text-white p-3 card-customization" style="background-color: #ff7f7f;">
<h5 class="small">Total facturado</h5>
<h1 class="dashboard-value">€ {% if dashboard.invoiced.total__sum == None %}0.00{% endif %} {{dashboard.invoiced.total__sum|floatformat:2}}</h1>
</div>
<div class="card text-white p-3 card-customization" style="background-color: #1000ff;">
<h5 class="small">Reservas hechas</h5>
<h1 class="dashboard-value">{{dashboard.new_bookings}}</h1>
</div>
<div class="card text-white p-3 card-customization" style="background-color: #00ab74;">
<h5 class="small">Huéspedes ingresando</h5>
<h1 class="dashboard-value">{{dashboard.incoming_guests}}</h1>
</div>
<div class="card text-white p-3 card-customization" style="background-color: #eeb258;">
<h5 class="small">Huéspedes saliendo</h5>
<h1 class="dashboard-value">{{dashboard.outcoming_guests}}</h1>
</div>
<div class="card text-white p-3 card-customization" style="background-color: #6f42c1;">
<h5 class="small">% ocupación</h5>
<h1 class="dashboard-value">{{dashboard.occupation_percentage|floatformat:2}}%</h1>
</div>
<div class="card text-white p-3 card-customization" style="background-color: #ff7f7f;">
<h5 class="small">Total facturado</h5>
<h1 class="dashboard-value">€ {% if dashboard.invoiced.total__sum == None %}0.00{% endif %} {{dashboard.invoiced.total__sum|floatformat:2}}</h1>
</div>
</div>
</div>
</div>
{% endblock content%}
48 changes: 47 additions & 1 deletion pms/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
from django.test import TestCase
from django.test import TestCase, override_settings
from django.urls import reverse

from pms.models import Room, Room_type, Customer, Booking


# Create your tests here.
@override_settings(STATICFILES_STORAGE="django.contrib.staticfiles.storage.StaticFilesStorage")
class DashboardViewTest(TestCase):
def setUp(self):
room_type = Room_type.objects.create(
name="Single",
max_guests=1,
price=20
)

room_1 = Room.objects.create(name="Room 1.1", room_type=room_type)
Room.objects.create(name="Room 1.2", room_type=room_type)

customer = Customer.objects.create(
name="John Doe",
email="john@example.com",
phone="123456789"
)

Booking.objects.create(
room=room_1,
customer=customer,
checkin="2022-01-01",
checkout="2022-01-02",
guests=1,
total=20,
code="ABC123",
state="NEW"
)

def test_dashboard_shows_occupation_percentage(self):
response = self.client.get(reverse("dashboard"))

self.assertEqual(response.status_code, 200)
self.assertContains(response, "% ocupación")
self.assertContains(response, "50.00%")

def test_dashboard_shows_zero_occupation_when_no_rooms_exist(self):
response = self.client.get(reverse("dashboard"))

self.assertEqual(response.status_code, 200)
self.assertContains(response, "% ocupación")
self.assertContains(response, "0.00%")
14 changes: 12 additions & 2 deletions pms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,24 @@ def get(self, request):
.exclude(state="DEL")
.aggregate(Sum('total'))
)
# calculate the occupation percentage
total_rooms = Room.objects.count()

# get the total number of confirmed bookings
confirmed_bookings = Booking.objects.filter(state="NEW").count()

# prevent division by zero when no rooms exist
occupation_percentage = 0
if total_rooms > 0:
occupation_percentage = (confirmed_bookings / total_rooms) * 100

# preparing context data
dashboard = {
'new_bookings': new_bookings,
'incoming_guests': incoming,
'outcoming_guests': outcoming,
'invoiced': invoiced

'invoiced': invoiced,
'occupation_percentage': occupation_percentage
}

context = {
Expand Down