Browse Source

Fix #2090 (#2091)

* Fix #2090

* HOT-FIX
pull/2102/head
Victor Fabre 7 years ago
committed by Edward
parent
commit
7d3ce7b265
  1. 9
      sapl/norma/views.py

9
sapl/norma/views.py

@ -1,4 +1,5 @@
import re
import weasyprint import weasyprint
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
@ -201,14 +202,12 @@ def recuperar_norma(request):
def recuperar_numero_norma(request): def recuperar_numero_norma(request):
tipo = TipoNormaJuridica.objects.get(pk=request.GET['tipo']) tipo = TipoNormaJuridica.objects.get(pk=request.GET['tipo'])
ano = request.GET.get('ano', '') ano = request.GET.get('ano', '')
param = {'tipo': tipo} param = {'tipo': tipo}
param['ano'] = ano if ano else timezone.now().year param['ano'] = ano if ano else timezone.now().year
norma = NormaJuridica.objects.filter(**param).extra( norma = NormaJuridica.objects.filter(**param).order_by(
{'numero_id': "CAST(numero as INTEGER)"}).order_by( 'tipo', 'ano').values_list('numero', 'ano').last()
'tipo', 'ano','numero_id').values_list('numero', 'ano').last()
if norma: if norma:
response = JsonResponse({'numero': int(norma[0]) + 1, response = JsonResponse({'numero': int(re.sub("[^0-9].*", '', norma[0])) + 1,
'ano': norma[1]}) 'ano': norma[1]})
else: else:
response = JsonResponse( response = JsonResponse(

Loading…
Cancel
Save