Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stregreport: Add all categories to overview #532

Merged
merged 15 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 23 additions & 49 deletions stregreport/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,61 +303,28 @@ def sales_product(request, ids, from_time, to_time, error=None):
# both at 10 o'clock
@permission_required("stregsystem.access_sales_reports")
def ranks_for_year(request, year):
if year <= 1900 or year > 9999:
return render(request, 'admin/stregsystem/report/error_ranksnotfound.html', locals())
milk = [2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 17, 18, 19, 20, 24, 25, 43, 44, 45, 1865]
caffeine = [11, 12, 30, 34, 37, 1787, 1790, 1791, 1795, 1799, 1800, 1803, 1804, 1837, 1864]
beer = [
13,
14,
29,
42,
47,
54,
65,
66,
1773,
1776,
1777,
1779,
1780,
1783,
1793,
1794,
1807,
1808,
1809,
1820,
1822,
1840,
1844,
1846,
1847,
1853,
1855,
1856,
1858,
1859,
]
coffee = [32, 35, 36, 39]
vitamin = [1850, 1851, 1852, 1863, 1880]

FORMAT = '%d/%m/%Y kl. %H:%M'
last_year = year - 1
next_year = year + 1
from_time = fjule_party(year - 1)
to_time = fjule_party(year)

kr_stat_list = sale_money_rank(from_time, to_time)
beer_stat_list = sale_product_rank(beer, from_time, to_time)
caffeine_stat_list = sale_product_rank(caffeine, from_time, to_time)
milk_stat_list = sale_product_rank(milk, from_time, to_time)
coffee_stat_list = sale_product_rank(coffee, from_time, to_time)
vitamin_stat_list = sale_product_rank(vitamin, from_time, to_time)

stat_list = [
(
cat.name,
sale_product_rank(get_product_ids_from_category(cat), from_time, to_time),
)
for cat in Category.objects.all()
]

from_time_string = from_time.strftime(FORMAT)
to_time_string = to_time.strftime(FORMAT)
current_date = timezone.now()
show_next_year = year < current_date.year
is_ongoing = current_date > from_time and current_date <= to_time
last_year = year - 1
next_year = year + 1

return render(request, 'admin/stregsystem/report/ranks.html', locals())


Expand All @@ -383,6 +350,10 @@ def sale_money_rank(from_time, to_time, rank_limit=10):
return stat_list


def get_product_ids_from_category(category):
return category.product_set.values_list('id', flat=True)


# year of the last fjuleparty
def last_fjule_party_year():
current_date = timezone.now()
Expand All @@ -401,9 +372,12 @@ def next_fjule_party_year():
return current_date.year + 1


# date of fjuleparty (first friday of december) for the given year at
# 10 o'clock
def fjule_party(year):
def fjule_party(year) -> datetime.datetime:
"""
date of fjuleparty (first friday of december) for the given year at 10 o'clock
:param year: The year of the fjuleparty
:return: The date of the party
"""
first_december = timezone.datetime(year, 12, 1, 22, tzinfo=pytz.timezone("Europe/Copenhagen"))
days_to_add = (11 - first_december.weekday()) % 7
return first_december + datetime.timedelta(days=days_to_add)
Expand Down
84 changes: 5 additions & 79 deletions stregsystem/templates/admin/stregsystem/report/ranks.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ <h1>Rangeringer for {{year}}</h1>
{% endif %}
<center>
<div id="statscontainer" style="margin-top: 12px; width: 1200px; float: left;">
<div id="stats" style="width: 200px; float: left;">
{% for stat_list in stat_lists %}
<div class="stats" style="width: 200px; float: left;">
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<th valign="top" colspan="3">Øl</th>
<th valign="top" colspan="3">{{stat_list.0}}</th>
</tr>
<tr>
<th>#</th>
<th>Bruger</th>
<th>Antal</th>
</tr>
{% for stat in beer_stat_list %}
{% for stat in stat_list.1 %}
<tr>
<td>{{forloop.counter}}</td>
<td>{{stat.username}}</td>
Expand All @@ -34,82 +35,7 @@ <h1>Rangeringer for {{year}}</h1>
{% endfor %}
</table>
</div>
<div id="stats2" style="width: 200px; float: left;">
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<th valign="top" colspan="3">Koffein</th>
</tr>
<tr>
<th>#</th>
<th>Bruger</th>
<th>Antal</th>
</tr>
{% for stat in caffeine_stat_list %}
<tr>
<td>{{forloop.counter}}</td>
<td>{{stat.username}}</td>
<td>{{stat.sale__count}}</td>
</tr>
{% endfor %}
</table>
</div>
<div id="stats3" style="width: 200px; float: left;">
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<th valign="top" colspan="3">Mælkeprodukter</th>
</tr>
<tr>
<th>#</th>
<th>Bruger</th>
<th>Antal</th>
</tr>
{% for stat in milk_stat_list %}
<tr>
<td>{{forloop.counter}}</td>
<td>{{stat.username}}</td>
<td>{{stat.sale__count}}</td>
</tr>
{% endfor %}
</table>
</div>
<div id="stats4" style="width: 200px; float: left;">
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<th valign="top" colspan="3">Kaffe</th>
</tr>
<tr>
<th>#</th>
<th>Bruger</th>
<th>Antal</th>
</tr>
{% for stat in coffee_stat_list %}
<tr>
<td>{{forloop.counter}}</td>
<td>{{stat.username}}</td>
<td>{{stat.sale__count}}</td>
</tr>
{% endfor %}
</table>
</div>
<div id="stats5" style="width: 200px; float: left;">
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<th valign="top" colspan="3">Vitaminvand</th>
</tr>
<tr>
<th>#</th>
<th>Bruger</th>
<th>Antal</th>
</tr>
{% for stat in vitamin_stat_list %}
<tr>
<td>{{forloop.counter}}</td>
<td>{{stat.username}}</td>
<td>{{stat.sale__count}}</td>
</tr>
{% endfor %}
</table>
</div>
{% endfor %}
<div id="stats6" style="width: 200px; float: left;">
<table border="1" cellspacing="2" cellpadding="2">
<tr>
Expand Down
8 changes: 4 additions & 4 deletions stregsystem/templates/shared_report_lists.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
<table>
<caption><a href="/admin/stregsystem/report/" class="section">{% blocktrans with app.name as name %}Rapporter{% endblocktrans %}</a></caption>
<tr>
<th scope="row"><a href = "/admin/stregsystem/report/ranks/">Købs- og forbrugsrangeringer</a></th>
<th scope="row"><a href = "/admin/stregsystem/report/daily/">Daglig omsætning</a></th>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<th scope="row"><a href = "/admin/stregsystem/report/sales/">Salgsrapporteringer</a></th>
<th scope="row"><a href = "/admin/stregsystem/report/ranks/">Kategorirangeringer</a></th>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<th scope="row"><a href = "/admin/stregsystem/report/daily/">Daglig rapportering</a></th>
<th scope="row"><a href = "/admin/stregsystem/report/categories/">Bruger køb i udvalgte kategorier</a></th>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<th scope="row"><a href = "/admin/stregsystem/report/categories/">Bruger køb i kategorier</a></th>
<th scope="row"><a href = "/admin/stregsystem/report/sales/">Salgsrapporteringer for udvalgte produkter</a></th>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
Expand Down
Loading