Features: 1) Add has_stock and has_price annotations for stock and price availability checks.
Fixes: 1) Correct conditional logic in `personal_order_only` annotation to use integers for comparison. Extra: 1) Minor readability improvements in annotation definitions.
This commit is contained in:
parent
91b043ac4f
commit
fe6316dae1
1 changed files with 16 additions and 1 deletions
|
|
@ -306,8 +306,23 @@ class ProductFilter(FilterSet):
|
|||
)
|
||||
|
||||
qs = qs.annotate(
|
||||
has_stock=Max(
|
||||
Case(
|
||||
When(stocks__quantity__gt=0, then=Value(1)),
|
||||
default=Value(0),
|
||||
output_field=IntegerField(),
|
||||
)
|
||||
),
|
||||
has_price=Max(
|
||||
Case(
|
||||
When(stocks__price__gt=0, then=Value(1)),
|
||||
default=Value(0),
|
||||
output_field=IntegerField(),
|
||||
)
|
||||
),
|
||||
).annotate(
|
||||
personal_order_only=Case(
|
||||
When(has_stock=Value(0), has_price=Value(1), then=Value(True)),
|
||||
When(has_stock=0, has_price=1, then=Value(True)),
|
||||
default=Value(False),
|
||||
output_field=BooleanField(),
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue