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
67 changes: 44 additions & 23 deletions pms/templates/dashboard.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
{% extends "main.html"%}

{% block content %}
{% extends "main.html"%} {% block content %}
<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>
<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: #87cefa"
>
<h5 class="small">Procentaje de ocupación</h5>
<h1 class="dashboard-value">
{{ dashboard.occupancy_perc|floatformat:2}}%
</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>
</div>
{% endblock content%}
{% endblock content%}
58 changes: 56 additions & 2 deletions pms/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
from django.test import TestCase

from django.test import TestCase, override_settings
from .models import Room, Room_type, Booking,Customer
from django.utils import timezone
from django.urls import reverse
# Create your tests here.

@override_settings(STATICFILES_STORAGE='django.contrib.staticfiles.storage.StaticFilesStorage')
class DashboardOccupancyPercentageTest(TestCase):
def setUp(self):
self.room_type = Room_type.objects.create(name='Doble', price=30, max_guests=2)
self.customer = Customer.objects.create(name="TestPerson", email="person@test.com", phone="123123123")
for i in range(4):
Room.objects.create(name=f"Room {i}", room_type=self.room_type)

Booking.objects.create(
checkin=timezone.now().date(),
checkout=timezone.now().date(),
room=Room.objects.first(),
state="NEW",
guests=1,
customer=self.customer,
total=30,
code="R01"
)
Booking.objects.create(
checkin=timezone.now().date(),
checkout=timezone.now().date(),
room=Room.objects.last(),
state="NEW",
guests=2,
customer=self.customer,
total=30,
code="R02"
)
Booking.objects.create(
checkin=timezone.now().date(),
checkout=timezone.now().date(),
room=None,
state="DEL",
guests=1,
customer=self.customer,
total=0.0,
code="R03"
)

"""Verifica que el calculo de porcentaje de ocupacion sea el correcto."""
def test_occupancy_precentage(self):
response = self.client.get(reverse('dashboard'))
occupancy = response.context['dashboard']['occupancy_perc']
self.assertEqual(occupancy, 50.00)
self.assertContains(response, "50.00%")

"""Verifica que no da error al dividir por 0 en caso de no existir habitaciones."""
def test_divide_by_zero(self):
Room.objects.all().delete()
response = self.client.get(reverse('dashboard'))
self.assertEqual(response.context['dashboard']['occupancy_perc'], 0)
14 changes: 11 additions & 3 deletions pms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .form_dates import Ymd
from .forms import *
from .models import Room
from .models import Room, Booking
from .reservation_code import generate


Expand Down Expand Up @@ -177,6 +177,7 @@ def post(self, request, pk):
class DashboardView(View):
def get(self, request):
from datetime import date, time, datetime

today = date.today()

# get bookings created today
Expand Down Expand Up @@ -208,14 +209,21 @@ def get(self, request):
.exclude(state="DEL")
.aggregate(Sum('total'))
)

# get occupancy percentage
total_rooms = Room.objects.count()
confirmed_bookings = Booking.objects.filter(checkin=today, state="NEW").count()
occupancy_perc = 0
if total_rooms > 0:
occupancy_perc = (confirmed_bookings / total_rooms) * 100

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

'invoiced': invoiced,
'occupancy_perc': occupancy_perc
}

context = {
Expand Down