Skip to content

#3821 centralizar geração próximo número para create de matérias legislativas#3822

Merged
edwardoliveira merged 17 commits intointerlegis:3.1.xfrom
LeandroJatai:3821_centralizar_geracao_proximo_numero_ml
Mar 26, 2026
Merged

#3821 centralizar geração próximo número para create de matérias legislativas#3822
edwardoliveira merged 17 commits intointerlegis:3.1.xfrom
LeandroJatai:3821_centralizar_geracao_proximo_numero_ml

Conversation

@LeandroJatai
Copy link
Copy Markdown
Member

Atualmente a geração de próximo número para matérias é um código replicado em dois pontos:

sapl.materia.forms.ConfirmarProposicaoForm.save()
sapl.materia.views.recuperar_materia()

Um terceiro local se faz necessário, no create da API, em _MateriaLegislativaViewSet, além de outros que possam surgir no futuro.

Este PR centraliza a geração de próximo número em um método estático no model MateriaLegislativa, refatora ConfirmarProposicaoForm e recuperar_materia, além de criar o método create na viewset para que em POSTs seja aplicada a mesma lógica de numeração configurada em Configurações da Aplicação e na sequencia de numeração do tipo de matéria.

Descrição

Issue Relacionada

#3821

Motivação e Contexto

Centraliza a geração de próximo número para matéria legislativa e remove duplicidade de código.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR centralizes the logic for generating the next sequential number for legislative matters (MateriaLegislativa) into a single static method get_proximo_numero() in the MateriaLegislativa model. Previously, this logic was duplicated in ConfirmarProposicaoForm.save() and recuperar_materia() view function. The refactoring removes code duplication and adds support for the same numbering logic in the API's create endpoint.

Changes:

  • Added static method get_proximo_numero() to MateriaLegislativa model to centralize number generation logic
  • Refactored recuperar_materia() view and ConfirmarProposicaoForm.save() to use the new centralized method
  • Implemented custom create() method in the API viewset to apply automatic numbering to API-created matters

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
sapl/materia/models.py Added centralized get_proximo_numero() static method that handles all numbering sequence types (A, L, U) and supports preferred numbers
sapl/materia/views.py Refactored recuperar_materia() to use the new centralized method, removing ~40 lines of duplicated logic
sapl/materia/forms.py Refactored ConfirmarProposicaoForm.save() to use the new centralized method, removing ~35 lines of duplicated logic
sapl/api/views_materia.py Added custom create() method to apply automatic numbering when creating MateriaLegislativa via API
sapl/api/serializers.py Added import for MateriaLegislativa model to support API changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sapl/api/views_materia.py Outdated
Comment thread sapl/api/serializers.py Outdated
Comment thread sapl/api/views_materia.py Outdated
Comment thread sapl/materia/models.py
Comment thread sapl/materia/models.py Outdated
Comment thread sapl/materia/models.py Outdated
Comment thread sapl/materia/models.py Outdated
Comment thread sapl/materia/models.py Outdated
Comment thread sapl/materia/models.py Outdated
@LeandroJatai LeandroJatai changed the title #3821 centralizar geracao proximo numero ml #3821 centralizar geração próximo número para create de matérias legislativas Jan 28, 2026
@joaohortsenado joaohortsenado self-requested a review March 14, 2026 11:35
Copy link
Copy Markdown
Contributor

@joaohortsenado joaohortsenado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeandroJatai no geral achei a mudança ótima e necessária, sempre que pudermos melhorar a reusabilidade do código é excelente.
Fiz comentários em alguns pontos, @edwardoliveira se você puder dar uma conferida, podem haver casos de tech debt antigo que talvez possamos passar em PR específico.

Comment thread sapl/api/views_materia.py Outdated
Comment thread sapl/materia/models.py
Comment thread sapl/materia/models.py Outdated
Comment thread sapl/api/views_materia.py Outdated
Comment thread sapl/api/views_materia.py Outdated
Comment thread sapl/materia/views.py
Comment thread sapl/materia/models.py Outdated
Comment thread sapl/materia/models.py
Comment thread sapl/api/views_materia.py Outdated
Comment thread sapl/api/views_materia.py Outdated
Comment thread sapl/materia/models.py Outdated
Comment thread sapl/materia/models.py Outdated
Comment thread sapl/api/views_materia.py Outdated
LeandroJatai and others added 9 commits March 16, 2026 07:42
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@LeandroJatai LeandroJatai force-pushed the 3821_centralizar_geracao_proximo_numero_ml branch from f96a98f to a9f66a9 Compare March 16, 2026 10:42
Comment thread sapl/materia/views.py
@edwardoliveira edwardoliveira merged commit f6c2ec5 into interlegis:3.1.x Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants