From 1f41f44651c0392fb3e265c9f748df5fed46d21e Mon Sep 17 00:00:00 2001 From: Ricardo Lima Canela Date: Thu, 21 Feb 2019 12:04:54 -0300 Subject: [PATCH] fix #2415 (#2532) co-authored-by: Victor Fabre --- sapl/materia/forms.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 9161f9eb8..05e3d3161 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -495,6 +495,20 @@ class TramitacaoForm(ModelForm): return cleaned_data + @transaction.atomic + def save(self, commit=True): + tramitacao = super(TramitacaoForm, self).save(commit) + materia = tramitacao.materia + for ma in materia.anexadas.all(): + if not ma.tramitacao_set.all() \ + or ma.tramitacao_set.last().unidade_tramitacao_destino == tramitacao.unidade_tramitacao_local: + tramitacao_nova = tramitacao + tramitacao_nova.pk = None + tramitacao_nova.materia = ma + tramitacao_nova.save() + + return tramitacao + class TramitacaoUpdateForm(TramitacaoForm): unidade_tramitacao_local = forms.ModelChoiceField(