Skip to content

Commit

Permalink
feat: No permitir crear clientes duplicados #88
Browse files Browse the repository at this point in the history
  • Loading branch information
juancruz1990 committed Jul 6, 2023
1 parent b7e1ae8 commit dd69ce6
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 25 deletions.
9 changes: 9 additions & 0 deletions venta/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

from core.models import Persona


def cliente_existe(dni_nuevo_cliente):
cliente = Persona.objects.filter(documento = dni_nuevo_cliente)
if cliente:
return True
return False
172 changes: 148 additions & 24 deletions venta/templates/venta/modals/modal_aniadir_cliente.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,151 @@
<div class="modal-xl modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">
AÑADIR CLIENTE
</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span>&times;</span>
</button>
</div>
<form action="{% url 'venta:modalAniadirCliente' %}" method="POST">
<div class="modal-body">
{% csrf_token %}
{{formulario.as_p}}

{% 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 class="modal-footer">
<button type="dismiss" class="cerrar" data-dismiss="modal">
Cerrar
</button>
<button type="submit" name="accion" class="guardar" value="hotel">
Guardar
</button>
</div>

<!-- 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 modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">
AÑADIR CLIENTE
</h5>
<a type="button" class="close" data-dismiss="modal" aria-label="Close" href="{% url 'venta:vistaCliente' %}">
<span aria-hidden="true">&times;</span>
</a>
</div>
<form action="{% url 'venta:modalAniadirCliente' %}" method="POST">
<div class="modal-body">
{% csrf_token %}
{{formulario.as_p}}
</div>
<div class="modal-footer">
<a href="{% url 'venta:vistaCliente' %}">Cerrar</a>
<button type="submit" name="accion" class="guardar" value="hotel">
Guardar
</button>
</div>
</form>
</div>
</div>


</div>
</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>
</form>
</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 %}
{% endblock %}

</body>


</html>
7 changes: 6 additions & 1 deletion venta/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from venta.helpers import cliente_existe
from venta.models import Factura, Tipo_pago
from venta.forms import ClienteForm
from django.shortcuts import render, HttpResponse, redirect, get_object_or_404
Expand Down Expand Up @@ -118,10 +119,14 @@ def vista_cliente(request):
contador=carrito.get_cantidad()
return render(request, "venta/vista_cliente.html", {"colClientes": colClientes,"vendedor":vendedorInstancia,"contador":contador})


def cliente_aniadir(request):
colClientes = Cliente.objects.all()
form = ClienteForm(request.POST)
if request.method == "POST":
dni_nuevo_cliente = request.POST['documento']
if cliente_existe(dni_nuevo_cliente):
form.add_error('documento', 'DNI ya existe en el sistema')
return render(request,"venta/modals/modal_aniadir_cliente.html",{"formulario":form})
if form.is_valid():
form.save()
form.instance.hacer_cliente()
Expand Down

0 comments on commit dd69ce6

Please sign in to comment.