25 lines
640 B
Python
25 lines
640 B
Python
from Base.models import ProductList
|
|
from Movement.models import Stock , Product
|
|
from django.db.models import Sum
|
|
|
|
def metric(Day):
|
|
List = ProductList.objects.all()
|
|
Products = Product.objects.all()
|
|
Stones = Stock.objects.all()
|
|
Stones_report = {}
|
|
|
|
for Prod in List:
|
|
sum_ = Stones.filter(
|
|
product__name=Prod.name,
|
|
).aggregate(Sum('quantity'))['quantity__sum'] or 0
|
|
|
|
sum_v = Products.filter(
|
|
product__name=Prod.name,
|
|
).aggregate(Sum('quantity'))['quantity__sum'] or 0
|
|
|
|
Stones_report[Prod.name] = sum_ - sum_v
|
|
|
|
return {
|
|
'Stone':Stones_report,
|
|
}
|