Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Determine low stock products by checking quantity sum from all locations
Marcin Gębala579ecf408af0
diff --git a/saleor/dashboard/views.py b/saleor/dashboard/views.pyindex 594c310630..4709f1fb2e 100644--- a/saleor/dashboard/views.py+++ b/saleor/dashboard/views.py@@ -1,7 +1,7 @@from django.conf import settingsfrom django.contrib.admin.views.decorators import staff_member_required \as _staff_member_required-from django.db.models import Q+from django.db.models import Q, Sumfrom django.template.response import TemplateResponsefrom django.utils.decorators import method_decoratorfrom django.views.generic.edit import FormMixin@@ -60,6 +60,5 @@ def index(request):def get_low_stock_products():threshold = getattr(settings, 'LOW_STOCK_THRESHOLD', 10)- products = Product.objects.filter(- Q(variants__stock__quantity__lte=threshold)).distinct()- return products+ products = Product.objects.annotate(total_stock=Sum('variants__stock__quantity'))+ return products.filter(Q(total_stock__lte=threshold)).distinct()