Commit 5b500689 authored by Skia's avatar Skia

Make sellings for clubs

parent 90e47c9d
Pipeline #208 failed with stage
in 1 minute and 55 seconds
{% extends "core/base.jinja" %}
{% block content %}
<div class="tool-bar">
<div>{{ club.name }}</div>
<div class="tools">
<a href="{{ url('club:club_view', club_id=club.id) }}"
{%- if tab == "infos" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Infos{% endtrans %}</a>
{% if can_view(club, user) %}
<a href="{{ url('club:club_members', club_id=club.pk) }}"
{%- if tab == "members" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Members{% endtrans %}</a>
{% endif %}
{% if can_view(club, user) %}
<a href="{{ url('club:club_old_members', club_id=club.pk) }}"
{%- if tab == "elderlies" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Old members{% endtrans %}</a>
{% endif %}
{% if can_view(club, user) %}
<a href="{{ url('club:tools', club_id=club.id) }}"
{%- if tab == "tools" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Tools{% endtrans %}</a>
{% endif %}
{% if can_edit(club, request.user) %}
<a href="{{ url('club:club_edit', club_id=club.id) }}"
{%- if tab == "edit" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Edit{% endtrans %}</a>
{% endif %}
{% if can_edit_prop(club, request.user) %}
<a href="{{ url('club:club_prop', club_id=club.id) }}"
{%- if tab == "props" -%}
class="selected_tab"
{%- endif -%}
>{% trans %}Props{% endtrans %}</a>
{% endif %}
</div>
<hr>
</div>
<div>
{% block club %}
{% endblock %}
</div>
{% endblock %}
......@@ -12,7 +12,7 @@
<td>{% trans %}To{% endtrans %}</td>
</thead>
<tbody>
{% for m in club.members.exclude(end_date=None).order_by('-role', '-end_date').all() %}
{% for m in club.members.exclude(end_date=None).order_by('-role', 'description', '-end_date').all() %}
<tr>
<td>{{ user_profile_link(m.user) }}</td>
<td>{{ settings.SITH_CLUB_ROLES[m.role] }}</td>
......
{% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import user_profile_link %}
{% block content %}
<h3>{% trans %}Sellings{% endtrans %}</h3>
<form action="" method="get">
{% csrf_token %}
{{ form }}
<p><input type="submit" value="{% trans %}Show{% endtrans %}" /></p>
</form>
<p>
{% trans %}Quantity: {% endtrans %}{{ result.count() }} {% trans %}units{% endtrans %}<br/>
{% trans %}Total: {% endtrans %}{{ total }}
</p>
<table>
<thead>
<tr>
<td>{% trans %}Date{% endtrans %}</td>
<td>{% trans %}Counter{% endtrans %}</td>
<td>{% trans %}Barman{% endtrans %}</td>
<td>{% trans %}Customer{% endtrans %}</td>
<td>{% trans %}Label{% endtrans %}</td>
<td>{% trans %}Quantity{% endtrans %}</td>
<td>{% trans %}Total{% endtrans %}</td>
<td>{% trans %}Payment method{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% for s in result %}
<tr>
<td>{{ s.date|localtime|date(DATETIME_FORMAT) }} {{ s.date|localtime|time(DATETIME_FORMAT) }}</td>
<td>{{ s.counter }}</td>
<td><a href="{{ s.seller.get_absolute_url() }}">{{ s.seller.get_display_name() }}</a></td>
<td><a href="{{ s.customer.user.get_absolute_url() }}">{{ s.customer.user.get_display_name() }}</a></td>
<td>{{ s.label }}</td>
<td>{{ s.quantity }}</td>
<td>{{ s.quantity * s.unit_price }}</td>
<td>{{ s.get_payment_method_display() }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
......@@ -9,6 +9,7 @@ urlpatterns = [
url(r'^(?P<club_id>[0-9]+)/edit$', ClubEditView.as_view(), name='club_edit'),
url(r'^(?P<club_id>[0-9]+)/members$', ClubMembersView.as_view(), name='club_members'),
url(r'^(?P<club_id>[0-9]+)/elderlies$', ClubOldMembersView.as_view(), name='club_old_members'),
url(r'^(?P<club_id>[0-9]+)/sellings$', ClubSellingView.as_view(), name='club_sellings'),
url(r'^(?P<club_id>[0-9]+)/prop$', ClubEditPropView.as_view(), name='club_prop'),
url(r'^(?P<club_id>[0-9]+)/tools$', ClubToolsView.as_view(), name='tools'),
url(r'^membership/(?P<membership_id>[0-9]+)/set_old$', MembershipSetOldView.as_view(), name='membership_set_old'),
......
......@@ -8,10 +8,15 @@ from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils import timezone
from django.utils.translation import ugettext as _
from django.conf import settings
from datetime import timedelta
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin
from core.views.forms import SelectDate, SelectSingle, SelectDateTime
from club.models import Club, Membership
from sith.settings import SITH_MAXIMUM_FREE_ROLE, SITH_MAIN_BOARD_GROUP
from counter.models import Product, Selling, Counter
class ClubTabsMixin(TabedViewMixin):
def get_tabs_title(self):
......@@ -46,6 +51,11 @@ class ClubTabsMixin(TabedViewMixin):
'slug': 'edit',
'name': _("Edit"),
})
tab_list.append({
'url': reverse('club:club_sellings', kwargs={'club_id': self.object.id}),
'slug': 'sellings',
'name': _("Sellings"),
})
if self.request.user.is_owner(self.object):
tab_list.append({
'url': reverse('club:club_prop', kwargs={'club_id': self.object.id}),
......@@ -143,6 +153,47 @@ class ClubOldMembersView(ClubTabsMixin, CanViewMixin, DetailView):
template_name = 'club/club_old_members.jinja'
current_tab = "elderlies"
class SellingsFormBase(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)
counter = forms.ModelChoiceField(Counter.objects.order_by('name').all(), label=_("Counter"), required=False)
class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailView):
"""
Sellings of a club
"""
model = Club
pk_url_kwarg = "club_id"
template_name = 'club/club_sellings.jinja'
current_tab = "sellings"
def get_form_class(self):
kwargs = {
'product': forms.ModelChoiceField(self.object.products.order_by('name').all(), label=_("Product"), required=False)
}
return type('SellingsForm', (SellingsFormBase,), kwargs)
def get_context_data(self, **kwargs):
kwargs = super(ClubSellingView, self).get_context_data(**kwargs)
form = self.get_form_class()(self.request.GET, initial={'begin_date': timezone.now()-timedelta(days=7)})
# form = self.get_form_class()(initial={'begin_date': timezone.now()-timedelta(days=7)})
qs = Selling.objects.filter(club=self.object)
if form.is_valid():
if form.cleaned_data['begin_date']:
qs = qs.filter(date__gte=form.cleaned_data['begin_date'])
if form.cleaned_data['end_date']:
qs = qs.filter(date__lte=form.cleaned_data['end_date'])
if form.cleaned_data['counter']:
qs = qs.filter(counter=form.cleaned_data['counter'])
if form.cleaned_data['product']:
qs = qs.filter(product__id=form.cleaned_data['product'].id)
kwargs['result'] = qs.all().order_by('-id')
kwargs['total'] = sum([s.quantity * s.unit_price for s in qs.all()])
else:
kwargs['result'] = qs[:0]
kwargs['form'] = form
return kwargs
class ClubEditView(ClubTabsMixin, CanEditMixin, UpdateView):
"""
Edit a Club's main informations (for the club's members)
......
This diff is collapsed.
This diff is collapsed.
......@@ -5,6 +5,7 @@
<title>{% block title %}{% trans %}Welcome!{% endtrans %}{% endblock %}</title>
<link rel="stylesheet" href="{{ static('core/base.css') }}">
<link rel="stylesheet" href="{{ static('core/multiple-select.css') }}">
<link rel="stylesheet" href="{{ static('core/jquery.datetimepicker.min.css') }}">
<link rel="stylesheet" href="{{ static('core/js/ui/jquery-ui.min.css') }}">
<link rel="stylesheet" href="{{ static('ajax_select/css/ajax_select.css') }}">
<link rel="stylesheet" href="{{ static('core/style.css') }}">
......@@ -113,8 +114,10 @@
<script src="{{ static('core/js/jquery-3.1.0.min.js') }}"></script>
<script src="{{ static('core/js/ui/jquery-ui.min.js') }}"></script>
<script src="{{ static('core/js/ui/i18n/datepicker-fr.js') }}"></script>
<script src="{{ static('core/js/jquery.datetimepicker.full.min.js') }}"></script>
<script src="{{ static('core/js/multiple-select.js') }}"></script>
<script src="{{ static('ajax_select/js/ajax_select.js') }}"></script>
<script src="{{ url('javascript-catalog') }}"></script>
<script src="{{ static('core/js/script.js') }}"></script>
<script>
$('.select_single').multipleSelect({
......@@ -146,6 +149,10 @@ $(document).keydown(function (e) {
return false;
}
});
jQuery.datetimepicker.setLocale('{{ request.LANGUAGE_CODE|lower }}');
$('.select_datetime').datetimepicker({
format: 'Y-m-d H:i:s',
});
</script>
{% endblock %}
</body>
......
......@@ -13,5 +13,17 @@ def markdown(text):
md = mistune.Markdown()
return mark_safe(md(escape(text)))
@register.filter()
@stringfilter
def datetime_format_python_to_PHP(python_format_string):
"""
Given a python datetime format string, attempts to convert it to the nearest PHP datetime format string possible.
"""
python2PHP = {"%a": "D", "%a": "D", "%A": "l", "%b": "M", "%B": "F", "%c": "", "%d": "d", "%H": "H", "%I": "h", "%j": "z", "%m": "m", "%M": "i", "%p": "A", "%S": "s", "%U": "", "%w": "w", "%W": "W", "%x": "", "%X": "", "%y": "y", "%Y": "Y", "%Z": "e" }
php_format_string = python_format_string
for py, php in python2PHP.items():
php_format_string = php_format_string.replace(py, php)
return php_format_string
......@@ -3,7 +3,7 @@ from django import forms
from django.db import transaction
from django.core.exceptions import ValidationError
from django.contrib.auth import logout, login, authenticate
from django.forms import CheckboxSelectMultiple, Select, DateInput, TextInput
from django.forms import CheckboxSelectMultiple, Select, DateInput, TextInput, DateTimeInput
from django.utils.translation import ugettext as _
from phonenumber_field.widgets import PhoneNumberInternationalFallbackWidget
......@@ -31,6 +31,14 @@ class SelectMultiple(Select):
attrs = {'class': "select_multiple"}
return super(SelectMultiple, self).render(name, value, attrs)
class SelectDateTime(DateTimeInput):
def render(self, name, value, attrs=None):
if attrs:
attrs['class'] = "select_datetime"
else:
attrs = {'class': "select_datetime"}
return super(SelectDateTime, self).render(name, value, attrs)
class SelectDate(DateInput):
def render(self, name, value, attrs=None):
if attrs:
......
This diff is collapsed.
......@@ -17,8 +17,13 @@ from django.conf.urls import include, url
from django.contrib import admin
from django.conf.urls.static import static
from django.conf import settings
from django.views.i18n import javascript_catalog
from ajax_select import urls as ajax_select_urls
js_info_dict = {
'packages': ('sith',),
}
handler403 = "core.views.forbidden"
handler404 = "core.views.not_found"
......@@ -34,5 +39,6 @@ urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^ajax_select/', include(ajax_select_urls)),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript-catalog'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # TODO: remove me for production!!!
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment