create comanda | detalhe comanda

This commit is contained in:
2024-12-12 21:33:04 -03:00
parent 2f84ca97c3
commit a3bb7bb674
15 changed files with 284 additions and 21 deletions

View File

@@ -14,10 +14,14 @@ class Comanda(models.Model):
dt_close = models.DateTimeField(null=True, blank=True)
client = models.ForeignKey(Client, on_delete=models.SET_NULL, null=True, blank=True)
name = models.CharField(max_length=255)
def __str__(self) -> str:
return self.name
class ProductComanda(models.Model):
id = models.AutoField(primary_key=True)
comanda = models.ForeignKey(Comanda, on_delete=models.CASCADE)
data_time = models.DateTimeField(auto_now_add=True)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
applicant = models.CharField(max_length=255, null=True, blank=True)
applicant = models.CharField(max_length=255, null=True, blank=True)
def __str__(self) -> str:
return self.comanda.name + " - " + self.product.name

View File

@@ -11,12 +11,15 @@ Comandas{% endblock %}
{% endblock %}
{% block 'body' %}
body>
<div class="grid-container">
<body>
<div class="grid-container">
<button class="button" id="openModal">Abrir Comanda</button>
{% for comanda in comandas %}
<div href="{% url 'viewcomanda' %}?parametro={{ comanda.id }}" class="card"> <a href="{% url 'viewcomanda' %}?parametro={{ comanda.id }}">{{comanda.name}} </a>
<div href="{% url 'viewcomanda' %}?parametro={{ comanda.id }}" class="card">
<a href="{% url 'viewcomanda' %}?parametro={{ comanda.id }}">{{comanda.name}} </a> <br>
<a href="{% url 'viewcomanda' %}?parametro={{ comanda.id }}">{{comanda.mesa}}</a>
</div>
@@ -25,7 +28,32 @@ body>
</div>
<div class="modal" id="Modal-create-comanda">
<div class="modal-content">
<form id="form-comanda" method="post" action="{% url 'createComanda' %}">
{% csrf_token %}
<h2>Abrir Comanda</h2>
<input type="text" id="name-comanda" name="name-comanda" required placeholder="Nome"><br>
<select name="select-mesa" >
{% for mesa in mesas %}
<option value="{{mesa.id}}">{{mesa.name}}</option>
{% endfor %}
<!-- <option value="opcao1">Opção 1</option>
<option value="opcao2">Opção 2</option>
<option value="opcao3" >Opção 3</option> -->
</select>
<button type="submit">Abrir</button>
<button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>
</form>
</div>
</div>
</body>
<script src="{% static 'comandas/js/comandas.js' %}"></script>

View File

@@ -5,22 +5,73 @@
{% block 'title' %}
Comandas{% endblock %}
Detalhes {{comanda.name}}
{% endblock %}
{% block 'head' %}
<link rel="stylesheet" href="{% static 'comandas/css/viewcomanda.css' %}">
{% endblock %}
{% block 'body' %}
body>
<body>
<div class="grid-container">
<h4>{{comanda.id}}</h4>
<h4>{{comanda.name}}</h4>
<h4>{{comanda.mesa}}</h4>
<h4>{{comanda.dt_open}}</h4>
<button class="button" id="openModal">Adicionar Produto</button>
<!-- <p>{{comanda.id}}</p> -->
<p>{{comanda.name}}</p>
<p>{{comanda.mesa}}</p>
<p>{{comanda.dt_open}}</p>
<table>
<tr>
<th style="text-align: left;">Produto</th>
<th style="text-align: left;">Preço</th>
</tr>
{% for item in consumo%}
<tr>
<td>{{item.product.name}}</td>
<td>R$ {{item.product.price}}</td>
</tr>
{% endfor %}
<tfoot>
<tr>
<td colspan="2" style="text-align: center;">Total R$ {{total}}</td>
</tr>
</tfoot>
</table>
</div>
<div class="modal" id="Modal-add-product">
<div class="modal-content">
<form id="productForm" >
<h2>Adicionar Produto <button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button></h2>
<input type="text" id="search-product" name="search-product" required placeholder="Buscar Produto"><br>
<!-- <input type="number" step="1" id="product-qtd" name="qtd" required placeholder="Quantidade"><br> -->
<!-- <button type="submit">Salvar</button> -->
</form>
</div>
</div>
<script src="{% static 'comandas/js/viewcomanda.js' %}"></script>
</body>

View File

@@ -5,6 +5,7 @@ from . import views
urlpatterns = [
path('', views.comandas, name='comandas'),
path('viewcomanda/', views.viewComanda, name='viewcomanda'),
path('createComanda/', views.createComanda, name='createComanda'),

View File

@@ -1,12 +1,14 @@
from django.shortcuts import render, redirect
from comandas.models import Comanda
from comandas.models import Comanda, ProductComanda
from mesas.models import Mesa
# Create your views here.
def comandas(request):
comandas = Comanda.objects.all()
return render(request, 'comandas.html', {'comandas': comandas})
mesas = Mesa.objects.all()
return render(request, 'comandas.html', {'comandas': comandas, 'mesas': mesas})
@@ -15,5 +17,27 @@ def viewComanda(request):
id = request.GET.get('parametro')
comanda_id = int(id)
comanda = Comanda.objects.get(id=comanda_id)
consumo = ProductComanda.objects.filter(comanda=comanda_id)
total = 0
for produto in consumo:
total += produto.product.price
return render(request, 'viewcomanda.html', {'comanda': comanda})
return render(request, 'viewcomanda.html', {'comanda': comanda, 'consumo': consumo, 'total': total})
def addProduct(request):
pass
# id = request.GET.get('parametro')
# comanda_id = int(id)
# comanda = Comanda.objects.get(id=comanda_id)
# return render(request, 'addproduct.html', {'comanda': comanda})
def createComanda(request):
name = request.POST.get('name-comanda')
mesa_id = int(request.POST.get('select-mesa')[0])
mesa = Mesa.objects.get(id=mesa_id)
comanda = Comanda(name=name, mesa=mesa)
comanda.save()
return redirect('comandas')