Skip to content

Commit

Permalink
fix event annotations for postgres (#757)
Browse files Browse the repository at this point in the history
[#188745145]
  • Loading branch information
uraniumanchor authored Jan 5, 2025
1 parent 356ee36 commit 6d1e2a3
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions tracker/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import decimal
import itertools
import logging
from decimal import Decimal

import post_office.models
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.core.validators import validate_slug
from django.db import models
from django.db.models import Case, Count, F, Q, Sum, When, signals
from django.db.models.functions import Cast, Coalesce
from django.db.models.functions import Coalesce
from django.dispatch import receiver
from django.urls import reverse
from timezone_field import TimeZoneField
Expand Down Expand Up @@ -59,23 +60,20 @@ def current_or_next(self, timestamp=None):

def with_annotations(self, ignore_order=False):
annotated = self.annotate(
amount=Cast(
Coalesce(
Sum(
Case(
When(
Q(donation__transactionstate='COMPLETED'),
then=F('donation__amount'),
),
output_field=models.DecimalField(decimal_places=2),
)
),
0.0,
amount=Coalesce(
Sum(
Case(
When(
Q(donation__transactionstate='COMPLETED'),
then=F('donation__amount'),
),
output_field=models.DecimalField(decimal_places=2),
)
),
output_field=models.DecimalField(),
Decimal('0.00'),
),
donation_count=Count(
'donation', filter=Q(donation__transactionstate='COMPLETED')
donation_count=Coalesce(
Count('donation', filter=Q(donation__transactionstate='COMPLETED')), 0
),
)

Expand Down

0 comments on commit 6d1e2a3

Please sign in to comment.