Skip to content

Conversation

@LeandroJatai
Copy link
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

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.

LeandroJatai and others added 7 commits January 27, 2026 17:02
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 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
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.

1 participant