From cc85c2624f81cd6a7cc0c82ec90667bb7599793e Mon Sep 17 00:00:00 2001 From: joao Date: Mon, 15 Aug 2022 10:23:02 -0300 Subject: [PATCH 1/2] fix: ajuste expediente materia e ordemdia para salvar tramitacao nula --- sapl/sessao/forms.py | 28 ++++++++----------- .../sessao/expedientemateria_form.html | 2 +- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/sapl/sessao/forms.py b/sapl/sessao/forms.py index 4a7f6838a..9f0494a54 100644 --- a/sapl/sessao/forms.py +++ b/sapl/sessao/forms.py @@ -368,8 +368,6 @@ class ExpedienteMateriaForm(ModelForm): if not self.is_valid(): return cleaned_data - sessao = self.instance.sessao_plenaria - try: materia = MateriaLegislativa.objects.get( numero=self.cleaned_data['numero_materia'], @@ -383,28 +381,26 @@ class ExpedienteMateriaForm(ModelForm): cleaned_data['materia'] = materia try: - id_t = self.cleaned_data['tramitacao_select'] if self.cleaned_data['tramitacao_select'] != '' else -1 - tramitacao = materia.tramitacao_set.get( - pk=self.cleaned_data['tramitacao_select'] if self.cleaned_data['tramitacao_select'] != '' else -1) + if materia.tramitacao_set.exists() and self.cleaned_data['tramitacao_select']: + tramitacao = materia.tramitacao_set.get( + pk=self.cleaned_data['tramitacao_select']) + cleaned_data['tramitacao'] = tramitacao except ObjectDoesNotExist: - if self.cleaned_data['tramitacao_select'] != '': - raise ValidationError( - _('Tramitação selecionada não existe para a Matéria: %(value)s'), - code='invalid', - params={'value': self.cleaned_data['tramitacao_select']}, - ) - else: - cleaned_data['tramitacao'] = False - else: - cleaned_data['tramitacao'] = tramitacao + raise ValidationError( + _('Tramitação selecionada não existe para a Matéria: %(value)s'), + code='invalid', + params={'value': self.cleaned_data['tramitacao_select']}, + ) return cleaned_data def save(self, commit=False): expediente = super(ExpedienteMateriaForm, self).save(commit) expediente.materia = self.cleaned_data['materia'] - if self.cleaned_data['tramitacao'] is not False: + if 'tramitacao' in self.cleaned_data and self.cleaned_data['tramitacao']: expediente.tramitacao = self.cleaned_data['tramitacao'] + else: + expediente.tramitacao = None expediente.save() return expediente diff --git a/sapl/templates/sessao/expedientemateria_form.html b/sapl/templates/sessao/expedientemateria_form.html index c11517dd2..f17e143f7 100644 --- a/sapl/templates/sessao/expedientemateria_form.html +++ b/sapl/templates/sessao/expedientemateria_form.html @@ -67,7 +67,7 @@ if (status == 'success') { $('#id_tramitacao_select').off('change') $('#id_tramitacao_select').find('option').remove() - $('#id_tramitacao_select').append(''); + $('#id_tramitacao_select').append(''); for (const property in data) { console.log(tramitacao_salvo + "===" + property) const option = $(``) From 92bde8eb5aecbae2eeb6fdd1394fe2b435e86c39 Mon Sep 17 00:00:00 2001 From: LeandroJatai Date: Mon, 15 Aug 2022 15:16:07 -0300 Subject: [PATCH 2/2] fix: corrige choice de correspondencia --- .../migrations/0068_auto_20220815_1515.py | 18 ++++++++++++++++++ sapl/sessao/models.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 sapl/sessao/migrations/0068_auto_20220815_1515.py diff --git a/sapl/sessao/migrations/0068_auto_20220815_1515.py b/sapl/sessao/migrations/0068_auto_20220815_1515.py new file mode 100644 index 000000000..1bb635850 --- /dev/null +++ b/sapl/sessao/migrations/0068_auto_20220815_1515.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.28 on 2022-08-15 18:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sessao', '0067_auto_20220813_2233'), + ] + + operations = [ + migrations.AlterField( + model_name='correspondencia', + name='tipo', + field=models.PositiveIntegerField(choices=[(1, 'Recebida'), (2, 'Enviada'), (3, 'Interna')], default=1, verbose_name='Tipo da Correspondência'), + ), + ] diff --git a/sapl/sessao/models.py b/sapl/sessao/models.py index 129703fe4..5ca0a2d0a 100644 --- a/sapl/sessao/models.py +++ b/sapl/sessao/models.py @@ -1042,7 +1042,7 @@ class Correspondencia(models.Model): TIPO_CHOICES = Choices( (1, 'recebida', 'Recebida'), (2, 'enviada', 'Enviada'), - (2, 'interna', 'Interna'), + (3, 'interna', 'Interna'), ) sessao_plenaria = models.ForeignKey(SessaoPlenaria,