From 0b4b1518dc624170c11afb43ca55657cec926281 Mon Sep 17 00:00:00 2001 From: joao Date: Mon, 15 Aug 2022 10:23:02 -0300 Subject: [PATCH] fix: ajuste expediente materia e ordemdia para salvar tramitacao nula --- sapl/sessao/forms.py | 30 ++++++++----------- .../migrations/0068_auto_20220816_1117.py | 24 +++++++++++++++ sapl/sessao/models.py | 2 +- .../sessao/expedientemateria_form.html | 2 +- 4 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 sapl/sessao/migrations/0068_auto_20220816_1117.py diff --git a/sapl/sessao/forms.py b/sapl/sessao/forms.py index 4a7f6838a..5e0411ad2 100644 --- a/sapl/sessao/forms.py +++ b/sapl/sessao/forms.py @@ -322,7 +322,7 @@ class ExpedienteMateriaForm(ModelForm): widget=forms.Select(attrs={'autocomplete': 'off'})) tramitacao_select = DependentChoiceField( - label=_('Situação Atual'), + label=_('Situação de Pauta'), widget=forms.Select()) numero_materia = forms.CharField( @@ -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/sessao/migrations/0068_auto_20220816_1117.py b/sapl/sessao/migrations/0068_auto_20220816_1117.py new file mode 100644 index 000000000..74cce67f7 --- /dev/null +++ b/sapl/sessao/migrations/0068_auto_20220816_1117.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2.28 on 2022-08-16 14:17 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('sessao', '0067_auto_20220813_2233'), + ] + + operations = [ + migrations.AlterField( + model_name='expedientemateria', + name='tramitacao', + field=models.ForeignKey(blank=True, default='', null=True, on_delete=django.db.models.deletion.PROTECT, to='materia.Tramitacao', verbose_name='Situação de Pauta'), + ), + migrations.AlterField( + model_name='ordemdia', + name='tramitacao', + field=models.ForeignKey(blank=True, default='', null=True, on_delete=django.db.models.deletion.PROTECT, to='materia.Tramitacao', verbose_name='Situação de Pauta'), + ), + ] diff --git a/sapl/sessao/models.py b/sapl/sessao/models.py index 129703fe4..538397ecc 100644 --- a/sapl/sessao/models.py +++ b/sapl/sessao/models.py @@ -375,7 +375,7 @@ class AbstractOrdemDia(models.Model): verbose_name=_('Matéria')) tramitacao = models.ForeignKey(Tramitacao, on_delete=models.PROTECT, - verbose_name=_('Situação Atual'), + verbose_name=_('Situação de Pauta'), blank=True, default='', null=True) 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 = $(``)