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,39 @@ 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 = (
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
+
749
803
def get_documento_id (self , edoc ):
750
804
return edoc .infNFe .Id [:3 ], edoc .infNFe .Id [3 :]
751
805
@@ -760,7 +814,7 @@ def status_servico(self):
760
814
return self ._post (
761
815
raiz ,
762
816
# '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 ),
764
818
"nfeStatusServicoNF" ,
765
819
retConsStatServ ,
766
820
)
@@ -777,7 +831,7 @@ def consulta_documento(self, chave):
777
831
return self ._post (
778
832
raiz ,
779
833
# '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 ),
781
835
"nfeConsultaNF" ,
782
836
retConsSitNFe ,
783
837
)
@@ -805,9 +859,7 @@ def envia_documento(self, edoc):
805
859
return self ._post (
806
860
xml_envio_etree ,
807
861
# '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 ),
811
863
"nfeAutorizacaoLote" ,
812
864
retEnviNFe ,
813
865
)
@@ -822,9 +874,7 @@ def envia_inutilizacao(self, evento):
822
874
823
875
return self ._post (
824
876
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 ),
828
878
"nfeInutilizacaoNF" ,
829
879
retInutNFe ,
830
880
)
@@ -844,9 +894,7 @@ def consulta_recibo(self, numero=False, proc_envio=False):
844
894
raiz .original_tagname_ = "consReciNFe"
845
895
return self ._post (
846
896
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 ),
850
898
# 'ws/nferetautorizacao4.asmx'
851
899
"nfeRetAutorizacaoLote" ,
852
900
retConsReciNFe ,
@@ -871,9 +919,7 @@ def enviar_lote_evento(self, lista_eventos, numero_lote=False):
871
919
872
920
return self ._post (
873
921
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 ),
877
923
"nfeRecepcaoEvento" ,
878
924
retEnvEvento ,
879
925
)
@@ -1023,9 +1069,7 @@ def consultar_distribuicao(
1023
1069
1024
1070
return self ._post (
1025
1071
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 ),
1029
1073
"nfeDistDFeInteresse" ,
1030
1074
retDistDFeInt ,
1031
1075
)
@@ -1091,7 +1135,7 @@ def consultar_cadastro(self, uf, cnpj=None, cpf=None, ie=None):
1091
1135
1092
1136
return self ._post (
1093
1137
raiz ,
1094
- localizar_url ( WS_NFE_CADASTRO , str ( self .uf ), self . mod , int ( self . ambiente ) ),
1138
+ self ._get_ws_endpoint ( WS_NFE_CADASTRO ),
1095
1139
"consultaCadastro" ,
1096
1140
retConsCad ,
1097
1141
)
0 commit comments