mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Add product top 10
This commit is contained in:
@ -6,20 +6,37 @@
|
||||
|
||||
{% block content %}
|
||||
{% if profile.permanencies %}
|
||||
<h3>{% trans %}Permanencies{% endtrans %}</h3>
|
||||
<div>
|
||||
<h3>{% trans %}Permanencies{% endtrans %}</h3>
|
||||
<p>Total: {{ total_perm_time }}</p>
|
||||
<p>Foyer: {{ total_foyer_time }}</p>
|
||||
<p>MDE: {{ total_mde_time }}</p>
|
||||
<p>La Gommette: {{ total_gommette_time }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
<h3>{% trans %}Buyings{% endtrans %}</h3>
|
||||
<div>
|
||||
<h3>{% trans %}Buyings{% endtrans %}</h3>
|
||||
<p>Foyer: {{ total_foyer_buyings }} €</p>
|
||||
<p>MDE: {{ total_mde_buyings }} €</p>
|
||||
<p>La Gommette: {{ total_gommette_buyings }} €</p>
|
||||
</div>
|
||||
<h3>{% trans %}Product top 10{% endtrans %}</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Product{% endtrans %}</td>
|
||||
<td>{% trans %}Quantity{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for p in top_product %}
|
||||
<tr>
|
||||
<td>{{ p['product__name'] }}</td>
|
||||
<td>{{ p['product_sum'] }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -222,7 +222,8 @@ class UserStatsView(UserTabsMixin, CanViewMixin, DetailView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(UserStatsView, self).get_context_data(**kwargs)
|
||||
from counter.models import Counter
|
||||
from counter.models import Counter, Product, Selling
|
||||
from django.db.models import Sum
|
||||
foyer = Counter.objects.filter(name="Foyer").first()
|
||||
mde = Counter.objects.filter(name="MDE").first()
|
||||
gommette = Counter.objects.filter(name="La Gommette").first()
|
||||
@ -237,6 +238,8 @@ class UserStatsView(UserTabsMixin, CanViewMixin, DetailView):
|
||||
date__gte=semester_start)])
|
||||
kwargs['total_gommette_buyings'] = sum([b.unit_price*b.quantity for b in
|
||||
self.object.customer.buyings.filter(counter=gommette, date__gte=semester_start)])
|
||||
kwargs['top_product'] = self.object.customer.buyings.values('product__name').annotate(
|
||||
product_sum=Sum('quantity')).exclude(product_sum=None).order_by('-product_sum').all()[:10]
|
||||
return kwargs
|
||||
|
||||
class UserMiniView(CanViewMixin, DetailView):
|
||||
|
Reference in New Issue
Block a user