Skip to content

Commit

Permalink
fix : no permitir duplicados en temporadas altas en hotel #97
Browse files Browse the repository at this point in the history
  • Loading branch information
juancruz1990 committed Aug 3, 2023
1 parent cf5242d commit 99d96ba
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 44 deletions.
13 changes: 13 additions & 0 deletions hotel/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,17 @@ def habitacion_duplicada(nueva_habitacion , hotel_id , form):
form.add_error('numero', 'el numero de habitacion ya existe en este hotel')
return True
break
return False


def hay_fechas_superpuestas(fecha_inicio, fecha_fin , fecha_inicio_paquete , fecha_fin_paquete):

if((fecha_inicio <= fecha_inicio_paquete) and (fecha_fin >= fecha_fin_paquete)):
return True
else:
if(fecha_inicio_paquete <= fecha_inicio <= fecha_fin_paquete):
return True
else:
if(fecha_inicio_paquete <= fecha_fin <= fecha_fin_paquete):
return True
return False
188 changes: 158 additions & 30 deletions hotel/templates/hotel/modals/modal_temporadaHotel_crear.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,160 @@
{{formulario.media}}
<div class="modal-xl modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">AÑADIR TEMPORADA</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span>&times;</span>
</button>


{% load static %}

<html>

<head>
<link rel="icon" type="image/png" href="/static/icons/hotelIco.png">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!--SWEET ALERT CSS-->
<link rel="stylesheet" href="{% static '/css/sweetalert2.css' %}">
<!--BOOTSTRAP CSS-->
<link rel="stylesheet" href="{% static '/css/bootstrap.min.css' %}">

<!-- Bootstrap CSS para datatable-->
<link rel="stylesheet" href="{% static '/css/bootstrap.css' %}">
<link rel="stylesheet" href="{% static '/css/dataTables.bootstrap4.min.css' %}">
<!-- Bootstrap CSS para datatable-->

<!-- FONTAWESOME -->
<script src="{% static '/js/d91d4c71ff.js' %}"></script>

<!--CUSTOM CSS-->
<link rel="stylesheet" href="{% static '/css/styleBase.css' %}">
<link rel="stylesheet" href="{% static '/css/modal.css' %}">
<link rel="stylesheet" href="{% static '/css/botones.css' %}">


{% block extra_css %}

{% endblock extra_css %}
</head>

<body class="bodyComplete">


<!-- HEADER -->
<div class="container-fluid mainHeader p-3 fixed-top">
<div class="row">
<div class="col-2">
{% block header %}

{% endblock header %}

</div>
<div class="col-8">
{% block headerContenido %}
{% endblock headerContenido %}

{% block carrito %}
{% endblock carrito %}
</div>
<div class="col-2">

<button onclick="location.href='/core/logout'" style="text-decoration:none; align-items:right;"
class="rounded-1 btn btn-lg btn-outline-secondary text-white float-center mt-1 "> Cerrar Sesion
</button>

</div>
</div>
</div>
<form action="{% url 'hotel:modalCrearTemporadaHotel' hotel.pk %}" method="POST">
<div class="modal-body">
{% csrf_token %}
{{formulario}}
</div>
<div class="modal-footer">
<button type="dismiss" class="cerrar" data-dismiss="modal">
Cerrar
</button>
<button type="submit" name="accion" class="guardar" value="hotel">
Guardar
</button>

<!-- opciones + contenido -->
<div class="container-fluid position-fixed" style="top: 100px;">
<!-- CONTENIDO -->
<div class="col-12 position-relative " id="main" >
<div class="modal-xl modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">AÑADIR TEMPORADA</h5>
<a type="button" class="close" data-dismiss="modal" aria-label="Close" href="{% url 'hotel:temporadaHotel' hotel.pk %}">
<span aria-hidden="true">&times;</span>
</a>
</div>
<form action="{% url 'hotel:modalCrearTemporadaHotel' hotel.pk %}" method="POST">
<div class="modal-body" style="max-height: 400px; overflow-y: auto;">
{% csrf_token %}
{{formulario}}
</div>
<div class="modal-footer">
<a href="{% url 'hotel:temporadaHotel' hotel.pk %}">Cerrar</a>
<button type="submit" name="accion" class="guardar" value="hotel">
Guardar
</button>
</div>
</form>
</div>
</div>
</div>
</form>
</div>
</div>

<script type="text/javascript">
$(document).ready(function () {
$('.datepicker').datetimepicker();
$(".datepicker").datetimepicker({ sideBySide: true, format: 'DD/MM/YYYY'})
});
</script>
</div>


<!-- Footer -->
<div class="footer text-center mb-0 fixed-bottom">
<div class="container">
{% block footer %}

{% endblock footer %}
<p class="m-0 mbt1 text-white">&copy; UNPSJB - GRUPO 1 - DESARROLLO DE SOFTWARE</p>
</div>
</div>


<!--sweet alert2-->

<script src="{% static '/js/[email protected]' %}"></script>

<!-- Bootstrap 4.5-->
<script src="{% static '/js/jquery-3.5.1.js' %}"></script>
<script src="{% static '/js/bootstrap.bundle.js' %}"></script>

<script src="{% static '/js/bootstrap-datetimepicker.min.js' %}"></script>

<!--dataTable jquery + bootstrap + popper include-->
<script src="{% static 'js/jquery.dataTables.min.js'%}"></script>
<script src="{% static '/js/dataTables.bootstrap4.min.js'%}"></script>

<!--scripts personalizados-->
<script src="{% static '/js/main.js' %}"></script>

<!--sweet alert2-->
<script src="{% static '/js/[email protected]' %}"></script>



<!--dataTable jquery + bootstrap + popper include-->
<script src="{% static '/js/jquery.dataTables.min.js'%}"></script>
<script src="{% static '/js/dataTables.bootstrap4.min.js'%}"></script>


<!--scripts personalizados-->

<script src="{% static '/js/main.js' %}"></script>

<!--CUSTOM CSS-->
<link rel="stylesheet" href="{% static '/css/styleBase.css' %}">
<link rel="stylesheet" href="{% static '/css/modal.css' %}">
<link rel="stylesheet" href="{% static '/css/botones.css' %}">

{% block extrajs %}

<script type="text/javascript">
$(document).ready(function () {
$('.datepicker').datetimepicker();
$(".datepicker").datetimepicker({ sideBySide: true, format: 'DD/MM/YYYY' })
});
</script>
{% endblock %}

</body>


</html>






22 changes: 8 additions & 14 deletions hotel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.http import request, JsonResponse
from django.http.response import HttpResponseRedirect
from django.shortcuts import render, HttpResponse, redirect, get_object_or_404
from hotel.helpers import habitacion_duplicada
from hotel.helpers import habitacion_duplicada, hay_fechas_superpuestas
from hotel.models import Habitacion, Hotel, PrecioPorTipo, TemporadaAlta, PaqueteTuristico
from .forms import HabitacionForm, HotelForm, ServicioForm, TemporadaHotelForm, AgregarTipoAHotelForm, HabitacionForm, PaqueteTuristicoForm, VendedorHotelForm
from django.contrib.auth.forms import AuthenticationForm
Expand Down Expand Up @@ -222,6 +222,13 @@ def temporadaHotelCrear(request, hotel):
hotelInstancia=get_object_or_404(Hotel, pk=hotel)
if request.method == "POST":
form = TemporadaHotelForm(request.POST)
temporadas = TemporadaAlta.objects.filter(hotel = hotel )
fecha_inicio = request.POST["inicio"]
fecha_fin = request.POST["fin"]
for temporada in temporadas:
if (hay_fechas_superpuestas(fecha_inicio ,fecha_fin , str(temporada.inicio), str(temporada.fin))):
form.add_error('inicio', 'las fechas se superponen con alguna existentes')
return render(request, "hotel/modals/modal_temporadaHotel_crear.html", { "hotel": hotelInstancia, "formulario": form})
if form.is_valid():
form = TemporadaHotelForm(request.POST)
temporadaInstancia=form.save(commit=False)
Expand Down Expand Up @@ -264,19 +271,6 @@ def paqueteTuristicoHotel(request,hotel):
return render(request, "hotel/vistaHotelAdmin.html",{"hotel":hotelInstancia,"administrador":personaInstancia })


def hay_fechas_superpuestas(fecha_inicio, fecha_fin , fecha_inicio_paquete , fecha_fin_paquete):

if((fecha_inicio <= fecha_inicio_paquete) and (fecha_fin >= fecha_fin_paquete)):
return True
else:
if(fecha_inicio_paquete <= fecha_inicio <= fecha_fin_paquete):
return True
else:
if(fecha_inicio_paquete <= fecha_fin <= fecha_fin_paquete):
return True
return False


def paqueteTuristicoHotelCrear(request, hotel):
id_hotel = hotel
form = PaqueteTuristicoForm(request.POST)
Expand Down

0 comments on commit 99d96ba

Please sign in to comment.