mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
feat: create page balcao
This commit is contained in:
0
gestaoRaul/balcao/__init__.py
Normal file
0
gestaoRaul/balcao/__init__.py
Normal file
BIN
gestaoRaul/balcao/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
gestaoRaul/balcao/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
gestaoRaul/balcao/__pycache__/__init__.cpython-313.pyc
Normal file
BIN
gestaoRaul/balcao/__pycache__/__init__.cpython-313.pyc
Normal file
Binary file not shown.
BIN
gestaoRaul/balcao/__pycache__/admin.cpython-310.pyc
Normal file
BIN
gestaoRaul/balcao/__pycache__/admin.cpython-310.pyc
Normal file
Binary file not shown.
BIN
gestaoRaul/balcao/__pycache__/admin.cpython-313.pyc
Normal file
BIN
gestaoRaul/balcao/__pycache__/admin.cpython-313.pyc
Normal file
Binary file not shown.
BIN
gestaoRaul/balcao/__pycache__/apps.cpython-310.pyc
Normal file
BIN
gestaoRaul/balcao/__pycache__/apps.cpython-310.pyc
Normal file
Binary file not shown.
BIN
gestaoRaul/balcao/__pycache__/apps.cpython-313.pyc
Normal file
BIN
gestaoRaul/balcao/__pycache__/apps.cpython-313.pyc
Normal file
Binary file not shown.
BIN
gestaoRaul/balcao/__pycache__/htmx_views.cpython-310.pyc
Normal file
BIN
gestaoRaul/balcao/__pycache__/htmx_views.cpython-310.pyc
Normal file
Binary file not shown.
BIN
gestaoRaul/balcao/__pycache__/htmx_views.cpython-313.pyc
Normal file
BIN
gestaoRaul/balcao/__pycache__/htmx_views.cpython-313.pyc
Normal file
Binary file not shown.
BIN
gestaoRaul/balcao/__pycache__/models.cpython-310.pyc
Normal file
BIN
gestaoRaul/balcao/__pycache__/models.cpython-310.pyc
Normal file
Binary file not shown.
BIN
gestaoRaul/balcao/__pycache__/models.cpython-313.pyc
Normal file
BIN
gestaoRaul/balcao/__pycache__/models.cpython-313.pyc
Normal file
Binary file not shown.
BIN
gestaoRaul/balcao/__pycache__/urls.cpython-310.pyc
Normal file
BIN
gestaoRaul/balcao/__pycache__/urls.cpython-310.pyc
Normal file
Binary file not shown.
BIN
gestaoRaul/balcao/__pycache__/urls.cpython-313.pyc
Normal file
BIN
gestaoRaul/balcao/__pycache__/urls.cpython-313.pyc
Normal file
Binary file not shown.
BIN
gestaoRaul/balcao/__pycache__/views.cpython-310.pyc
Normal file
BIN
gestaoRaul/balcao/__pycache__/views.cpython-310.pyc
Normal file
Binary file not shown.
BIN
gestaoRaul/balcao/__pycache__/views.cpython-313.pyc
Normal file
BIN
gestaoRaul/balcao/__pycache__/views.cpython-313.pyc
Normal file
Binary file not shown.
3
gestaoRaul/balcao/admin.py
Normal file
3
gestaoRaul/balcao/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
gestaoRaul/balcao/apps.py
Normal file
6
gestaoRaul/balcao/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ComandasConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'balcao'
|
||||
46
gestaoRaul/balcao/htmx_views.py
Normal file
46
gestaoRaul/balcao/htmx_views.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from django.shortcuts import render, redirect
|
||||
|
||||
from comandas.models import Comanda, ProductComanda
|
||||
from products.models import Product
|
||||
from payments.models import Payments
|
||||
from typePay.models import TypePay
|
||||
|
||||
|
||||
def listProduct(request, comanda_id):
|
||||
product = request.GET.get("search-product")
|
||||
products = Product.objects.filter(name__icontains=product)
|
||||
return render(request, "htmx_components/htmx_list_products_balcao.html", {"products": products,'comanda_id':comanda_id})
|
||||
|
||||
def addProduct(request, product_id, comanda_id):
|
||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||
product_comanda.save()
|
||||
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
||||
total = 0
|
||||
for produto in consumo:
|
||||
total += produto.product.price
|
||||
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total})
|
||||
|
||||
|
||||
def removeProductComanda(request, productComanda_id):
|
||||
product_comanda = ProductComanda.objects.get(id=productComanda_id)
|
||||
consumo = ProductComanda.objects.filter(comanda=product_comanda.comanda)
|
||||
product_comanda.delete()
|
||||
total = 0
|
||||
for produto in consumo:
|
||||
total += produto.product.price
|
||||
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total})
|
||||
|
||||
|
||||
def paymentComanda(request, comanda_id):
|
||||
typePayment = TypePay.objects.get(id=1)
|
||||
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
||||
comanda = Comanda.objects.get(name='VENDA BALCÃO')
|
||||
total = 0
|
||||
for produto in consumo:
|
||||
total += produto.product.price
|
||||
removeProductComanda(request, produto.id)
|
||||
pagamento = Payments(value=total, comanda=comanda, type_pay=typePayment,description='VENDA BALÃO')
|
||||
pagamento.save()
|
||||
comanda.save()
|
||||
return redirect('comandas')
|
||||
|
||||
30
gestaoRaul/balcao/migrations/0001_initial.py
Normal file
30
gestaoRaul/balcao/migrations/0001_initial.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# Generated by Django 5.1.4 on 2024-12-10 01:19
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('clients', '0001_initial'),
|
||||
('mesas', '0001_initial'),
|
||||
('typePay', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Comanda',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('dt_open', models.DateTimeField(auto_now_add=True)),
|
||||
('dt_close', models.DateTimeField(blank=True, null=True)),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('client', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='clients.client')),
|
||||
('mesa', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mesas.mesa')),
|
||||
('type_pay', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='typePay.typepay')),
|
||||
],
|
||||
),
|
||||
]
|
||||
25
gestaoRaul/balcao/migrations/0002_productcomanda.py
Normal file
25
gestaoRaul/balcao/migrations/0002_productcomanda.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Generated by Django 5.1.4 on 2024-12-10 01:20
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('comandas', '0001_initial'),
|
||||
('products', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ProductComanda',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('data_time', models.DateTimeField(auto_now_add=True)),
|
||||
('applicant', models.CharField(blank=True, max_length=255, null=True)),
|
||||
('comanda', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='comandas.comanda')),
|
||||
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='products.product')),
|
||||
],
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,25 @@
|
||||
# Generated by Django 5.1.4 on 2024-12-20 12:36
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('comandas', '0002_productcomanda'),
|
||||
('products', '0002_product_image_product_quantity'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='comanda',
|
||||
name='status',
|
||||
field=models.CharField(default='OPEN', max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='productcomanda',
|
||||
name='product',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='products.product'),
|
||||
),
|
||||
]
|
||||
0
gestaoRaul/balcao/migrations/__init__.py
Normal file
0
gestaoRaul/balcao/migrations/__init__.py
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
27
gestaoRaul/balcao/models.py
Normal file
27
gestaoRaul/balcao/models.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# from django.db import models
|
||||
|
||||
# from clients.models import Client
|
||||
# from products.models import Product
|
||||
# from mesas.models import Mesa
|
||||
# from typePay.models import TypePay
|
||||
|
||||
# class Comanda(models.Model):
|
||||
# id = models.AutoField(primary_key=True)
|
||||
# mesa = models.ForeignKey(Mesa, on_delete=models.CASCADE)
|
||||
# type_pay = models.ForeignKey(TypePay, on_delete=models.SET_NULL, null=True)
|
||||
# dt_open = models.DateTimeField(auto_now_add=True)
|
||||
# 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)
|
||||
# status = models.CharField(max_length=255, default="OPEN")
|
||||
# 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.PROTECT)
|
||||
# applicant = models.CharField(max_length=255, null=True, blank=True)
|
||||
# def __str__(self) -> str:
|
||||
# return self.comanda.name + " - " + self.product.name
|
||||
201
gestaoRaul/balcao/templates/viewBalcao.html
Normal file
201
gestaoRaul/balcao/templates/viewBalcao.html
Normal file
@@ -0,0 +1,201 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
|
||||
|
||||
|
||||
{% block 'title' %}
|
||||
Detalhes {{comanda.name}}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
|
||||
{% block 'head' %}
|
||||
<link rel="stylesheet" href="{% static 'comandas/css/viewbalcao.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block 'body' %}
|
||||
|
||||
|
||||
<body>
|
||||
<div class="grid-container" >
|
||||
<div>
|
||||
<h1>Venda Balcão</h1>
|
||||
<div>
|
||||
<button class="primary" id="openModal" >Adicionar Produto</button>
|
||||
|
||||
<button id="pagarComanda" hx-get="{% url 'closeComanda' comanda.id %} " hx-trigger="click" hx-swap="none" onclick="imprimirConta()"
|
||||
{% if comanda.status != 'OPEN' %}
|
||||
style="display: none;"
|
||||
{% endif %}
|
||||
>Fechar Comanda</button>
|
||||
|
||||
<button id="pagarComanda" onclick="modal_payment_comanda()"
|
||||
|
||||
>Receber</button>
|
||||
|
||||
<button class="button" id="imprimirFichas" onclick="imprimirFichas()"
|
||||
|
||||
>Imprimir Fichas</button>
|
||||
|
||||
<!-- <button class="button" id="imprimirFichas" hx-get="{% url 'reopenComanda' comanda.id %} " hx-trigger="click" hx-swap="none" onclick="reloadPage()"
|
||||
{% if comanda.status == 'OPEN'%}
|
||||
style="display: none;"
|
||||
{% elif comanda.status == 'CLOSED' %}
|
||||
style="display: none;"
|
||||
{% endif %}
|
||||
>Reabrir</button> -->
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<!-- <p>Aberta em: {{comanda.dt_open|date:"D"}} {{comanda.dt_open|date:"d/m/Y - H:i"}}</p> -->
|
||||
|
||||
|
||||
<table id="list-products-comanda">
|
||||
<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>
|
||||
<td><button
|
||||
hx-get="{% url 'removeProductComanda' item.id %} " hx-trigger="click" hx-target="#list-products-comanda"
|
||||
onclick="reloadPage()">🗑️ Excluir</button></td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
{% endfor %}
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2" style="text-align: center;">Total R$ {{total}}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div id="add-produto">
|
||||
|
||||
|
||||
|
||||
<article>
|
||||
|
||||
<form id="productForm" >
|
||||
<h2>Adicionar Produto </h2>
|
||||
<input type="text" id="search-product" name="search-product" placeholder="Buscar Produto" hx-get="{% url 'listProduct' comanda.id %}" hx-trigger="keyup" hx-target="#product-list"><br>
|
||||
<div id="product-list" class="grid-list-products">
|
||||
{% for product in products %}
|
||||
|
||||
<article onclick="reloadPage()" style="background-color: #293552;" hx-get="{% url 'addProduct' product.id comanda.id %} " hx-trigger="click" hx-target="#list-products-comanda">
|
||||
{{product.name}} <br>
|
||||
R$ {{product.price}}
|
||||
</article >
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
</article>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- <dialog id="Modal-add-product" style="display: none;" >
|
||||
<article>
|
||||
|
||||
<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" placeholder="Buscar Produto" hx-get="{% url 'listProduct' comanda.id %}" hx-trigger="keyup" hx-target="#product-list"><br>
|
||||
<div id="product-list" class="grid-list-products">
|
||||
{% for product in products %}
|
||||
|
||||
<article onclick="reloadPage()" style="background-color: #293552;" hx-get="{% url 'addProduct' product.id comanda.id %} " hx-trigger="click" hx-target="#list-products-comanda">
|
||||
{{product.name}} <br>
|
||||
R$ {{product.price}}
|
||||
</article >
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
</article>
|
||||
</dialog> -->
|
||||
|
||||
|
||||
|
||||
<dialog id="remove-product-comanda" style="display: none;" >
|
||||
<article>
|
||||
<h2>Produto Excluido!</h2>
|
||||
<h1>✅</h1>
|
||||
<p>
|
||||
|
||||
</p>
|
||||
<ul>
|
||||
|
||||
</ul>
|
||||
<footer>
|
||||
<button class="secondary" onclick="removeCloseModal()">
|
||||
OK
|
||||
</button>
|
||||
<!-- <button >Excluir</button> -->
|
||||
</footer>
|
||||
</article>
|
||||
</dialog>
|
||||
|
||||
<dialog id="payment-comanda" style="display: none;" >
|
||||
<article>
|
||||
<h2>Receber</h2>
|
||||
<h1>R$ {{ total }}</h1>
|
||||
<p>
|
||||
</p>
|
||||
<ul>
|
||||
</ul>
|
||||
<footer>
|
||||
<button class="secondary" hx-get="{% url 'paymentComanda' comanda.id %} " hx-trigger="click" hx-swap="none" onclick="backPage()">
|
||||
Comfimar
|
||||
</button>
|
||||
|
||||
<button onclick="close_modal_payment_comanda()" >Cancelar</button>
|
||||
</footer>
|
||||
</article>
|
||||
</dialog>
|
||||
|
||||
|
||||
|
||||
<script src="{% static 'comandas/js/viewbalcao.js' %}"></script>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
3
gestaoRaul/balcao/tests.py
Normal file
3
gestaoRaul/balcao/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
25
gestaoRaul/balcao/urls.py
Normal file
25
gestaoRaul/balcao/urls.py
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
from django.urls import path
|
||||
|
||||
from balcao import htmx_views
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
# path('', views.comandas, name='comandas'),
|
||||
path('', views.viewBalcao, name='viewBalcao'),
|
||||
# path('createComanda/', views.createComanda, name='createComanda'),
|
||||
|
||||
]
|
||||
|
||||
|
||||
htmx_urlpatterns = [
|
||||
# path('listProduct/', htmx_views.listProduct, name='listProduct'),
|
||||
path('listProduct/<int:comanda_id>/', htmx_views.listProduct, name='listProduct'),
|
||||
path('addProduct<int:product_id>/<int:comanda_id>/', htmx_views.addProduct, name='addProduct'),
|
||||
path('removeProductComanda<int:productComanda_id>/', htmx_views.removeProductComanda, name='removeProductComanda'),
|
||||
# path('closeComanda<int:comanda_id>/', htmx_views.closeComanda, name='closeComanda'),
|
||||
# path('reopenComanda<int:comanda_id>/', htmx_views.reopenComanda, name='reopenComanda'),
|
||||
path('paymentComanda<int:comanda_id>/', htmx_views.paymentComanda, name='paymentComanda'),
|
||||
]
|
||||
|
||||
urlpatterns += htmx_urlpatterns
|
||||
36
gestaoRaul/balcao/views.py
Normal file
36
gestaoRaul/balcao/views.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from django.shortcuts import render, redirect
|
||||
|
||||
from comandas.models import Comanda, ProductComanda
|
||||
from products.models import Product
|
||||
from mesas.models import Mesa
|
||||
|
||||
|
||||
# def balcao(request):
|
||||
# comandas = Comanda.objects.filter(status__in=["OPEN", "PAYING"])
|
||||
# mesas = Mesa.objects.all()
|
||||
# return render(request, 'comandas.html', {'comandas': comandas, 'mesas': mesas})
|
||||
|
||||
|
||||
|
||||
def viewBalcao(request):
|
||||
|
||||
comanda = Comanda.objects.get(name='VENDA BALCÃO')
|
||||
consumo = ProductComanda.objects.filter(comanda=comanda.id)
|
||||
products = Product.objects.all()
|
||||
total = 0
|
||||
for produto in consumo:
|
||||
total += produto.product.price
|
||||
|
||||
return render(request, 'viewBalcao.html', {'comanda': comanda, 'consumo': consumo, 'total': total, 'products': products})
|
||||
|
||||
|
||||
|
||||
# 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')
|
||||
|
||||
Reference in New Issue
Block a user