backoffice: add average price across all tickets of the given type to the tickettype stats detail view

This commit is contained in:
Thomas Steen Rasmussen 2021-07-26 18:47:34 +02:00
parent a494bdfd4b
commit 4c6eca2a6d
3 changed files with 6 additions and 0 deletions

View file

@ -51,6 +51,7 @@
</tfoot> </tfoot>
</table> </table>
<br> <br>
<p class="lead">The average price of the <b>{{ total_units }}</b> tickets with the ticket type <b>{{ product_list.0.ticket_type.name }}</b> is <b>{{ average_price|floatformat:"2" }}</b>&nbsp;DKK.</p>
<p class="lead">Note: This view only shows tickets, which are generated based on paid orders. Unpaid orders are not included here.</p> <p class="lead">Note: This view only shows tickets, which are generated based on paid orders. Unpaid orders are not included here.</p>
<a class="btn btn-default" href="{% url 'backoffice:shop_ticket_stats' camp_slug=camp.slug %}"><i class="fas fa-undo"></i> Back to Ticket Types</a> <a class="btn btn-default" href="{% url 'backoffice:shop_ticket_stats' camp_slug=camp.slug %}"><i class="fas fa-undo"></i> Back to Ticket Types</a>
</p> </p>

View file

@ -228,4 +228,7 @@ class ShopTicketStatsDetailView(CampViewMixin, OrgaTeamPermissionMixin, ListView
context["total_income"] += product.total_income context["total_income"] += product.total_income
context["total_cost"] += product.total_cost context["total_cost"] += product.total_cost
context["total_profit"] += product.total_profit context["total_profit"] += product.total_profit
context["average_price"] = round(
context["total_income"] / context["total_units"], 2
)
return context return context

View file

@ -138,6 +138,8 @@ class DiscountTicket(BaseTicket):
class ShopTicket(BaseTicket): class ShopTicket(BaseTicket):
"""Why doesn't this have an FK to OrderProductRelation instead of the fk to Order?"""
order = models.ForeignKey( order = models.ForeignKey(
"shop.Order", related_name="shoptickets", on_delete=models.PROTECT "shop.Order", related_name="shoptickets", on_delete=models.PROTECT
) )