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: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
*/__pycache__/**
.idea/
*.pyc
db.sqlite3
staticfiles/
.env
Binary file modified db.sqlite3
Binary file not shown.
8 changes: 7 additions & 1 deletion pms/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ <h1 class="dashboard-value">{{dashboard.outcoming_guests}}</h1>

<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>
<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: #9b59b6;">
<h5 class="small">% Ocupación</h5>
<h1 class="dashboard-value">{{dashboard.porcentaje_ocupacion}}%</h1>
</div>
</div>
</div>
Expand Down
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 .models import Room, Room_type, Booking, Customer

# Create your tests here.
class RoomsViewTest(TestCase):

def setUp(self):
room_type = Room_type.objects.create(
name="Simple",
price=20,
max_guests=1
)
Room.objects.create(name="Room 1.1", description="", room_type=room_type)
Room.objects.create(name="Room 1.2", description="", room_type=room_type)
Room.objects.create(name="Room 2.1", description="", room_type=room_type)

def test_sin_filtro(self):
response = self.client.get('/rooms/')
self.assertEqual(len(response.context['rooms']), 3)

def test_con_filtro(self):
response = self.client.get('/rooms/?name_room=Room 1')
self.assertEqual(len(response.context['rooms']), 2)

def test_filtro_sin_resultados(self):
response = self.client.get('/rooms/?name_room=Room 99')
self.assertEqual(len(response.context['rooms']), 0)


class DashboardViewTest(TestCase):

def setUp(self):
from datetime import date
room_type = Room_type.objects.create(name="Simple", price=20, max_guests=1)
room = Room.objects.create(name="Room 1.1", description="", room_type=room_type)
customer = Customer.objects.create(name="Test", email="test@test.com", phone="123")
Booking.objects.create(
checkin=date(2026, 5, 1),
checkout=date(2026, 5, 3),
room=room,
customer=customer,
guests=1,
total=40,
code="TEST0001",
state="NEW"
)

def test_porcentaje_ocupacion(self):
response = self.client.get('/dashboard/')
self.assertEqual(response.context['dashboard']['porcentaje_ocupacion'], 100.0)
17 changes: 14 additions & 3 deletions pms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,21 @@ def get(self, request):
.exclude(state="DEL")
.aggregate(Sum('total'))
)

reservas_confirmadas = Booking.objects.filter(state="NEW").count()
total_habitaciones = Room.objects.count()
if total_habitaciones > 0:
porcentaje_ocupacion = round((reservas_confirmadas / total_habitaciones) * 100, 2)
else:
porcentaje_ocupacion = 0

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

}

Expand All @@ -238,8 +246,11 @@ def get(self, request, pk):

class RoomsView(View):
def get(self, request):
# renders a list of rooms
rooms = Room.objects.all().values("name", "room_type__name", "id")
name_room = request.GET.get('name_room', '')
if name_room:
rooms = Room.objects.filter(name__icontains=name_room).values("name", "room_type__name", "id")
else:
rooms = Room.objects.all().values("name", "room_type__name", "id")
context = {
'rooms': rooms
}
Expand Down