Skip to content

Commit bf8fa64

Browse files
committed
ambiente autorizador de contingencia para nfe
1 parent 0499709 commit bf8fa64

File tree

1 file changed

+65
-21
lines changed

1 file changed

+65
-21
lines changed

src/erpbrasil/edoc/nfe.py

+65-21
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,16 @@
166166
SVC_AN = {
167167
AMBIENTE_PRODUCAO: {
168168
"servidor": "www.svc.fazenda.gov.br",
169+
WS_NFE_INUTILIZACAO: "NFeInutilizacao4/NFeInutilizacao4.asmx?wsdl",
169170
WS_NFE_CONSULTA: "NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx?wsdl", # noqa
170171
WS_NFE_SITUACAO: "NFeStatusServico4/NFeStatusServico4.asmx?wsdl",
171172
WS_NFE_RECEPCAO_EVENTO: "NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx?wsdl", # noqa
172173
WS_NFE_AUTORIZACAO: "NFeAutorizacao4/NFeAutorizacao4.asmx?wsdl",
173174
WS_NFE_RET_AUTORIZACAO: "NFeRetAutorizacao4/NFeRetAutorizacao4.asmx?wsdl", # noqa
174175
},
175176
AMBIENTE_HOMOLOGACAO: {
176-
"servidor": "hom.svc.fazenda.gov.br",
177+
"servidor": "hom.sefazvirtual.fazenda.gov.br",
178+
WS_NFE_INUTILIZACAO: "NFeInutilizacao4/NFeInutilizacao4.asmx?wsdl",
177179
WS_NFE_CONSULTA: "NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx?wsdl", # noqa
178180
WS_NFE_SITUACAO: "NFeStatusServico4/NFeStatusServico4.asmx?wsdl",
179181
WS_NFE_RECEPCAO_EVENTO: "NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx?wsdl", # noqa
@@ -675,10 +677,41 @@
675677
"AN": AN,
676678
}
677679

680+
ESTADO_WS_CONTINGENCIA = {
681+
"AC": SVC_AN,
682+
"AL": SVC_AN,
683+
"AM": SVC_RS,
684+
"AP": SVC_AN,
685+
"BA": SVC_RS,
686+
"CE": SVC_AN,
687+
"DF": SVC_AN,
688+
"ES": SVC_AN,
689+
"GO": SVC_RS,
690+
"MA": SVC_RS,
691+
"MG": SVC_AN,
692+
"MS": SVC_RS,
693+
"MT": SVC_RS,
694+
"PA": SVC_AN,
695+
"PB": SVC_AN,
696+
"PE": SVC_RS,
697+
"PI": SVC_RS,
698+
"PR": SVC_RS,
699+
"RJ": SVC_AN,
700+
"RN": SVC_AN,
701+
"RO": SVC_AN,
702+
"RR": SVC_AN,
703+
"RS": SVC_AN,
704+
"SC": SVC_AN,
705+
"SE": SVC_AN,
706+
"SP": SVC_AN,
707+
"TO": SVC_AN,
708+
}
709+
678710

679-
def localizar_url(servico, estado, mod="55", ambiente=2):
711+
def localizar_url(servico, estado, mod="55", ambiente=2, contingencia=False):
680712
sigla = SIGLA_ESTADO[estado]
681-
ws = ESTADO_WS[sigla]
713+
714+
ws = ESTADO_WS_CONTINGENCIA[sigla] if contingencia else ESTADO_WS[sigla]
682715

683716
if servico in (WS_DFE_DISTRIBUICAO, WS_DOWNLOAD_NFE):
684717
ws = AN
@@ -734,18 +767,39 @@ def __init__(
734767
ambiente="2",
735768
mod="55",
736769
envio_sincrono=False,
770+
contingencia=False,
737771
):
738772
super().__init__(transmissao, envio_sincrono)
739773
self.versao = str(versao)
740774
self.ambiente = str(ambiente)
741775
self.uf = int(uf)
742776
self.mod = str(mod)
777+
self.contingencia = contingencia
743778

744779
def _edoc_situacao_ja_enviado(self, proc_consulta):
745780
if proc_consulta.resposta.cStat in ("100", "110", "150", "301", "302"):
746781
return True
747782
return False
748783

784+
def _get_ws_endpoint(self, service):
785+
"""
786+
Obtém o endpoint de um webservice específico.
787+
788+
Esta função localiza a URL do endpoint para um dado serviço,
789+
utilizando atributos da instância como a unidade federativa (UF),
790+
o modelo (mod), o ambiente e a contingência.
791+
"""
792+
endpoint = (
793+
localizar_url(
794+
service,
795+
str(self.uf),
796+
self.mod,
797+
int(self.ambiente),
798+
self.contingencia,
799+
),
800+
)
801+
return endpoint
802+
749803
def get_documento_id(self, edoc):
750804
return edoc.infNFe.Id[:3], edoc.infNFe.Id[3:]
751805

@@ -760,7 +814,7 @@ def status_servico(self):
760814
return self._post(
761815
raiz,
762816
# 'https://hom.sefazvirtual.fazenda.gov.br/NFeStatusServico4/NFeStatusServico4.asmx?wsdl',
763-
localizar_url(WS_NFE_SITUACAO, str(self.uf), self.mod, int(self.ambiente)),
817+
self._get_ws_endpoint(WS_NFE_SITUACAO),
764818
"nfeStatusServicoNF",
765819
retConsStatServ,
766820
)
@@ -777,7 +831,7 @@ def consulta_documento(self, chave):
777831
return self._post(
778832
raiz,
779833
# 'https://hom.sefazvirtual.fazenda.gov.br/NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx?wsdl',
780-
localizar_url(WS_NFE_CONSULTA, str(self.uf), self.mod, int(self.ambiente)),
834+
self._get_ws_endpoint(WS_NFE_CONSULTA),
781835
"nfeConsultaNF",
782836
retConsSitNFe,
783837
)
@@ -805,9 +859,7 @@ def envia_documento(self, edoc):
805859
return self._post(
806860
xml_envio_etree,
807861
# 'https://hom.sefazvirtual.fazenda.gov.br/NFeAutorizacao4/NFeAutorizacao4.asmx?wsdl',
808-
localizar_url(
809-
WS_NFE_AUTORIZACAO, str(self.uf), self.mod, int(self.ambiente)
810-
),
862+
self._get_ws_endpoint(WS_NFE_AUTORIZACAO),
811863
"nfeAutorizacaoLote",
812864
retEnviNFe,
813865
)
@@ -822,9 +874,7 @@ def envia_inutilizacao(self, evento):
822874

823875
return self._post(
824876
xml_envio_etree,
825-
localizar_url(
826-
WS_NFE_INUTILIZACAO, str(self.uf), self.mod, int(self.ambiente)
827-
),
877+
self._get_ws_endpoint(WS_NFE_INUTILIZACAO),
828878
"nfeInutilizacaoNF",
829879
retInutNFe,
830880
)
@@ -844,9 +894,7 @@ def consulta_recibo(self, numero=False, proc_envio=False):
844894
raiz.original_tagname_ = "consReciNFe"
845895
return self._post(
846896
raiz,
847-
localizar_url(
848-
WS_NFE_RET_AUTORIZACAO, str(self.uf), self.mod, int(self.ambiente)
849-
),
897+
self._get_ws_endpoint(WS_NFE_RET_AUTORIZACAO),
850898
# 'ws/nferetautorizacao4.asmx'
851899
"nfeRetAutorizacaoLote",
852900
retConsReciNFe,
@@ -871,9 +919,7 @@ def enviar_lote_evento(self, lista_eventos, numero_lote=False):
871919

872920
return self._post(
873921
xml_envio_etree,
874-
localizar_url(
875-
WS_NFE_RECEPCAO_EVENTO, str(self.uf), self.mod, int(self.ambiente)
876-
),
922+
self._get_ws_endpoint(WS_NFE_RECEPCAO_EVENTO),
877923
"nfeRecepcaoEvento",
878924
retEnvEvento,
879925
)
@@ -1023,9 +1069,7 @@ def consultar_distribuicao(
10231069

10241070
return self._post(
10251071
raiz,
1026-
localizar_url(
1027-
WS_DFE_DISTRIBUICAO, str(self.uf), self.mod, int(self.ambiente)
1028-
),
1072+
self._get_ws_endpoint(WS_DFE_DISTRIBUICAO),
10291073
"nfeDistDFeInteresse",
10301074
retDistDFeInt,
10311075
)
@@ -1091,7 +1135,7 @@ def consultar_cadastro(self, uf, cnpj=None, cpf=None, ie=None):
10911135

10921136
return self._post(
10931137
raiz,
1094-
localizar_url(WS_NFE_CADASTRO, str(self.uf), self.mod, int(self.ambiente)),
1138+
self._get_ws_endpoint(WS_NFE_CADASTRO),
10951139
"consultaCadastro",
10961140
retConsCad,
10971141
)

0 commit comments

Comments
 (0)