-
-
- De {{ filter_form.from_date|add_class:"form-control" }} -
- à {{ filter_form.to_date|add_class:"form-control" }} -
- Caisses {{ filter_form.checkouts }} -
- Comptes {{ filter_form.accounts }} -
+ {{ filter_form|bootstrap}}
@@ -48,30 +43,13 @@ $(document).ready(function() {
khistory = new KHistory();
- var $from_date = $('#id_from_date');
- var $to_date = $('#id_to_date');
- var $checkouts = $('#id_checkouts');
- var $accounts = $('#id_accounts');
-
- function getSelectedMultiple($el) {
- var selected = [];
- $el.find(':selected').each(function() {
- selected.push($(this).val())
- });
- return selected;
- }
+ var $from_date = $('#id_start');
+ var $to_date = $('#id_end');
+ var $checkout = $('#id_checkout');
+ var $account = $('#id_account');
function getHistory() {
- var data = {};
- 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;
+ data = $("#history-form").find("input, select, textarea").serialize();
khistory.fetch(data).done(function () {
var nb_opes = khistory.$container.find('.entry:not(.canceled)').length;
@@ -84,7 +62,11 @@ $(document).ready(function() {
format : 'YYYY-MM-DD HH:mm',
stepping : 5,
locale : 'fr',
- showTodayButton: true
+ showTodayButton: true,
+ widgetPositioning: {
+ horizontal: "left",
+ vertical: "bottom",
+ }
};
$from_date.datetimepicker($.extend({}, defaults_datetimepicker, {
@@ -101,14 +83,6 @@ $(document).ready(function() {
$('#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() {
khistory.reset();
getHistory();
diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html
index 7b292087..3d6ba2d1 100644
--- a/kfet/templates/kfet/kpsul.html
+++ b/kfet/templates/kfet/kpsul.html
@@ -1142,8 +1142,8 @@ $(document).ready(function() {
khistory = new KHistory({
fetch_options: {
- from: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss'),
- opesonly: true,
+ start: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss'),
+ opes_only: true,
},
});
diff --git a/kfet/templates/kfet/transfers.html b/kfet/templates/kfet/transfers.html
index 83f20c70..f8bef33d 100644
--- a/kfet/templates/kfet/transfers.html
+++ b/kfet/templates/kfet/transfers.html
@@ -36,7 +36,7 @@ $(document).ready(function() {
var khistory = new KHistory({
fetch_options:{
- transfersonly: true,
+ transfers_only: true,
}
});
diff --git a/kfet/views.py b/kfet/views.py
index 3a3c8cd0..2afbfbc5 100644
--- a/kfet/views.py
+++ b/kfet/views.py
@@ -15,7 +15,7 @@ from django.contrib.messages.views import SuccessMessageMixin
from django.db import transaction
from django.db.models import Count, F, Prefetch, Q, Sum
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.urls import reverse, reverse_lazy
from django.utils import timezone
@@ -1407,12 +1407,17 @@ def cancel_operations(request):
@login_required
def history_json(request):
# Récupération des paramètres
- from_date = request.POST.get("from", None)
- to_date = request.POST.get("to", None)
- checkouts = request.POST.getlist("checkouts[]", None)
- accounts = request.POST.getlist("accounts[]", None)
- transfers_only = request.POST.get("transfersonly", False)
- opes_only = request.POST.get("opesonly", False)
+ form = FilterHistoryForm(request.GET)
+
+ if not form.is_valid():
+ return HttpResponseBadRequest()
+
+ 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
@@ -1421,9 +1426,9 @@ def history_json(request):
)
# Le check sur les comptes est dans le prefetch pour les transferts
- if accounts:
+ if account:
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"):
@@ -1458,21 +1463,21 @@ def history_json(request):
)
# Application des filtres
- if from_date:
- opegroups = opegroups.filter(at__gte=from_date)
- transfergroups = transfergroups.filter(at__gte=from_date)
- if to_date:
- opegroups = opegroups.filter(at__lt=to_date)
- transfergroups = transfergroups.filter(at__lt=to_date)
- if checkouts:
- opegroups = opegroups.filter(checkout__in=checkouts)
+ if start:
+ opegroups = opegroups.filter(at__gte=start)
+ transfergroups = transfergroups.filter(at__gte=start)
+ if end:
+ opegroups = opegroups.filter(at__lt=end)
+ transfergroups = transfergroups.filter(at__lt=end)
+ if checkout:
+ opegroups = opegroups.filter(checkout__in=checkout)
transfergroups = TransferGroup.objects.none()
if transfers_only:
opegroups = OperationGroup.objects.none()
if opes_only:
transfergroups = TransferGroup.objects.none()
- if accounts:
- opegroups = opegroups.filter(on_acc__in=accounts)
+ if account:
+ opegroups = opegroups.filter(on_acc=account)
# Un non-membre de l'équipe n'a que accès à son historique
if not request.user.has_perm("kfet.is_team"):
opegroups = opegroups.filter(on_acc=request.user.profile.account_kfet)