Features: 1) Streamlined stock and price annotations by removing redundant Max wrapping;

Fixes: None;

Extra: 1) Simplified code structure for readability; 2) Optimized boolean calculations for annotations;
This commit is contained in:
Egor Pavlovich Gorbunov 2025-10-03 17:07:59 +03:00
parent d917584829
commit 40c86c7eef

View file

@ -277,20 +277,16 @@ class ProductFilter(FilterSet):
ordering_param = self.data.get("order_by", "")
qs = qs.annotate(
has_stock=Max(
Case(
has_stock=Case(
When(stocks__quantity__gt=0, then=Value(True)),
default=Value(False),
output_field=BooleanField(),
)
),
has_price=Max(
Case(
),
has_price=Case(
When(stocks__price__gt=0, then=Value(True)),
default=Value(False),
output_field=BooleanField(),
)
),
),
).annotate(
personal_orders_only=Case(
When(has_stock=False, has_price=False, then=Value(True)),