mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 03:49:24 +00:00
Add invoices calls
This commit is contained in:
34
counter/templates/counter/invoices_call.jinja
Normal file
34
counter/templates/counter/invoices_call.jinja
Normal file
@ -0,0 +1,34 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Invoices call{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h3>{% trans %}Invoices call{% endtrans %}</h3>
|
||||
<form method="get" action="">
|
||||
<select name="month">
|
||||
{% for m in months %}
|
||||
<option value="{{ m|date("Y-m") }}">{{ m|date("Y-m") }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<input type="submit" value="{% trans %}Go{% endtrans %}" />
|
||||
</form>
|
||||
<table>
|
||||
<thead>
|
||||
<td>{% trans %}Club{% endtrans %}</td>
|
||||
<td>{% trans %}Sum{% endtrans %}</td>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for i in sums %}
|
||||
<tr>
|
||||
<td>{{ i['club__name'] }}</td>
|
||||
<td>{{ i['selling_sum'] }} €</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -16,6 +16,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/invoices_call$', InvoiceCallView.as_view(), name='invoices_call'),
|
||||
url(r'^admin/cash_summary/list$', CashSummaryListView.as_view(), name='cash_summary_list'),
|
||||
url(r'^admin/cash_summary/(?P<cashsummary_id>[0-9]+)$', CashSummaryEditView.as_view(), name='cash_summary_edit'),
|
||||
url(r'^admin/product/list$', ProductListView.as_view(), name='product_list'),
|
||||
|
@ -1,6 +1,6 @@
|
||||
from django.shortcuts import render
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.views.generic import ListView, DetailView, RedirectView
|
||||
from django.views.generic import ListView, DetailView, RedirectView, TemplateView
|
||||
from django.views.generic.edit import UpdateView, CreateView, DeleteView, ProcessFormView, FormMixin
|
||||
from django.forms.models import modelform_factory
|
||||
from django.forms import CheckboxSelectMultiple
|
||||
@ -459,6 +459,11 @@ class CounterAdminTabsMixin(TabedViewMixin):
|
||||
'slug': 'cash_summary',
|
||||
'name': _("Cash register summaries"),
|
||||
},
|
||||
{
|
||||
'url': reverse_lazy('counter:invoices_call'),
|
||||
'slug': 'invoices_call',
|
||||
'name': _("Invoices call"),
|
||||
},
|
||||
]
|
||||
|
||||
class CounterListView(CounterAdminTabsMixin, CanViewMixin, ListView):
|
||||
@ -908,3 +913,29 @@ class CashSummaryListView(CanEditPropMixin, CounterAdminTabsMixin, ListView):
|
||||
kwargs['refilling_sums'][c.name] = sum([s.amount for s in Refilling.objects.filter(counter=c, date__gt=last_date).all()])
|
||||
return kwargs
|
||||
|
||||
class InvoiceCallView(CounterAdminTabsMixin, TemplateView):
|
||||
template_name = 'counter/invoices_call.jinja'
|
||||
current_tab = 'invoices_call'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
""" Add sums to the context """
|
||||
kwargs = super(InvoiceCallView, self).get_context_data(**kwargs)
|
||||
kwargs['months'] = Selling.objects.datetimes('date', 'month', order='DESC')
|
||||
start_date = None
|
||||
end_date = None
|
||||
try:
|
||||
start_date = datetime.strptime(self.request.GET['month'], '%Y-%m')
|
||||
except:
|
||||
start_date = datetime(year=timezone.now().year, month=(timezone.now().month+10)%12+1, day=1)
|
||||
end_date = (start_date + timedelta(days=32)).replace(day=1, hour=0, minute=0, microsecond=0)
|
||||
from django.db.models import Sum, Case, When, F, DecimalField
|
||||
kwargs['sums'] = Selling.objects.values('club__name').annotate(selling_sum=Sum(
|
||||
Case(When(date__gte=start_date,
|
||||
date__lt=end_date,
|
||||
then=F('unit_price')*F('quantity')),
|
||||
output_field=CurrencyField()
|
||||
)
|
||||
)).exclude(selling_sum=None).order_by('-selling_sum')
|
||||
return kwargs
|
||||
|
||||
#).exclude(selling_sum=None).order_by('-selling_sum').all()[:100]
|
||||
|
Reference in New Issue
Block a user