Merge branch 'Aufinal/history_form' into 'master'
On utilise un vrai formulaire pour l'historique Closes #242 See merge request klub-dev-ens/gestioCOF!461
This commit is contained in:
commit
84ff0d7182
8 changed files with 73 additions and 72 deletions
|
@ -7,6 +7,7 @@ from django.core import validators
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.forms import modelformset_factory
|
from django.forms import modelformset_factory
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from djconfig.forms import ConfigForm
|
from djconfig.forms import ConfigForm
|
||||||
|
|
||||||
from gestioncof.models import CofProfile
|
from gestioncof.models import CofProfile
|
||||||
|
@ -482,10 +483,23 @@ class KFetConfigForm(ConfigForm):
|
||||||
|
|
||||||
|
|
||||||
class FilterHistoryForm(forms.Form):
|
class FilterHistoryForm(forms.Form):
|
||||||
checkouts = forms.ModelMultipleChoiceField(queryset=Checkout.objects.all())
|
start = forms.DateTimeField(label=_("De"), widget=DateTimeWidget, required=False)
|
||||||
accounts = forms.ModelMultipleChoiceField(queryset=Account.objects.all())
|
end = forms.DateTimeField(label=_("À"), widget=DateTimeWidget, required=False)
|
||||||
from_date = forms.DateTimeField(widget=DateTimeWidget)
|
checkout = forms.ModelChoiceField(
|
||||||
to_date = forms.DateTimeField(widget=DateTimeWidget)
|
label=_("Caisse"),
|
||||||
|
queryset=Checkout.objects.all(),
|
||||||
|
required=False,
|
||||||
|
empty_label=_("Toutes les caisses"),
|
||||||
|
)
|
||||||
|
account = forms.ModelChoiceField(
|
||||||
|
label=_("Compte"),
|
||||||
|
queryset=Account.objects.all(),
|
||||||
|
required=False,
|
||||||
|
empty_label=_("Tous les comptes"),
|
||||||
|
)
|
||||||
|
|
||||||
|
transfers_only = forms.BooleanField(widget=forms.HiddenInput, required=False)
|
||||||
|
opes_only = forms.BooleanField(widget=forms.HiddenInput, required=False)
|
||||||
|
|
||||||
|
|
||||||
# -----
|
# -----
|
||||||
|
|
|
@ -109,3 +109,7 @@
|
||||||
#history .entry .glyphicon {
|
#history .entry .glyphicon {
|
||||||
padding-left:15px;
|
padding-left:15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#history-form .form-group {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
|
@ -205,17 +205,21 @@ function KHistory(options = {}) {
|
||||||
$group.find('.amount').text(amount);
|
$group.find('.amount').text(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fetch = function (fetch_options) {
|
this.fetch = function (fetch_options = {}) {
|
||||||
options = $.extend({}, this.fetch_options, fetch_options);
|
if (typeof (fetch_options) == "string")
|
||||||
var that = this;
|
data = fetch_options
|
||||||
|
else
|
||||||
|
data = $.extend({}, this.fetch_options, fetch_options);
|
||||||
|
|
||||||
return $.ajax({
|
return $.ajax({
|
||||||
|
context: this,
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
url: django_urls["kfet.history.json"](),
|
url: django_urls["kfet.history.json"](),
|
||||||
method: "POST",
|
method: "GET",
|
||||||
data: options,
|
data: data,
|
||||||
}).done(function (data) {
|
}).done(function (data) {
|
||||||
for (let group of data['groups']) {
|
for (let group of data['groups']) {
|
||||||
that.add_history_group(group);
|
this.add_history_group(group);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ $(document).ready(function() {
|
||||||
khistory = new KHistory({
|
khistory = new KHistory({
|
||||||
display_trigramme: false,
|
display_trigramme: false,
|
||||||
fetch_options: {
|
fetch_options: {
|
||||||
'accounts': [{{ account.pk }}],
|
account: {{ account.pk }},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% extends 'kfet/base_col_2.html' %}
|
{% extends 'kfet/base_col_2.html' %}
|
||||||
{% load l10n staticfiles widget_tweaks %}
|
{% load l10n staticfiles widget_tweaks bootstrap %}
|
||||||
|
|
||||||
{% block extra_head %}
|
{% block extra_head %}
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'kfet/vendor/multiple-select/multiple-select.css' %}">
|
<link rel="stylesheet" type="text/css" href="{% static 'kfet/vendor/multiple-select/multiple-select.css' %}">
|
||||||
|
@ -20,13 +20,8 @@
|
||||||
<span id="nb_opes"></span>
|
<span id="nb_opes"></span>
|
||||||
<span class="sub">opérations</span>
|
<span class="sub">opérations</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="text">
|
<div class="text" id="history-form">
|
||||||
<ul class="list-unstyled">
|
{{ filter_form|bootstrap}}
|
||||||
<li style="position: relative;"><b>De</b> {{ filter_form.from_date|add_class:"form-control" }}</li>
|
|
||||||
<li style="position: relative;"><b>à</b> {{ filter_form.to_date|add_class:"form-control" }}</li>
|
|
||||||
<li><b>Caisses</b> {{ filter_form.checkouts }}</li>
|
|
||||||
<li><b>Comptes</b> {{ filter_form.accounts }}</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button class="btn btn-primary" id="btn-fetch">Valider</button>
|
<button class="btn btn-primary" id="btn-fetch">Valider</button>
|
||||||
|
@ -48,30 +43,13 @@ $(document).ready(function() {
|
||||||
|
|
||||||
khistory = new KHistory();
|
khistory = new KHistory();
|
||||||
|
|
||||||
var $from_date = $('#id_from_date');
|
var $from_date = $('#id_start');
|
||||||
var $to_date = $('#id_to_date');
|
var $to_date = $('#id_end');
|
||||||
var $checkouts = $('#id_checkouts');
|
var $checkout = $('#id_checkout');
|
||||||
var $accounts = $('#id_accounts');
|
var $account = $('#id_account');
|
||||||
|
|
||||||
function getSelectedMultiple($el) {
|
|
||||||
var selected = [];
|
|
||||||
$el.find(':selected').each(function() {
|
|
||||||
selected.push($(this).val())
|
|
||||||
});
|
|
||||||
return selected;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getHistory() {
|
function getHistory() {
|
||||||
var data = {};
|
data = $("#history-form").find("input, select, textarea").serialize();
|
||||||
if ($from_date.val())
|
|
||||||
data['from'] = moment($from_date.val()).format('YYYY-MM-DD HH:mm:ss');
|
|
||||||
if ($to_date.val())
|
|
||||||
data['to'] = moment($to_date.val()).format('YYYY-MM-DD HH:mm:ss');
|
|
||||||
var checkouts = getSelectedMultiple($checkouts);
|
|
||||||
if ($checkouts)
|
|
||||||
data['checkouts'] = checkouts;
|
|
||||||
var accounts = getSelectedMultiple($accounts);
|
|
||||||
data['accounts'] = accounts;
|
|
||||||
|
|
||||||
khistory.fetch(data).done(function () {
|
khistory.fetch(data).done(function () {
|
||||||
var nb_opes = khistory.$container.find('.entry:not(.canceled)').length;
|
var nb_opes = khistory.$container.find('.entry:not(.canceled)').length;
|
||||||
|
@ -84,7 +62,11 @@ $(document).ready(function() {
|
||||||
format : 'YYYY-MM-DD HH:mm',
|
format : 'YYYY-MM-DD HH:mm',
|
||||||
stepping : 5,
|
stepping : 5,
|
||||||
locale : 'fr',
|
locale : 'fr',
|
||||||
showTodayButton: true
|
showTodayButton: true,
|
||||||
|
widgetPositioning: {
|
||||||
|
horizontal: "left",
|
||||||
|
vertical: "bottom",
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$from_date.datetimepicker($.extend({}, defaults_datetimepicker, {
|
$from_date.datetimepicker($.extend({}, defaults_datetimepicker, {
|
||||||
|
@ -101,14 +83,6 @@ $(document).ready(function() {
|
||||||
$('#from_date').data("DateTimePicker").maxDate(e.date);
|
$('#from_date').data("DateTimePicker").maxDate(e.date);
|
||||||
});
|
});
|
||||||
|
|
||||||
$("select").multipleSelect({
|
|
||||||
width: '100%',
|
|
||||||
filter: true,
|
|
||||||
allSelected: " ",
|
|
||||||
selectAllText: "Tout-te-s",
|
|
||||||
countSelected: "# sur %"
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#btn-fetch").on('click', function() {
|
$("#btn-fetch").on('click', function() {
|
||||||
khistory.reset();
|
khistory.reset();
|
||||||
getHistory();
|
getHistory();
|
||||||
|
|
|
@ -1142,8 +1142,8 @@ $(document).ready(function() {
|
||||||
|
|
||||||
khistory = new KHistory({
|
khistory = new KHistory({
|
||||||
fetch_options: {
|
fetch_options: {
|
||||||
from: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss'),
|
start: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss'),
|
||||||
opesonly: true,
|
opes_only: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
var khistory = new KHistory({
|
var khistory = new KHistory({
|
||||||
fetch_options:{
|
fetch_options:{
|
||||||
transfersonly: true,
|
transfers_only: true,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ from django.contrib.messages.views import SuccessMessageMixin
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import Count, F, Prefetch, Q, Sum
|
from django.db.models import Count, F, Prefetch, Q, Sum
|
||||||
from django.forms import formset_factory
|
from django.forms import formset_factory
|
||||||
from django.http import Http404, JsonResponse
|
from django.http import Http404, HttpResponseBadRequest, JsonResponse
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.urls import reverse, reverse_lazy
|
from django.urls import reverse, reverse_lazy
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
@ -1407,12 +1407,17 @@ def cancel_operations(request):
|
||||||
@login_required
|
@login_required
|
||||||
def history_json(request):
|
def history_json(request):
|
||||||
# Récupération des paramètres
|
# Récupération des paramètres
|
||||||
from_date = request.POST.get("from", None)
|
form = FilterHistoryForm(request.GET)
|
||||||
to_date = request.POST.get("to", None)
|
|
||||||
checkouts = request.POST.getlist("checkouts[]", None)
|
if not form.is_valid():
|
||||||
accounts = request.POST.getlist("accounts[]", None)
|
return HttpResponseBadRequest()
|
||||||
transfers_only = request.POST.get("transfersonly", False)
|
|
||||||
opes_only = request.POST.get("opesonly", False)
|
start = form.cleaned_data["start"]
|
||||||
|
end = form.cleaned_data["end"]
|
||||||
|
account = form.cleaned_data["account"]
|
||||||
|
checkout = form.cleaned_data["checkout"]
|
||||||
|
transfers_only = form.cleaned_data["transfers_only"]
|
||||||
|
opes_only = form.cleaned_data["opes_only"]
|
||||||
|
|
||||||
# Construction de la requête (sur les transferts) pour le prefetch
|
# Construction de la requête (sur les transferts) pour le prefetch
|
||||||
|
|
||||||
|
@ -1421,9 +1426,9 @@ def history_json(request):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Le check sur les comptes est dans le prefetch pour les transferts
|
# Le check sur les comptes est dans le prefetch pour les transferts
|
||||||
if accounts:
|
if account:
|
||||||
transfer_queryset_prefetch = transfer_queryset_prefetch.filter(
|
transfer_queryset_prefetch = transfer_queryset_prefetch.filter(
|
||||||
Q(from_acc__in=accounts) | Q(to_acc__in=accounts)
|
Q(from_acc=account) | Q(to_acc=account)
|
||||||
)
|
)
|
||||||
|
|
||||||
if not request.user.has_perm("kfet.is_team"):
|
if not request.user.has_perm("kfet.is_team"):
|
||||||
|
@ -1458,21 +1463,21 @@ def history_json(request):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Application des filtres
|
# Application des filtres
|
||||||
if from_date:
|
if start:
|
||||||
opegroups = opegroups.filter(at__gte=from_date)
|
opegroups = opegroups.filter(at__gte=start)
|
||||||
transfergroups = transfergroups.filter(at__gte=from_date)
|
transfergroups = transfergroups.filter(at__gte=start)
|
||||||
if to_date:
|
if end:
|
||||||
opegroups = opegroups.filter(at__lt=to_date)
|
opegroups = opegroups.filter(at__lt=end)
|
||||||
transfergroups = transfergroups.filter(at__lt=to_date)
|
transfergroups = transfergroups.filter(at__lt=end)
|
||||||
if checkouts:
|
if checkout:
|
||||||
opegroups = opegroups.filter(checkout__in=checkouts)
|
opegroups = opegroups.filter(checkout__in=checkout)
|
||||||
transfergroups = TransferGroup.objects.none()
|
transfergroups = TransferGroup.objects.none()
|
||||||
if transfers_only:
|
if transfers_only:
|
||||||
opegroups = OperationGroup.objects.none()
|
opegroups = OperationGroup.objects.none()
|
||||||
if opes_only:
|
if opes_only:
|
||||||
transfergroups = TransferGroup.objects.none()
|
transfergroups = TransferGroup.objects.none()
|
||||||
if accounts:
|
if account:
|
||||||
opegroups = opegroups.filter(on_acc__in=accounts)
|
opegroups = opegroups.filter(on_acc=account)
|
||||||
# Un non-membre de l'équipe n'a que accès à son historique
|
# Un non-membre de l'équipe n'a que accès à son historique
|
||||||
if not request.user.has_perm("kfet.is_team"):
|
if not request.user.has_perm("kfet.is_team"):
|
||||||
opegroups = opegroups.filter(on_acc=request.user.profile.account_kfet)
|
opegroups = opegroups.filter(on_acc=request.user.profile.account_kfet)
|
||||||
|
|
Loading…
Reference in a new issue