mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
feat: gerenciamento quantidade product
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -16,4 +16,12 @@ class Product(models.Model):
|
||||
active = models.BooleanField(default=True)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.id} - {self.name} - {self.price} - {self.category} - {self.cuisine} - {self.active} "
|
||||
return f"{self.name}"
|
||||
|
||||
def subStock(self, qtd):
|
||||
self.quantity -= qtd
|
||||
self.save()
|
||||
|
||||
def addStock(self, qtd):
|
||||
self.quantity += qtd
|
||||
self.save()
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from django.http import HttpResponse
|
||||
import json
|
||||
from django.db.models import Q
|
||||
from django.db.models import Q, Count, F
|
||||
|
||||
|
||||
from categories.models import Categories
|
||||
from comandas.models import ProductComanda
|
||||
from products.models import Product
|
||||
from gestaoRaul.decorators import group_required
|
||||
|
||||
@@ -65,6 +67,10 @@ def editProduct(request, productId):
|
||||
return render(request, "htmx_components/products/htmx_search_products.html", {"products": products})
|
||||
|
||||
def createJson(request):
|
||||
produtos_mais_vendidos = list(ProductComanda.objects.values('product').annotate(
|
||||
quantidade=Count('product'),
|
||||
nome=F('product__name') ).order_by('-quantidade'))
|
||||
|
||||
products = Product.objects.filter(active=True).exclude(
|
||||
category__name__in=['Insumos',
|
||||
'Adicional',
|
||||
@@ -76,8 +82,21 @@ def createJson(request):
|
||||
'Cigarros',
|
||||
'Outros']
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
products_ordenados = []
|
||||
for produto in produtos_mais_vendidos:
|
||||
for p in products:
|
||||
if p.name == produto['nome']:
|
||||
products_ordenados.append(p)
|
||||
|
||||
|
||||
|
||||
|
||||
product_list = []
|
||||
for product in products:
|
||||
for product in products_ordenados:
|
||||
product_data = {
|
||||
"id": product.id,
|
||||
"name": product.name,
|
||||
|
||||
Reference in New Issue
Block a user