Skip to content

Commit 4a8e8de

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

File tree

1 file changed

+84
-11
lines changed

1 file changed

+84
-11
lines changed

src/erpbrasil/edoc/nfe.py

+84-11
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,12 +767,14 @@ 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"):
@@ -760,7 +795,13 @@ def status_servico(self):
760795
return self._post(
761796
raiz,
762797
# 'https://hom.sefazvirtual.fazenda.gov.br/NFeStatusServico4/NFeStatusServico4.asmx?wsdl',
763-
localizar_url(WS_NFE_SITUACAO, str(self.uf), self.mod, int(self.ambiente)),
798+
localizar_url(
799+
WS_NFE_SITUACAO,
800+
str(self.uf),
801+
self.mod,
802+
int(self.ambiente),
803+
self.contingencia,
804+
),
764805
"nfeStatusServicoNF",
765806
retConsStatServ,
766807
)
@@ -777,7 +818,13 @@ def consulta_documento(self, chave):
777818
return self._post(
778819
raiz,
779820
# 'https://hom.sefazvirtual.fazenda.gov.br/NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx?wsdl',
780-
localizar_url(WS_NFE_CONSULTA, str(self.uf), self.mod, int(self.ambiente)),
821+
localizar_url(
822+
WS_NFE_CONSULTA,
823+
str(self.uf),
824+
self.mod,
825+
int(self.ambiente),
826+
self.contingencia,
827+
),
781828
"nfeConsultaNF",
782829
retConsSitNFe,
783830
)
@@ -806,7 +853,11 @@ def envia_documento(self, edoc):
806853
xml_envio_etree,
807854
# 'https://hom.sefazvirtual.fazenda.gov.br/NFeAutorizacao4/NFeAutorizacao4.asmx?wsdl',
808855
localizar_url(
809-
WS_NFE_AUTORIZACAO, str(self.uf), self.mod, int(self.ambiente)
856+
WS_NFE_AUTORIZACAO,
857+
str(self.uf),
858+
self.mod,
859+
int(self.ambiente),
860+
self.contingencia,
810861
),
811862
"nfeAutorizacaoLote",
812863
retEnviNFe,
@@ -823,7 +874,11 @@ def envia_inutilizacao(self, evento):
823874
return self._post(
824875
xml_envio_etree,
825876
localizar_url(
826-
WS_NFE_INUTILIZACAO, str(self.uf), self.mod, int(self.ambiente)
877+
WS_NFE_INUTILIZACAO,
878+
str(self.uf),
879+
self.mod,
880+
int(self.ambiente),
881+
self.contingencia,
827882
),
828883
"nfeInutilizacaoNF",
829884
retInutNFe,
@@ -845,7 +900,11 @@ def consulta_recibo(self, numero=False, proc_envio=False):
845900
return self._post(
846901
raiz,
847902
localizar_url(
848-
WS_NFE_RET_AUTORIZACAO, str(self.uf), self.mod, int(self.ambiente)
903+
WS_NFE_RET_AUTORIZACAO,
904+
str(self.uf),
905+
self.mod,
906+
int(self.ambiente),
907+
self.contingencia,
849908
),
850909
# 'ws/nferetautorizacao4.asmx'
851910
"nfeRetAutorizacaoLote",
@@ -872,7 +931,11 @@ def enviar_lote_evento(self, lista_eventos, numero_lote=False):
872931
return self._post(
873932
xml_envio_etree,
874933
localizar_url(
875-
WS_NFE_RECEPCAO_EVENTO, str(self.uf), self.mod, int(self.ambiente)
934+
WS_NFE_RECEPCAO_EVENTO,
935+
str(self.uf),
936+
self.mod,
937+
int(self.ambiente),
938+
self.contingencia,
876939
),
877940
"nfeRecepcaoEvento",
878941
retEnvEvento,
@@ -1024,7 +1087,11 @@ def consultar_distribuicao(
10241087
return self._post(
10251088
raiz,
10261089
localizar_url(
1027-
WS_DFE_DISTRIBUICAO, str(self.uf), self.mod, int(self.ambiente)
1090+
WS_DFE_DISTRIBUICAO,
1091+
str(self.uf),
1092+
self.mod,
1093+
int(self.ambiente),
1094+
self.contingencia,
10281095
),
10291096
"nfeDistDFeInteresse",
10301097
retDistDFeInt,
@@ -1091,7 +1158,13 @@ def consultar_cadastro(self, uf, cnpj=None, cpf=None, ie=None):
10911158

10921159
return self._post(
10931160
raiz,
1094-
localizar_url(WS_NFE_CADASTRO, str(self.uf), self.mod, int(self.ambiente)),
1161+
localizar_url(
1162+
WS_NFE_CADASTRO,
1163+
str(self.uf),
1164+
self.mod,
1165+
int(self.ambiente),
1166+
self.contingencia,
1167+
),
10951168
"consultaCadastro",
10961169
retConsCad,
10971170
)

0 commit comments

Comments
 (0)