From 4a8e8dee4b01cd2c3280e21e720679f02a9dd7fb Mon Sep 17 00:00:00 2001 From: Antonio Neto Date: Mon, 6 May 2024 13:41:00 -0300 Subject: [PATCH] ambiente autorizador de contingencia para nfe --- src/erpbrasil/edoc/nfe.py | 95 ++++++++++++++++++++++++++++++++++----- 1 file changed, 84 insertions(+), 11 deletions(-) diff --git a/src/erpbrasil/edoc/nfe.py b/src/erpbrasil/edoc/nfe.py index df034f5..6ccb95e 100644 --- a/src/erpbrasil/edoc/nfe.py +++ b/src/erpbrasil/edoc/nfe.py @@ -166,6 +166,7 @@ SVC_AN = { AMBIENTE_PRODUCAO: { "servidor": "www.svc.fazenda.gov.br", + WS_NFE_INUTILIZACAO: "NFeInutilizacao4/NFeInutilizacao4.asmx?wsdl", WS_NFE_CONSULTA: "NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx?wsdl", # noqa WS_NFE_SITUACAO: "NFeStatusServico4/NFeStatusServico4.asmx?wsdl", WS_NFE_RECEPCAO_EVENTO: "NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx?wsdl", # noqa @@ -173,7 +174,8 @@ WS_NFE_RET_AUTORIZACAO: "NFeRetAutorizacao4/NFeRetAutorizacao4.asmx?wsdl", # noqa }, AMBIENTE_HOMOLOGACAO: { - "servidor": "hom.svc.fazenda.gov.br", + "servidor": "hom.sefazvirtual.fazenda.gov.br", + WS_NFE_INUTILIZACAO: "NFeInutilizacao4/NFeInutilizacao4.asmx?wsdl", WS_NFE_CONSULTA: "NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx?wsdl", # noqa WS_NFE_SITUACAO: "NFeStatusServico4/NFeStatusServico4.asmx?wsdl", WS_NFE_RECEPCAO_EVENTO: "NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx?wsdl", # noqa @@ -675,10 +677,41 @@ "AN": AN, } +ESTADO_WS_CONTINGENCIA = { + "AC": SVC_AN, + "AL": SVC_AN, + "AM": SVC_RS, + "AP": SVC_AN, + "BA": SVC_RS, + "CE": SVC_AN, + "DF": SVC_AN, + "ES": SVC_AN, + "GO": SVC_RS, + "MA": SVC_RS, + "MG": SVC_AN, + "MS": SVC_RS, + "MT": SVC_RS, + "PA": SVC_AN, + "PB": SVC_AN, + "PE": SVC_RS, + "PI": SVC_RS, + "PR": SVC_RS, + "RJ": SVC_AN, + "RN": SVC_AN, + "RO": SVC_AN, + "RR": SVC_AN, + "RS": SVC_AN, + "SC": SVC_AN, + "SE": SVC_AN, + "SP": SVC_AN, + "TO": SVC_AN, +} + -def localizar_url(servico, estado, mod="55", ambiente=2): +def localizar_url(servico, estado, mod="55", ambiente=2, contingencia=False): sigla = SIGLA_ESTADO[estado] - ws = ESTADO_WS[sigla] + + ws = ESTADO_WS_CONTINGENCIA[sigla] if contingencia else ESTADO_WS[sigla] if servico in (WS_DFE_DISTRIBUICAO, WS_DOWNLOAD_NFE): ws = AN @@ -734,12 +767,14 @@ def __init__( ambiente="2", mod="55", envio_sincrono=False, + contingencia=False, ): super().__init__(transmissao, envio_sincrono) self.versao = str(versao) self.ambiente = str(ambiente) self.uf = int(uf) self.mod = str(mod) + self.contingencia = contingencia def _edoc_situacao_ja_enviado(self, proc_consulta): if proc_consulta.resposta.cStat in ("100", "110", "150", "301", "302"): @@ -760,7 +795,13 @@ def status_servico(self): return self._post( raiz, # 'https://hom.sefazvirtual.fazenda.gov.br/NFeStatusServico4/NFeStatusServico4.asmx?wsdl', - localizar_url(WS_NFE_SITUACAO, str(self.uf), self.mod, int(self.ambiente)), + localizar_url( + WS_NFE_SITUACAO, + str(self.uf), + self.mod, + int(self.ambiente), + self.contingencia, + ), "nfeStatusServicoNF", retConsStatServ, ) @@ -777,7 +818,13 @@ def consulta_documento(self, chave): return self._post( raiz, # 'https://hom.sefazvirtual.fazenda.gov.br/NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx?wsdl', - localizar_url(WS_NFE_CONSULTA, str(self.uf), self.mod, int(self.ambiente)), + localizar_url( + WS_NFE_CONSULTA, + str(self.uf), + self.mod, + int(self.ambiente), + self.contingencia, + ), "nfeConsultaNF", retConsSitNFe, ) @@ -806,7 +853,11 @@ def envia_documento(self, edoc): xml_envio_etree, # 'https://hom.sefazvirtual.fazenda.gov.br/NFeAutorizacao4/NFeAutorizacao4.asmx?wsdl', localizar_url( - WS_NFE_AUTORIZACAO, str(self.uf), self.mod, int(self.ambiente) + WS_NFE_AUTORIZACAO, + str(self.uf), + self.mod, + int(self.ambiente), + self.contingencia, ), "nfeAutorizacaoLote", retEnviNFe, @@ -823,7 +874,11 @@ def envia_inutilizacao(self, evento): return self._post( xml_envio_etree, localizar_url( - WS_NFE_INUTILIZACAO, str(self.uf), self.mod, int(self.ambiente) + WS_NFE_INUTILIZACAO, + str(self.uf), + self.mod, + int(self.ambiente), + self.contingencia, ), "nfeInutilizacaoNF", retInutNFe, @@ -845,7 +900,11 @@ def consulta_recibo(self, numero=False, proc_envio=False): return self._post( raiz, localizar_url( - WS_NFE_RET_AUTORIZACAO, str(self.uf), self.mod, int(self.ambiente) + WS_NFE_RET_AUTORIZACAO, + str(self.uf), + self.mod, + int(self.ambiente), + self.contingencia, ), # 'ws/nferetautorizacao4.asmx' "nfeRetAutorizacaoLote", @@ -872,7 +931,11 @@ def enviar_lote_evento(self, lista_eventos, numero_lote=False): return self._post( xml_envio_etree, localizar_url( - WS_NFE_RECEPCAO_EVENTO, str(self.uf), self.mod, int(self.ambiente) + WS_NFE_RECEPCAO_EVENTO, + str(self.uf), + self.mod, + int(self.ambiente), + self.contingencia, ), "nfeRecepcaoEvento", retEnvEvento, @@ -1024,7 +1087,11 @@ def consultar_distribuicao( return self._post( raiz, localizar_url( - WS_DFE_DISTRIBUICAO, str(self.uf), self.mod, int(self.ambiente) + WS_DFE_DISTRIBUICAO, + str(self.uf), + self.mod, + int(self.ambiente), + self.contingencia, ), "nfeDistDFeInteresse", retDistDFeInt, @@ -1091,7 +1158,13 @@ def consultar_cadastro(self, uf, cnpj=None, cpf=None, ie=None): return self._post( raiz, - localizar_url(WS_NFE_CADASTRO, str(self.uf), self.mod, int(self.ambiente)), + localizar_url( + WS_NFE_CADASTRO, + str(self.uf), + self.mod, + int(self.ambiente), + self.contingencia, + ), "consultaCadastro", retConsCad, )