mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 03:49:24 +00:00
Add cash register summary view
This commit is contained in:
@ -346,6 +346,14 @@ class CashRegisterSummary(models.Model):
|
||||
def __str__(self):
|
||||
return "At %s by %s - Total: %s €" % (self.counter, self.user, self.get_total())
|
||||
|
||||
def is_owned_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
if user.is_in_group(settings.SITH_GROUPS['counter-admin']['name']):
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_total(self):
|
||||
t = 0
|
||||
for it in self.items.all():
|
||||
|
58
counter/templates/counter/cash_summary_list.jinja
Normal file
58
counter/templates/counter/cash_summary_list.jinja
Normal file
@ -0,0 +1,58 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
{% from 'core/macros.jinja' import user_profile_link %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Cash register summary list{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if cashsummary_list %}
|
||||
<h3>{% trans %}Cash register summary list{% endtrans %}</h3>
|
||||
<h5>{% trans %}Theoric sums{% endtrans %}</h5>
|
||||
<h6>{% trans %}Refillings{% endtrans %}</h6>
|
||||
<p>
|
||||
{% for b,s in refilling_sums.items() %}
|
||||
{{ b }}: {{ s }} €<br/>
|
||||
{% endfor %}
|
||||
</p>
|
||||
<h6>{% trans %}Cash register summaries{% endtrans %}</h6>
|
||||
<p>
|
||||
{% for b,s in summaries_sums.items() %}
|
||||
{{ b }}: {{ s }} €<br/>
|
||||
{% endfor %}
|
||||
</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}User{% endtrans %}</td>
|
||||
<td>{% trans %}Counter{% endtrans %}</td>
|
||||
<td>{% trans %}Date{% endtrans %}</td>
|
||||
<td>{% trans %}Total{% endtrans %}</td>
|
||||
<td>{% trans %}Emptied{% endtrans %}</td>
|
||||
<td>{% trans %}Comment{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for c in cashsummary_list.order_by('-date') %}
|
||||
<tr>
|
||||
<td>{{ user_profile_link(c.user) }}</td>
|
||||
<td>{{ c.counter }}</td>
|
||||
<td>{{ c.date|localtime|date(DATETIME_FORMAT) }} - {{ c.date|localtime|time(DATETIME_FORMAT) }}</td>
|
||||
<td>{{ c.get_total() }} €</td>
|
||||
{% if c.emptied %}
|
||||
<td>{% trans %}yes{% endtrans %}</td>
|
||||
{% else %}
|
||||
<td></td>
|
||||
{% endif %}
|
||||
<td>{{ c.comment }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
{% trans %}There is no cash register summary in this website.{% endtrans %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -14,6 +14,7 @@ urlpatterns = [
|
||||
url(r'^admin$', CounterListView.as_view(), name='admin_list'),
|
||||
url(r'^admin/new$', CounterCreateView.as_view(), name='new'),
|
||||
url(r'^admin/delete/(?P<counter_id>[0-9]+)$', CounterDeleteView.as_view(), name='delete'),
|
||||
url(r'^admin/cash_summary/list$', CashSummaryListView.as_view(), name='cash_summary_list'),
|
||||
url(r'^admin/product/list$', ProductListView.as_view(), name='product_list'),
|
||||
url(r'^admin/product/list_archived$', ProductArchivedListView.as_view(), name='product_list_archived'),
|
||||
url(r'^admin/product/create$', ProductCreateView.as_view(), name='new_product'),
|
||||
|
@ -12,7 +12,8 @@ from django.conf import settings
|
||||
from django.db import DataError, transaction
|
||||
|
||||
import re
|
||||
from datetime import date, timedelta
|
||||
import pytz
|
||||
from datetime import date, timedelta, datetime
|
||||
from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultipleField
|
||||
from ajax_select import make_ajax_form, make_ajax_field
|
||||
|
||||
@ -407,6 +408,11 @@ class CounterTabsMixin(TabedViewMixin):
|
||||
'slug': 'product_types',
|
||||
'name': _("Product types"),
|
||||
},
|
||||
{
|
||||
'url': reverse_lazy('counter:cash_summary_list'),
|
||||
'slug': 'cash_summary',
|
||||
'name': _("Cash register summaries"),
|
||||
},
|
||||
]
|
||||
|
||||
class CounterListView(CounterTabsMixin, CanViewMixin, ListView):
|
||||
@ -687,3 +693,24 @@ class CounterActivityView(DetailView):
|
||||
pk_url_kwarg = "counter_id"
|
||||
template_name = 'counter/activity.jinja'
|
||||
|
||||
class CashSummaryListView(CanEditPropMixin, CounterTabsMixin, ListView):
|
||||
"""Display a list of cash summaries"""
|
||||
model = CashRegisterSummary
|
||||
template_name = 'counter/cash_summary_list.jinja'
|
||||
context_object_name = "cashsummary_list"
|
||||
current_tab = "cash_summary"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
""" Add sums to the context """
|
||||
kwargs = super(CashSummaryListView, self).get_context_data(**kwargs)
|
||||
kwargs['summaries_sums'] = {}
|
||||
kwargs['refilling_sums'] = {}
|
||||
for c in Counter.objects.filter(type="BAR").all():
|
||||
last_summary = CashRegisterSummary.objects.filter(counter=c, emptied=True).order_by('-date').first()
|
||||
if last_summary:
|
||||
last_date = last_summary.date
|
||||
else:
|
||||
last_date = datetime(year=1994, month=5, day=17, tzinfo=pytz.UTC) # My birth date should be old enough
|
||||
kwargs['summaries_sums'][c.name] = sum([s.get_total() for s in CashRegisterSummary.objects.filter(counter=c, date__gt=last_date).all()])
|
||||
kwargs['refilling_sums'][c.name] = sum([s.amount for s in Refilling.objects.filter(counter=c, date__gt=last_date).all()])
|
||||
return kwargs
|
||||
|
Reference in New Issue
Block a user