diff --git a/.gitignore b/.gitignore
index 9a54ec5a8..e5720e3b1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,6 @@
*/__pycache__/**
.idea/
+*.pyc
+db.sqlite3
+staticfiles/
+.env
\ No newline at end of file
diff --git a/db.sqlite3 b/db.sqlite3
index 28c05bb8e..7dd454ece 100644
Binary files a/db.sqlite3 and b/db.sqlite3 differ
diff --git a/pms/templates/dashboard.html b/pms/templates/dashboard.html
index 10f0285cc..c699c287e 100644
--- a/pms/templates/dashboard.html
+++ b/pms/templates/dashboard.html
@@ -20,7 +20,13 @@
{{dashboard.outcoming_guests}}
Total facturado
- € {% if dashboard.invoiced.total__sum == None %}0.00{% endif %} {{dashboard.invoiced.total__sum|floatformat:2}}
+ € {% if dashboard.invoiced.total__sum == None %}0.00{% endif %}
+ {{dashboard.invoiced.total__sum|floatformat:2}}
+
+
+
+
% Ocupación
+ {{dashboard.porcentaje_ocupacion}}%
diff --git a/pms/tests.py b/pms/tests.py
index 7ce503c2d..2ad8ff79c 100644
--- a/pms/tests.py
+++ b/pms/tests.py
@@ -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)
\ No newline at end of file
diff --git a/pms/views.py b/pms/views.py
index f38563933..65515d213 100644
--- a/pms/views.py
+++ b/pms/views.py
@@ -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
}
@@ -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
}