feat: acossiar comandas fiados a conta client

This commit is contained in:
2025-02-19 16:49:24 -03:00
parent 456fba3d6a
commit d2ab8212b9
14 changed files with 111 additions and 6 deletions

View File

@@ -34,7 +34,7 @@ Detalhes {{comanda.name}}
{% endif %}
>Fechar Conta</button>
{% if comanda.status == 'PAYING' %}
{% if comanda.status == 'PAYING' or comanda.status == 'FIADO'%}
<button class="btn-secondary" id="pagarComanda" onclick="modal_payment_comanda()">Receber</button>
{% else %}
@@ -207,9 +207,11 @@ Detalhes {{comanda.name}}
<div style="display: flex;gap: 10px;">
<button type="submit" class="btn-secondary" onclick="backPage()">Receber</button>
{% if comanda.status != 'FIADO' %}
<button type="button" class="btn-primary" onclick=" modal_conta_client()">
Conta
</button>
{% endif %}
<button type="button" class="btn-cancel" onclick="close_modal_payment_comanda()">Cancelar</button>
</div>
</footer>

View File

@@ -1,6 +1,8 @@
from decimal import Decimal
from django import template
from comandas.models import Comanda, ProductComanda
from payments.models import Payments
register = template.Library()
@@ -8,10 +10,18 @@ register = template.Library()
def filter_total(value):
id = value
comanda_id = int(id)
totalParcial = Decimal(0)
comanda = Comanda.objects.get(id=comanda_id)
consumo = ProductComanda.objects.filter(comanda=comanda_id)
total = 0
parcial = Payments.objects.filter(comanda=comanda)
for p in parcial:
totalParcial += p.value
total = Decimal(0)
for produto in consumo:
total += produto.product.price
taxa = round(total * Decimal(0.1), 2)
total = (total + taxa) - totalParcial
return f'R$ {total}'

View File

@@ -87,12 +87,12 @@ def addContaCliente(request):
comandaId = int(request.POST.get('idComanda'))
clientId = int(request.POST.get('select-client'))
valor = float(request.POST.get('valor-conta').replace(',','.'))
comanda = Comanda.objects.get(id=comandaId)
client = Client.objects.get(id=clientId)
client.debt = client.debt + Decimal(valor)
# client.debt = Decimal(0)
comanda.client = client
comanda.status = 'CLOSED'
comanda.dt_close = timezone.now()
comanda.status = 'FIADO'
client.save()
comanda.save()
return redirect('comandas')