feat: criado funcções de movimentação de estoque

This commit is contained in:
2025-07-22 18:22:41 -03:00
parent a9289cb28d
commit 37428e8cc7
15 changed files with 164 additions and 23 deletions

View File

@@ -6,7 +6,7 @@ from django.contrib.auth.models import User
from comandas.models import Comanda, ProductComanda
from comandas.models import Comanda, ProductComanda, StockMovementType, StockMovement
from mesas.models import Mesa
from products.models import Product
from payments.models import Payments
@@ -30,7 +30,19 @@ def addProductBalcao(request, product_id, comanda_id, qtd):
for i in range(qtd):
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
product_comanda.save()
Product.subStock(Product.objects.get(id=product_id), qtd)
product = Product.objects.get(id=product_id)
comanda = Comanda.objects.get(id=comanda_id)
user = User.objects.get(id=request.user.id)
typeMovement = StockMovementType.objects.get(name="Venda - Balcao")
StockMovement.subTransactionStock(
product=product,
movement_type=typeMovement,
comanda=comanda,
user=user,
qtd=1,
obs= "Vendido no balcão"
)
consumo = ProductComanda.objects.filter(comanda=comanda_id)
total = 0
@@ -44,7 +56,20 @@ def addProductBalcaoTeclado(request, product_id, comanda_id, qtd):
for i in range(qtd):
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
product_comanda.save()
Product.subStock(Product.objects.get(id=product_id), qtd)
product = Product.objects.get(id=product_id)
comanda = Comanda.objects.get(id=comanda_id)
user = User.objects.get(id=request.user.id)
typeMovement = StockMovementType.objects.get(name="Venda - Balcao")
StockMovement.subTransactionStock(
product=product,
movement_type=typeMovement,
comanda=comanda,
user=user,
qtd=1,
obs= "Vendido no balcão"
)
consumo = ProductComanda.objects.filter(comanda=comanda_id)
total = 0
for produto in consumo:
@@ -54,9 +79,23 @@ def addProductBalcaoTeclado(request, product_id, comanda_id, qtd):
@group_required(groupName='Garçom')
def removeProductBalcao(request, productComanda_id):
product_comanda = ProductComanda.objects.get(id=productComanda_id)
comanda = product_comanda.comanda
product = product_comanda.product
user = User.objects.get(id=request.user.id)
typeMovement = StockMovementType.objects.get(name="Estorno")
consumo = ProductComanda.objects.filter(comanda=product_comanda.comanda)
StockMovement.sumTransactionStock(
product=product,
movement_type=typeMovement,
comanda=comanda,
user=user,
qtd=1,
obs= "Excluido do balcão"
)
product_comanda.delete()
Product.addStock(Product.objects.get(id=product_comanda.product.id), 1)
total = 0
for produto in consumo: