fix: InvoiceQuerySet.annotate_total() (but for real this time)

This commit is contained in:
imperosol
2024-10-13 10:37:48 +02:00
parent 768e2867b5
commit 564d95f701
2 changed files with 4 additions and 4 deletions

View File

@ -173,9 +173,8 @@ class InvoiceQueryset(models.QuerySet):
return self.annotate(
total=Subquery(
InvoiceItem.objects.filter(invoice_id=OuterRef("pk"))
.annotate(item_amount=F("product_unit_price") * F("quantity"))
.values("item_amount")
.annotate(total=Sum("item_amount"))
.values("invoice_id")
.annotate(total=Sum(F("product_unit_price") * F("quantity")))
.values("total")
)
)