166
166
SVC_AN = {
167
167
AMBIENTE_PRODUCAO : {
168
168
"servidor" : "www.svc.fazenda.gov.br" ,
169
+ WS_NFE_INUTILIZACAO : "NFeInutilizacao4/NFeInutilizacao4.asmx?wsdl" ,
169
170
WS_NFE_CONSULTA : "NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx?wsdl" , # noqa
170
171
WS_NFE_SITUACAO : "NFeStatusServico4/NFeStatusServico4.asmx?wsdl" ,
171
172
WS_NFE_RECEPCAO_EVENTO : "NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx?wsdl" , # noqa
172
173
WS_NFE_AUTORIZACAO : "NFeAutorizacao4/NFeAutorizacao4.asmx?wsdl" ,
173
174
WS_NFE_RET_AUTORIZACAO : "NFeRetAutorizacao4/NFeRetAutorizacao4.asmx?wsdl" , # noqa
174
175
},
175
176
AMBIENTE_HOMOLOGACAO : {
176
- "servidor" : "hom.svc.fazenda.gov.br" ,
177
+ "servidor" : "hom.sefazvirtual.fazenda.gov.br" ,
178
+ WS_NFE_INUTILIZACAO : "NFeInutilizacao4/NFeInutilizacao4.asmx?wsdl" ,
177
179
WS_NFE_CONSULTA : "NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx?wsdl" , # noqa
178
180
WS_NFE_SITUACAO : "NFeStatusServico4/NFeStatusServico4.asmx?wsdl" ,
179
181
WS_NFE_RECEPCAO_EVENTO : "NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx?wsdl" , # noqa
675
677
"AN" : AN ,
676
678
}
677
679
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
+
678
710
679
- def localizar_url (servico , estado , mod = "55" , ambiente = 2 ):
711
+ def localizar_url (servico , estado , mod = "55" , ambiente = 2 , contingencia = False ):
680
712
sigla = SIGLA_ESTADO [estado ]
681
- ws = ESTADO_WS [sigla ]
713
+
714
+ ws = ESTADO_WS_CONTINGENCIA [sigla ] if contingencia else ESTADO_WS [sigla ]
682
715
683
716
if servico in (WS_DFE_DISTRIBUICAO , WS_DOWNLOAD_NFE ):
684
717
ws = AN
@@ -734,18 +767,37 @@ def __init__(
734
767
ambiente = "2" ,
735
768
mod = "55" ,
736
769
envio_sincrono = False ,
770
+ contingencia = False ,
737
771
):
738
772
super ().__init__ (transmissao , envio_sincrono )
739
773
self .versao = str (versao )
740
774
self .ambiente = str (ambiente )
741
775
self .uf = int (uf )
742
776
self .mod = str (mod )
777
+ self .contingencia = contingencia
743
778
744
779
def _edoc_situacao_ja_enviado (self , proc_consulta ):
745
780
if proc_consulta .resposta .cStat in ("100" , "110" , "150" , "301" , "302" ):
746
781
return True
747
782
return False
748
783
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 = localizar_url (
793
+ service ,
794
+ str (self .uf ),
795
+ self .mod ,
796
+ int (self .ambiente ),
797
+ self .contingencia ,
798
+ )
799
+ return endpoint
800
+
749
801
def get_documento_id (self , edoc ):
750
802
return edoc .infNFe .Id [:3 ], edoc .infNFe .Id [3 :]
751
803
@@ -760,7 +812,7 @@ def status_servico(self):
760
812
return self ._post (
761
813
raiz ,
762
814
# 'https://hom.sefazvirtual.fazenda.gov.br/NFeStatusServico4/NFeStatusServico4.asmx?wsdl',
763
- localizar_url ( WS_NFE_SITUACAO , str ( self .uf ), self . mod , int ( self . ambiente ) ),
815
+ self ._get_ws_endpoint ( WS_NFE_SITUACAO ),
764
816
"nfeStatusServicoNF" ,
765
817
retConsStatServ ,
766
818
)
@@ -777,7 +829,7 @@ def consulta_documento(self, chave):
777
829
return self ._post (
778
830
raiz ,
779
831
# 'https://hom.sefazvirtual.fazenda.gov.br/NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx?wsdl',
780
- localizar_url ( WS_NFE_CONSULTA , str ( self .uf ), self . mod , int ( self . ambiente ) ),
832
+ self ._get_ws_endpoint ( WS_NFE_CONSULTA ),
781
833
"nfeConsultaNF" ,
782
834
retConsSitNFe ,
783
835
)
@@ -805,9 +857,7 @@ def envia_documento(self, edoc):
805
857
return self ._post (
806
858
xml_envio_etree ,
807
859
# '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
- ),
860
+ self ._get_ws_endpoint (WS_NFE_AUTORIZACAO ),
811
861
"nfeAutorizacaoLote" ,
812
862
retEnviNFe ,
813
863
)
@@ -822,9 +872,7 @@ def envia_inutilizacao(self, evento):
822
872
823
873
return self ._post (
824
874
xml_envio_etree ,
825
- localizar_url (
826
- WS_NFE_INUTILIZACAO , str (self .uf ), self .mod , int (self .ambiente )
827
- ),
875
+ self ._get_ws_endpoint (WS_NFE_INUTILIZACAO ),
828
876
"nfeInutilizacaoNF" ,
829
877
retInutNFe ,
830
878
)
@@ -844,9 +892,7 @@ def consulta_recibo(self, numero=False, proc_envio=False):
844
892
raiz .original_tagname_ = "consReciNFe"
845
893
return self ._post (
846
894
raiz ,
847
- localizar_url (
848
- WS_NFE_RET_AUTORIZACAO , str (self .uf ), self .mod , int (self .ambiente )
849
- ),
895
+ self ._get_ws_endpoint (WS_NFE_RET_AUTORIZACAO ),
850
896
# 'ws/nferetautorizacao4.asmx'
851
897
"nfeRetAutorizacaoLote" ,
852
898
retConsReciNFe ,
@@ -871,9 +917,7 @@ def enviar_lote_evento(self, lista_eventos, numero_lote=False):
871
917
872
918
return self ._post (
873
919
xml_envio_etree ,
874
- localizar_url (
875
- WS_NFE_RECEPCAO_EVENTO , str (self .uf ), self .mod , int (self .ambiente )
876
- ),
920
+ self ._get_ws_endpoint (WS_NFE_RECEPCAO_EVENTO ),
877
921
"nfeRecepcaoEvento" ,
878
922
retEnvEvento ,
879
923
)
@@ -1023,9 +1067,7 @@ def consultar_distribuicao(
1023
1067
1024
1068
return self ._post (
1025
1069
raiz ,
1026
- localizar_url (
1027
- WS_DFE_DISTRIBUICAO , str (self .uf ), self .mod , int (self .ambiente )
1028
- ),
1070
+ self ._get_ws_endpoint (WS_DFE_DISTRIBUICAO ),
1029
1071
"nfeDistDFeInteresse" ,
1030
1072
retDistDFeInt ,
1031
1073
)
@@ -1091,7 +1133,7 @@ def consultar_cadastro(self, uf, cnpj=None, cpf=None, ie=None):
1091
1133
1092
1134
return self ._post (
1093
1135
raiz ,
1094
- localizar_url ( WS_NFE_CADASTRO , str ( self .uf ), self . mod , int ( self . ambiente ) ),
1136
+ self ._get_ws_endpoint ( WS_NFE_CADASTRO ),
1095
1137
"consultaCadastro" ,
1096
1138
retConsCad ,
1097
1139
)
0 commit comments