mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 05:25:40 +00:00
feat: criado funcções de movimentação de estoque
This commit is contained in:
Binary file not shown.
@@ -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 mesas.models import Mesa
|
||||||
from products.models import Product
|
from products.models import Product
|
||||||
from payments.models import Payments
|
from payments.models import Payments
|
||||||
@@ -30,7 +30,19 @@ def addProductBalcao(request, product_id, comanda_id, qtd):
|
|||||||
for i in range(qtd):
|
for i in range(qtd):
|
||||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||||
product_comanda.save()
|
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)
|
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
||||||
total = 0
|
total = 0
|
||||||
@@ -44,7 +56,20 @@ def addProductBalcaoTeclado(request, product_id, comanda_id, qtd):
|
|||||||
for i in range(qtd):
|
for i in range(qtd):
|
||||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||||
product_comanda.save()
|
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)
|
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
||||||
total = 0
|
total = 0
|
||||||
for produto in consumo:
|
for produto in consumo:
|
||||||
@@ -54,9 +79,23 @@ def addProductBalcaoTeclado(request, product_id, comanda_id, qtd):
|
|||||||
@group_required(groupName='Garçom')
|
@group_required(groupName='Garçom')
|
||||||
def removeProductBalcao(request, productComanda_id):
|
def removeProductBalcao(request, productComanda_id):
|
||||||
product_comanda = ProductComanda.objects.get(id=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)
|
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_comanda.delete()
|
||||||
Product.addStock(Product.objects.get(id=product_comanda.product.id), 1)
|
|
||||||
|
|
||||||
total = 0
|
total = 0
|
||||||
for produto in consumo:
|
for produto in consumo:
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,9 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from comandas.models import Comanda, ProductComanda
|
from comandas.models import Comanda, ProductComanda, StockMovement, StockMovementType
|
||||||
|
|
||||||
admin.site.register(Comanda)
|
admin.site.register(Comanda)
|
||||||
admin.site.register(ProductComanda)
|
admin.site.register(ProductComanda)
|
||||||
|
admin.site.register(StockMovementType)
|
||||||
|
admin.site.register(StockMovement)
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ from datetime import date
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from comandas.models import Comanda, ProductComanda
|
|
||||||
|
from comandas.models import Comanda, ProductComanda, StockMovementType, StockMovement
|
||||||
from orders.models import Order
|
from orders.models import Order
|
||||||
from products.models import Product
|
from products.models import Product
|
||||||
from payments.models import Payments, somar
|
from payments.models import Payments, somar
|
||||||
@@ -37,15 +39,27 @@ def removeProductComanda(request, productComanda_id):
|
|||||||
'taxa': False
|
'taxa': False
|
||||||
}
|
}
|
||||||
product_comanda = ProductComanda.objects.get(id=productComanda_id)
|
product_comanda = ProductComanda.objects.get(id=productComanda_id)
|
||||||
comanda = Comanda.objects.get(id= product_comanda.comanda.id)
|
comanda = product_comanda.comanda
|
||||||
|
product = product_comanda.product
|
||||||
|
user = User.objects.get(id=request.user.id)
|
||||||
|
typeMovement = StockMovementType.objects.get(name="Estorno")
|
||||||
|
|
||||||
if comanda.status == 'OPEN':
|
if comanda.status == 'OPEN':
|
||||||
parcial = Payments.objects.filter(comanda=comanda)
|
parcial = Payments.objects.filter(comanda=comanda)
|
||||||
consumo = ProductComanda.objects.filter(comanda=comanda)
|
consumo = ProductComanda.objects.filter(comanda=comanda)
|
||||||
valores = somar(consumo,comanda)
|
valores = somar(consumo,comanda)
|
||||||
if product_comanda.product.cuisine == True:
|
if product_comanda.product.cuisine == True:
|
||||||
order = Order.objects.get(productComanda=product_comanda)
|
order = Order.objects.get(productComanda=product_comanda)
|
||||||
|
|
||||||
|
StockMovement.sumTransactionStock(
|
||||||
|
product=product,
|
||||||
|
movement_type=typeMovement,
|
||||||
|
comanda=comanda,
|
||||||
|
user=user,
|
||||||
|
qtd=1,
|
||||||
|
obs= "Excluido da comanda"
|
||||||
|
)
|
||||||
product_comanda.delete()
|
product_comanda.delete()
|
||||||
Product.addStock(Product.objects.get(id=product_comanda.product.id), 1)
|
|
||||||
|
|
||||||
msg = JsonResponse({
|
msg = JsonResponse({
|
||||||
'type': 'broadcast',
|
'type': 'broadcast',
|
||||||
@@ -60,8 +74,15 @@ def removeProductComanda(request, productComanda_id):
|
|||||||
consumo = ProductComanda.objects.filter(comanda=comanda)
|
consumo = ProductComanda.objects.filter(comanda=comanda)
|
||||||
valores = somar(consumo,comanda)
|
valores = somar(consumo,comanda)
|
||||||
else:
|
else:
|
||||||
|
StockMovement.sumTransactionStock(
|
||||||
|
product=product,
|
||||||
|
movement_type=typeMovement,
|
||||||
|
comanda=comanda,
|
||||||
|
user=user,
|
||||||
|
qtd=1,
|
||||||
|
obs= "Excluido da comanda"
|
||||||
|
)
|
||||||
product_comanda.delete()
|
product_comanda.delete()
|
||||||
Product.addStock(Product.objects.get(id=product_comanda.product.id), 1)
|
|
||||||
consumo = ProductComanda.objects.filter(comanda=comanda)
|
consumo = ProductComanda.objects.filter(comanda=comanda)
|
||||||
valores = somar(consumo,comanda)
|
valores = somar(consumo,comanda)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from django.db.models import Count, F
|
|||||||
|
|
||||||
|
|
||||||
from clients.models import Client
|
from clients.models import Client
|
||||||
from products.models import Product
|
from products.models import Product, ProductComponent
|
||||||
from mesas.models import Mesa
|
from mesas.models import Mesa
|
||||||
from typePay.models import TypePay
|
from typePay.models import TypePay
|
||||||
|
|
||||||
@@ -77,5 +77,75 @@ class StockMovement(models.Model):
|
|||||||
f"({self.movement_type.name}) em {self.movement_date.strftime('%d/%m/%Y %H:%M')}"
|
f"({self.movement_type.name}) em {self.movement_date.strftime('%d/%m/%Y %H:%M')}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def subTransactionStock(product:Product,
|
||||||
|
movement_type:StockMovementType,
|
||||||
|
comanda:Comanda,
|
||||||
|
obs:str,
|
||||||
|
user:User=None,
|
||||||
|
qtd:int=1):
|
||||||
|
|
||||||
|
components = ProductComponent.objects.filter(composite_product=product)
|
||||||
|
if components.exists():
|
||||||
|
for component in components:
|
||||||
|
movi = StockMovement.objects.create(
|
||||||
|
product=component.component_product ,
|
||||||
|
related_comanda=comanda,
|
||||||
|
user=user,
|
||||||
|
movement_type=movement_type,
|
||||||
|
quantity=-component.quantity_required,
|
||||||
|
observation=obs
|
||||||
|
)
|
||||||
|
movi.save()
|
||||||
|
component.component_product.quantity -= component.quantity_required
|
||||||
|
component.component_product.save()
|
||||||
|
|
||||||
|
movi = StockMovement.objects.create(
|
||||||
|
product=product ,
|
||||||
|
related_comanda=comanda,
|
||||||
|
user=user,
|
||||||
|
movement_type=movement_type,
|
||||||
|
quantity=-qtd,
|
||||||
|
observation=obs
|
||||||
|
)
|
||||||
|
movi.save()
|
||||||
|
product.quantity -= qtd
|
||||||
|
product.save()
|
||||||
|
|
||||||
|
|
||||||
|
def sumTransactionStock(product:Product,
|
||||||
|
movement_type:StockMovementType,
|
||||||
|
comanda:Comanda,
|
||||||
|
obs:str,
|
||||||
|
user:User=None,
|
||||||
|
qtd:int=1):
|
||||||
|
|
||||||
|
components = ProductComponent.objects.filter(composite_product=product)
|
||||||
|
if components.exists():
|
||||||
|
for component in components:
|
||||||
|
movi = StockMovement.objects.create(
|
||||||
|
product=component.component_product ,
|
||||||
|
related_comanda=comanda,
|
||||||
|
user=user,
|
||||||
|
movement_type=movement_type,
|
||||||
|
quantity=component.quantity_required,
|
||||||
|
observation=obs
|
||||||
|
)
|
||||||
|
movi.save()
|
||||||
|
component.component_product.quantity += component.quantity_required
|
||||||
|
component.component_product.save()
|
||||||
|
|
||||||
|
movi = StockMovement.objects.create(
|
||||||
|
product=product ,
|
||||||
|
related_comanda=comanda,
|
||||||
|
user=user,
|
||||||
|
movement_type=movement_type,
|
||||||
|
quantity=qtd,
|
||||||
|
observation=obs
|
||||||
|
)
|
||||||
|
movi.save()
|
||||||
|
product.quantity += qtd
|
||||||
|
product.save()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['-movement_date']
|
ordering = ['-movement_date']
|
||||||
@@ -3,15 +3,16 @@ from django.urls import reverse
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from django.http import JsonResponse, HttpResponseRedirect
|
from django.http import JsonResponse, HttpResponseRedirect
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from django.db.models import Count, F
|
from django.db.models import Count, F
|
||||||
|
|
||||||
from comandas.models import Comanda, ProductComanda
|
from comandas.models import Comanda, ProductComanda, StockMovement, StockMovementType
|
||||||
from clients.models import Client
|
from clients.models import Client
|
||||||
from payments.models import Payments, somar
|
from payments.models import Payments, somar
|
||||||
from orders.models import Order
|
from orders.models import Order
|
||||||
from products.models import Product
|
from products.models import Product, ProductComponent
|
||||||
from mesas.models import Mesa
|
from mesas.models import Mesa
|
||||||
from gestaoRaul.decorators import group_required
|
from gestaoRaul.decorators import group_required
|
||||||
|
|
||||||
@@ -147,9 +148,21 @@ def addProduct(request, product_id, comanda_id):
|
|||||||
obs = request.GET.get("obs")
|
obs = request.GET.get("obs")
|
||||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||||
product_comanda.save()
|
product_comanda.save()
|
||||||
Product.subStock(Product.objects.get(id=product_id), 1)
|
|
||||||
product = Product.objects.get(id=product_id)
|
product = Product.objects.get(id=product_id)
|
||||||
comanda = Comanda.objects.get(id=comanda_id)
|
comanda = Comanda.objects.get(id=comanda_id)
|
||||||
|
user = User.objects.get(id=request.user.id)
|
||||||
|
typeMovement = StockMovementType.objects.get(name="Venda - Comanda")
|
||||||
|
|
||||||
|
StockMovement.subTransactionStock(
|
||||||
|
product=product,
|
||||||
|
movement_type=typeMovement,
|
||||||
|
comanda=comanda,
|
||||||
|
user=user,
|
||||||
|
qtd=1,
|
||||||
|
obs= "Adicionado na comanda"
|
||||||
|
)
|
||||||
|
|
||||||
parcial = Payments.objects.filter(comanda=comanda)
|
parcial = Payments.objects.filter(comanda=comanda)
|
||||||
if product.cuisine == True:
|
if product.cuisine == True:
|
||||||
order = Order(id_comanda=comanda, id_product=product, productComanda=product_comanda, obs='')
|
order = Order(id_comanda=comanda, id_product=product, productComanda=product_comanda, obs='')
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,11 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from products.models import Product
|
from products.models import Product, ProductComponent, UnitOfMeasure
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Product)
|
admin.site.register(Product)
|
||||||
|
admin.site.register(ProductComponent)
|
||||||
|
admin.site.register(UnitOfMeasure)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ from django.db import models
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from categories.models import Categories
|
from categories.models import Categories
|
||||||
# from comandas.models import Comanda
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -47,14 +46,6 @@ class Product(models.Model):
|
|||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"{self.name}"
|
return f"{self.name}"
|
||||||
|
|
||||||
def subStock(self, qtd):
|
|
||||||
self.quantity -= qtd
|
|
||||||
self.save()
|
|
||||||
|
|
||||||
def addStock(self, qtd):
|
|
||||||
self.quantity += qtd
|
|
||||||
self.save()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ProductComponent(models.Model):
|
class ProductComponent(models.Model):
|
||||||
|
|||||||
Reference in New Issue
Block a user