feat: pagamento

This commit is contained in:
2024-12-20 16:47:45 -03:00
parent 859393406d
commit 2bb17b6e77
16 changed files with 153 additions and 9 deletions

View File

@@ -1,7 +1,9 @@
from django.shortcuts import render, redirect
from django.shortcuts import render, redirect, HttpResponse
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):
@@ -29,9 +31,30 @@ def removeProductComanda(request, productComanda_id):
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total})
def closeComanda(request, comanda_id):
# id = request.POST.get('id-comanda')
# comanda_id = int(id)
comanda = Comanda.objects.get(id=comanda_id)
comanda.status = "PAYING"
comanda.save()
return redirect('comandas')
# return redirect('back')
def reopenComanda(request, comanda_id):
comanda = Comanda.objects.get(id=comanda_id)
if comanda.status == 'CLOSED':
pass
else:
comanda.status = "OPEN"
comanda.save()
# return redirect('back')
def paymentComanda(request, comanda_id):
typePayment = TypePay.objects.get(id=1)
consumo = ProductComanda.objects.filter(comanda=comanda_id)
comanda = Comanda.objects.get(id=comanda_id)
total = 0
for produto in consumo:
total += produto.product.price
pagamento = Payments(value=total, comanda=comanda, type_pay=typePayment,description='tipo de pagamento mokado')
pagamento.save()
comanda.status = 'CLOSED'
comanda.save()
return redirect('comandas')