mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Allow more control on the dates for cash summaries sums
This commit is contained in:
parent
31d62532be
commit
13265e6a0d
@ -7,6 +7,11 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if cashsummary_list %}
|
{% if cashsummary_list %}
|
||||||
|
<form action="" method="get">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form }}
|
||||||
|
<p><input type="submit" value="{% trans %}Show{% endtrans %}" /></p>
|
||||||
|
</form>
|
||||||
<h3>{% trans %}Cash register summary list{% endtrans %}</h3>
|
<h3>{% trans %}Cash register summary list{% endtrans %}</h3>
|
||||||
<h5>{% trans %}Theoric sums{% endtrans %}</h5>
|
<h5>{% trans %}Theoric sums{% endtrans %}</h5>
|
||||||
<h6>{% trans %}Refillings{% endtrans %}</h6>
|
<h6>{% trans %}Refillings{% endtrans %}</h6>
|
||||||
|
@ -20,7 +20,7 @@ from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultip
|
|||||||
from ajax_select import make_ajax_form, make_ajax_field
|
from ajax_select import make_ajax_form, make_ajax_field
|
||||||
|
|
||||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin
|
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin
|
||||||
from core.views.forms import SelectUser, LoginForm, SelectDate
|
from core.views.forms import SelectUser, LoginForm, SelectDate, SelectDateTime
|
||||||
from core.models import User
|
from core.models import User
|
||||||
from subscription.models import Subscriber, Subscription
|
from subscription.models import Subscriber, Subscription
|
||||||
from subscription.views import get_subscriber
|
from subscription.views import get_subscriber
|
||||||
@ -896,6 +896,10 @@ class CashSummaryEditView(CanEditPropMixin, CounterAdminTabsMixin, UpdateView):
|
|||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('counter:cash_summary_list')
|
return reverse('counter:cash_summary_list')
|
||||||
|
|
||||||
|
class CashSummaryFormBase(forms.Form):
|
||||||
|
begin_date = forms.DateTimeField(['%Y-%m-%d %H:%M:%S'], label=_("Begin date"), required=False, widget=SelectDateTime)
|
||||||
|
end_date = forms.DateTimeField(['%Y-%m-%d %H:%M:%S'], label=_("End date"), required=False, widget=SelectDateTime)
|
||||||
|
|
||||||
class CashSummaryListView(CanEditPropMixin, CounterAdminTabsMixin, ListView):
|
class CashSummaryListView(CanEditPropMixin, CounterAdminTabsMixin, ListView):
|
||||||
"""Display a list of cash summaries"""
|
"""Display a list of cash summaries"""
|
||||||
model = CashRegisterSummary
|
model = CashRegisterSummary
|
||||||
@ -906,16 +910,29 @@ class CashSummaryListView(CanEditPropMixin, CounterAdminTabsMixin, ListView):
|
|||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
""" Add sums to the context """
|
""" Add sums to the context """
|
||||||
kwargs = super(CashSummaryListView, self).get_context_data(**kwargs)
|
kwargs = super(CashSummaryListView, self).get_context_data(**kwargs)
|
||||||
|
form = CashSummaryFormBase(self.request.GET)
|
||||||
|
kwargs['form'] = form
|
||||||
kwargs['summaries_sums'] = {}
|
kwargs['summaries_sums'] = {}
|
||||||
kwargs['refilling_sums'] = {}
|
kwargs['refilling_sums'] = {}
|
||||||
for c in Counter.objects.filter(type="BAR").all():
|
for c in Counter.objects.filter(type="BAR").all():
|
||||||
last_summary = CashRegisterSummary.objects.filter(counter=c, emptied=True).order_by('-date').first()
|
refillings = Refilling.objects.filter(counter=c)
|
||||||
if last_summary:
|
cashredistersummaries = CashRegisterSummary.objects.filter(counter=c)
|
||||||
last_date = last_summary.date
|
if form.is_valid() and form.cleaned_data['begin_date']:
|
||||||
|
refillings = refillings.filter(date__gte=form.cleaned_data['begin_date'])
|
||||||
|
cashredistersummaries = cashredistersummaries.filter(date__gte=form.cleaned_data['begin_date'])
|
||||||
else:
|
else:
|
||||||
last_date = datetime(year=1994, month=5, day=17, tzinfo=pytz.UTC) # My birth date should be old enough
|
last_summary = CashRegisterSummary.objects.filter(counter=c, emptied=True).order_by('-date').first()
|
||||||
kwargs['summaries_sums'][c.name] = sum([s.get_total() for s in CashRegisterSummary.objects.filter(counter=c, date__gt=last_date).all()])
|
if last_summary:
|
||||||
kwargs['refilling_sums'][c.name] = sum([s.amount for s in Refilling.objects.filter(counter=c, date__gt=last_date).all()])
|
refillings = refillings.filter(date__gte=last_summary.date)
|
||||||
|
cashredistersummaries = cashredistersummaries.filter(date__gte=last_summary.date)
|
||||||
|
else:
|
||||||
|
refillings = refillings.filter(date__gte=datetime(year=1994, month=5, day=17, tzinfo=pytz.UTC)) # My birth date should be old enough
|
||||||
|
cashredistersummaries = cashredistersummaries.filter(date__gte=datetime(year=1994, month=5, day=17, tzinfo=pytz.UTC))
|
||||||
|
if form.is_valid() and form.cleaned_data['end_date']:
|
||||||
|
refillings = refillings.filter(date__lte=form.cleaned_data['end_date'])
|
||||||
|
cashredistersummaries = cashredistersummaries.filter(date__lte=form.cleaned_data['end_date'])
|
||||||
|
kwargs['summaries_sums'][c.name] = sum([s.get_total() for s in cashredistersummaries.all()])
|
||||||
|
kwargs['refilling_sums'][c.name] = sum([s.amount for s in refillings.all()])
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
class InvoiceCallView(CounterAdminTabsMixin, TemplateView):
|
class InvoiceCallView(CounterAdminTabsMixin, TemplateView):
|
||||||
|
Loading…
Reference in New Issue
Block a user