From 872b9069d5d31ee8979c1bb9f7937f499208c1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Fri, 7 Dec 2012 08:54:07 -0200 Subject: [PATCH] Forma correta para garantir que o valor_executado de uma meta seja sempre um float, evitando erros em calculos. --- sigi/apps/metas/models.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sigi/apps/metas/models.py b/sigi/apps/metas/models.py index d14d094..e30d648 100644 --- a/sigi/apps/metas/models.py +++ b/sigi/apps/metas/models.py @@ -37,7 +37,10 @@ class Meta(models.Model): """ algoritmo = self.algoritmo.lower() valor = getattr(self, algoritmo)() - valor = valor if type(valor) is float else 0.0 + try: + valor = float(valor) + except: + valor = 0.0 return valor @property @@ -81,7 +84,7 @@ class Meta(models.Model): def sum_gastos(self): valor = Desembolso.objects.filter(projeto=self.projeto, data__gte=self.data_inicio, data__lte=self.data_fim) \ .aggregate(total_dolar=models.Sum('valor_dolar')) - valor = valor['total_dolar'] if type(valor['total_dolar']) is float else 0.0 + valor = valor['total_dolar'] return valor def count_equi(self):