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,19 +277,15 @@ class ProductFilter(FilterSet):
ordering_param = self.data.get("order_by", "") ordering_param = self.data.get("order_by", "")
qs = qs.annotate( qs = qs.annotate(
has_stock=Max( has_stock=Case(
Case(
When(stocks__quantity__gt=0, then=Value(True)), When(stocks__quantity__gt=0, then=Value(True)),
default=Value(False), default=Value(False),
output_field=BooleanField(), output_field=BooleanField(),
)
), ),
has_price=Max( has_price=Case(
Case(
When(stocks__price__gt=0, then=Value(True)), When(stocks__price__gt=0, then=Value(True)),
default=Value(False), default=Value(False),
output_field=BooleanField(), output_field=BooleanField(),
)
), ),
).annotate( ).annotate(
personal_orders_only=Case( personal_orders_only=Case(