feat: criado tabela no db (UnitOfMeasure, ProductComponent, StockMovementType, StockMovement) add UnitOfMeasure na tabela produtos

This commit is contained in:
2025-07-22 15:39:37 -03:00
parent b74736f391
commit a9289cb28d
9 changed files with 184 additions and 1 deletions

View File

@@ -43,4 +43,39 @@ class ProductComanda(models.Model):
for p in products:
if p.name == produto['nome'] and p.active == True:
products_ordenados.append(p)
return products_ordenados[:15]
return products_ordenados[:15]
class StockMovementType(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100, unique=True, help_text="Ex: 'Entrada por Compra', 'Saída por Venda', 'Ajuste de Estoque'")
observation = models.TextField(null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.name
class StockMovement(models.Model):
id = models.AutoField(primary_key=True)
product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='stock_movements')
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True, help_text="Usuário que realizou a movimentação.")
related_comanda = models.ForeignKey(
Comanda,
on_delete=models.SET_NULL,
null=True,
blank=True,
help_text="Comanda relacionada à movimentação (opcional)."
)
movement_type = models.ForeignKey(StockMovementType, on_delete=models.PROTECT, help_text="Tipo de movimentação (entrada, saída, ajuste).")
quantity = models.IntegerField(help_text="Quantidade movimentada. Use valores negativos para saídas.")
observation = models.TextField(null=True, blank=True)
movement_date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return (
f"Movimentação de {self.quantity} de {self.product.name} "
f"({self.movement_type.name}) em {self.movement_date.strftime('%d/%m/%Y %H:%M')}"
)
class Meta:
ordering = ['-movement_date']