use Count() to get the number of paid orders for the product
This commit is contained in:
parent
b76cc2ed64
commit
f61d0b85e8
|
@ -31,7 +31,7 @@
|
||||||
<td class="text-right">{{ p.price|floatformat:"2" }} DKK</td>
|
<td class="text-right">{{ p.price|floatformat:"2" }} DKK</td>
|
||||||
<td class="text-right">{{ p.cost|floatformat:"2" }} DKK</td>
|
<td class="text-right">{{ p.cost|floatformat:"2" }} DKK</td>
|
||||||
<td class="text-right">{{ p.profit|floatformat:"2" }} DKK</td>
|
<td class="text-right">{{ p.profit|floatformat:"2" }} DKK</td>
|
||||||
<td class="text-center">{{ p.order_set.count }}</td>
|
<td class="text-center">{{ p.order_count }}</td>
|
||||||
<td class="text-center">{{ p.total_units_sold }}</td>
|
<td class="text-center">{{ p.total_units_sold }}</td>
|
||||||
<td class="text-right">{{ p.total_revenue|floatformat:"2" }} DKK</td>
|
<td class="text-right">{{ p.total_revenue|floatformat:"2" }} DKK</td>
|
||||||
<td class="text-right">{{ p.total_cost|floatformat:"2" }} DKK</td>
|
<td class="text-right">{{ p.total_cost|floatformat:"2" }} DKK</td>
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.contrib import messages
|
||||||
from django.contrib.postgres.fields import DateTimeRangeField
|
from django.contrib.postgres.fields import DateTimeRangeField
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import F, Sum
|
from django.db.models import Count, F, Sum
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.dateparse import parse_datetime
|
from django.utils.dateparse import parse_datetime
|
||||||
|
@ -403,6 +403,7 @@ class ProductStatsManager(models.Manager):
|
||||||
.annotate(total_revenue=F("price") * F("total_units_sold"))
|
.annotate(total_revenue=F("price") * F("total_units_sold"))
|
||||||
.annotate(total_cost=F("cost") * F("total_units_sold"))
|
.annotate(total_cost=F("cost") * F("total_units_sold"))
|
||||||
.annotate(total_profit=F("profit") * F("total_units_sold"))
|
.annotate(total_profit=F("profit") * F("total_units_sold"))
|
||||||
|
.annotate(order_count=Count("orderproductrelation__order"))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue