add a simple additional filter to make the cpf filter more interesting
gitea/barbacompta/pipeline/head This commit looks good
Details
gitea/barbacompta/pipeline/head This commit looks good
Details
This commit is contained in:
parent
5d7894bfab
commit
4b461758ce
|
@ -26,7 +26,7 @@ from django.contrib import admin
|
|||
from django.contrib.admin.options import BaseModelAdmin
|
||||
from django.contrib.humanize.templatetags.humanize import ordinal
|
||||
from django.db import transaction
|
||||
from django.db.models import TextField
|
||||
from django.db.models import Exists, OuterRef, TextField
|
||||
from django.forms import Textarea
|
||||
from django.forms.models import BaseInlineFormSet
|
||||
from django.shortcuts import render
|
||||
|
@ -158,11 +158,35 @@ class MyClientsFilter(admin.SimpleListFilter):
|
|||
return queryset
|
||||
|
||||
|
||||
class LastBillAgeFilter(admin.SimpleListFilter):
|
||||
title = 'last bill age'
|
||||
parameter_name = 'last_bill_age'
|
||||
|
||||
def value(self):
|
||||
value = super().value()
|
||||
return value if value in ('3', '6', '12') else 'all'
|
||||
|
||||
def choices(self, changelist):
|
||||
choices = list(super().choices(changelist))
|
||||
return choices[1:] # don't include automatic "All"
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
return [('all', 'tous'), ('3', 'plus de 3 mois'), ('6', 'plus de 6 mois'), ('12', 'plus de 12 mois')]
|
||||
|
||||
def queryset(self, request, queryset):
|
||||
if self.value() == 'all':
|
||||
return queryset
|
||||
else:
|
||||
min_date = dt.date.today() - dt.timedelta(days=30 * int(self.value()))
|
||||
subquery = models.Facture.objects.filter(emission__gte=min_date, client=OuterRef('pk'))
|
||||
return queryset.exclude(Exists(subquery))
|
||||
|
||||
|
||||
class ClientAdmin(admin.ModelAdmin):
|
||||
form = forms.ClientForm
|
||||
list_display = ['nom', 'adresse', 'email', 'telephone']
|
||||
list_editable = ['email', 'telephone']
|
||||
list_filter = [ActiveFilter, MyClientsFilter]
|
||||
list_filter = [ActiveFilter, MyClientsFilter, LastBillAgeFilter]
|
||||
ordering = ['nom']
|
||||
search_fields = ['nom', 'email']
|
||||
save_on_top = True
|
||||
|
|
Loading…
Reference in New Issue