Skip to content
Discussion options

You must be logged in to vote

I founded the solution
models.py

class RemainingInRGPItemManager(models.Manager):
    def get_queryset(self):
        """Retrieve all active users"""
        return super().get_queryset().annotate(
            total_qty=Sum("qty", distinct=True),
            out_rgp_item_sent_qty=Sum("outrgpitem__sent_qty"),
            remaining_qty=Case(
                When(out_rgp_item_sent_qty__isnull=True, then=F("total_qty")),
                default=F("total_qty") - F("out_rgp_item_sent_qty"),
                output_field=models.IntegerField()
            )
        ).filter(
            Q(remaining_qty__gt=0)
        )

class InRGPItem(CreatedAtAndUpdatedAt):
    guid = models.UUIDField(default=uuid.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@bhautik-jivani
Comment options

@jrief
Comment options

jrief May 3, 2025
Maintainer

Comment options

You must be logged in to vote
0 replies
Answer selected by bhautik-jivani
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants