From 9731181ce209fcb887c7869886c4720c3cb2ee5f Mon Sep 17 00:00:00 2001 From: phzhik Date: Tue, 21 May 2024 01:15:55 +0400 Subject: [PATCH] * Checklist.bonus_used as an absolute value --- store/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/store/models.py b/store/models.py index 753c0b8..7cb59e6 100644 --- a/store/models.py +++ b/store/models.py @@ -13,7 +13,7 @@ from django.core.files.base import ContentFile from django.core.validators import MinValueValidator, MaxValueValidator from django.db import models from django.db.models import F, Case, When, DecimalField, Prefetch, Max, Q, Subquery, OuterRef -from django.db.models.functions import Ceil, Coalesce +from django.db.models.functions import Ceil, Coalesce, Abs from django.db.models.lookups import GreaterThan from django.db.transaction import atomic from django.utils import timezone @@ -215,7 +215,7 @@ class ChecklistQuerySet(models.QuerySet): order_id=OuterRef('id')) .values('amount')) - return self.annotate(_bonus_used=Coalesce(amount_subquery, 0)) + return self.annotate(_bonus_used=Coalesce(Abs(amount_subquery), 0)) def default_ordering(self): return self.order_by(F('status_updated_at').desc(nulls_last=True))