Skip to content

Conversation

joaoguazzelli
Copy link

No description provided.

@joaoguazzelli joaoguazzelli changed the title feat: add recepcao evento cte WIP feat: add recepcao evento cte Jun 24, 2025
@felps-dev
Copy link
Collaborator

Os testes estão falhando, e consegue colocar uma descrição por favor?

@leotada leotada requested a review from Copilot June 25, 2025 03:17
Copy link

@Copilot 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 adds support for the CTe “recepção de evento” endpoint by updating dependency requirements, service URLs, and SOAP communication methods.

  • Adds pytz to dependencies for timezone handling
  • Extends webservices.py with new RECEPCAO_EVENTO endpoints per state
  • Implements prestacao_em_desacordo and evento methods and enhances SOAP envelope construction and headers in comunicacao.py

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
setup.py Added pytz to install_requires
pynfe/utils/webservices.py Introduced RECEPCAO_EVENTO URL entries for each state
pynfe/processamento/comunicacao.py Added event methods, updated _construir_xml_soap, _cabecalho_soap, and _post_header logic
Comments suppressed due to low confidence (2)

pynfe/processamento/comunicacao.py:1267

  • [nitpick] Consider adding a docstring to prestacao_em_desacordo explaining its purpose, parameters, and returned value to improve readability and maintainability.
    def prestacao_em_desacordo(self, chave_cte, cnpj, id_lote=1):

pynfe/processamento/comunicacao.py:1410

  • This method defines headers but does not explicitly return them in all code paths. Add return headers at the end of _post_header to ensure the caller receives the header dict.
    def _post_header(self, soap_action=None):

Comment on lines +1399 to +1402
elif metodo == 'CTeRecepcaoEventoV4':
a = etree.SubElement(
body, "cteDadosMsg", xmlns=NAMESPACE_CTE_METODO + metodo
)
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

This branch creates the same element as the else block below, making it redundant. You can remove this elif and let the else handle it.

Suggested change
elif metodo == 'CTeRecepcaoEventoV4':
a = etree.SubElement(
body, "cteDadosMsg", xmlns=NAMESPACE_CTE_METODO + metodo
)
# Removed redundant elif block; handled by the else block below.

Copilot uses AI. Check for mistakes.

dt_com_fuso = datetime.datetime.now(fuso_horario)
data_hora_evento_str = dt_com_fuso.strftime('%Y-%m-%dT%H:%M:%S%z')
data_hora = data_hora_evento_str[:-2] + ':' + data_hora_evento_str[-2:]
id_evento = f"ID610110{chave_cte}{str('1').zfill(3)}" # 610110 é o código do evento de prestacao de servico em desacordo
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

[nitpick] The use of str('1') is redundant; you can simply write '1'.zfill(3) to achieve the same result.

Suggested change
id_evento = f"ID610110{chave_cte}{str('1').zfill(3)}" # 610110 é o código do evento de prestacao de servico em desacordo
id_evento = f"ID610110{chave_cte}{'1'.zfill(3)}" # 610110 é o código do evento de prestacao de servico em desacordo

Copilot uses AI. Check for mistakes.

"requests",
"lxml",
"signxml",
"pytz"
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

[nitpick] It’s often safer to pin third-party dependencies to a version range (e.g., pytz>=2021.1,<2025.0) to avoid unexpected breaking changes when new releases come out.

Suggested change
"pytz"
"pytz>=2021.1,<2025.0"

Copilot uses AI. Check for mistakes.

@leotada
Copy link
Member

leotada commented Jun 25, 2025

não é necessário adicionar a dependencia pytz, dá para fazer sem. Outra ponto é fixar o timezone.

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.

3 participants