Added avg. price per ticket per ticket type.
This commit is contained in:
parent
4ed1b51ba2
commit
198f6d26c7
|
@ -20,6 +20,7 @@
|
|||
<th class="text-right">Total Income</th>
|
||||
<th class="text-right">Total Cost</th>
|
||||
<th class="text-right">Total Profit</th>
|
||||
<th class="text-right">Avg. Ticket Price</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -32,6 +33,7 @@
|
|||
<td class="text-right">{{ tt.total_income|floatformat:"2" }} DKK</td>
|
||||
<td class="text-right">{{ tt.total_cost|floatformat:"2" }} DKK</td>
|
||||
<td class="text-right">{{ tt.total_profit|floatformat:"2" }} DKK</td>
|
||||
<td class="text-right">{{ tt.avg_ticket_price|floatformat:"2" }} DKK</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
@ -53,12 +53,22 @@ class TicketTypeQuerySet(models.QuerySet):
|
|||
.values("total_profit")[:1]
|
||||
)
|
||||
|
||||
avg_ticket_price = Subquery(
|
||||
TicketType.objects.annotate(units=Sum(quantity))
|
||||
.annotate(income=Sum(income))
|
||||
.annotate(avg_ticket_price=F("income") / F("units"))
|
||||
.filter(pk=OuterRef("pk"))
|
||||
.values("avg_ticket_price")[:1],
|
||||
output_field=models.DecimalField(),
|
||||
)
|
||||
|
||||
return self.annotate(
|
||||
shopticket_count=shopticket_count,
|
||||
total_units_sold=total_units_sold,
|
||||
total_income=total_income,
|
||||
total_cost=total_cost,
|
||||
total_profit=total_profit,
|
||||
avg_ticket_price=avg_ticket_price,
|
||||
).distinct()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue