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

@@ -5,7 +5,7 @@ from django.db.models import Count, F
from clients.models import Client
from products.models import Product
from products.models import Product, ProductComponent
from mesas.models import Mesa
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')}"
)
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:
ordering = ['-movement_date']