From afdba539f08db02d50039206c7b6632c86b1e6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Mon, 24 May 2021 23:29:17 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=A3o=20filtro=20servi=C3=A7os?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/servicos/admin.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/sigi/apps/servicos/admin.py b/sigi/apps/servicos/admin.py index 843ee3a..6d77a33 100644 --- a/sigi/apps/servicos/admin.py +++ b/sigi/apps/servicos/admin.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -from datetime import date -from dateutil.relativedelta import relativedelta +from datetime import date, timedelta from django.contrib import admin from django.core.urlresolvers import reverse from django.forms.models import ModelForm @@ -73,22 +72,22 @@ class DataUtimoUsoFilter(admin.SimpleListFilter): if self.value() == 'err': queryset = queryset.exclude(erro_atualizacao="") elif self.value() == 'year': - limite = date.today() - relativedelta(years=1) + limite = date.today() - timedelta(days=365) queryset = queryset.filter(data_ultimo_uso__lte=limite) else: de = date.today() - ( - relativedelta(months=6) if self.value() == 'semester' else - relativedelta(months=3) if self.value() == 'quarter' else - relativedelta(months=1) if self.value() == 'month' else - relativedelta(days=7) if self.value() == 'week' else - relativedelta(days=0) + timedelta(days=6*30) if self.value() == 'semester' else + timedelta(days=3*30) if self.value() == 'quarter' else + timedelta(days=30) if self.value() == 'month' else + timedelta(days=7) if self.value() == 'week' else + timedelta(days=0) ) ate = date.today() - ( - relativedelta(years=1) if self.value() == 'semester' else - relativedelta(months=6) if self.value() == 'quarter' else - relativedelta(months=3) if self.value() == 'month' else - relativedelta(months=1) if self.value() == 'week' else - relativedelta(days=0) + timedelta(days=365) if self.value() == 'semester' else + timedelta(days=6*30) if self.value() == 'quarter' else + timedelta(days=3*30) if self.value() == 'month' else + timedelta(days=30) if self.value() == 'week' else + timedelta(days=0) ) print (de, ate) queryset = queryset.filter(data_ultimo_uso__range=(de, ate))