|
9 | 9 | from erpbrasil.base import misc |
10 | 10 | from erpbrasil.edoc.nfse import NFSe, ServicoNFSe |
11 | 11 | from erpbrasil.edoc.resposta import RetornoSoap |
12 | | -from zeep.helpers import serialize_object |
13 | 12 |
|
14 | 13 | try: |
15 | 14 | from urllib.parse import urljoin |
|
18 | 17 |
|
19 | 18 | try: |
20 | 19 | from nfselib.barueri import ( |
21 | | - ConsultarNFeRecebidaNumero, |
22 | 20 | NFeLoteEnviarArquivo, |
23 | 21 | NFeLoteStatusArquivo, |
24 | 22 | NFeLoteBaixarArquivo, |
|
29 | 27 | barueri = False |
30 | 28 |
|
31 | 29 | endpoint = "nfeservice/wsrps.asmx?WSDL" |
32 | | -nsmap = { |
33 | | - "consulta": "http://www.barueri.sp.gov.br/nfe/ConsultaNFeRecebidaNumero" |
34 | | - "ConsultaNFeRecebidaNumero.v1.xsd", |
35 | | - "tipo": "https://servicos.barueri.sp.gov.br/nfewsxml/wsgeraxml.asmx?op=ConsultaNFeRecebidaNumero", |
36 | | -} |
37 | 30 |
|
38 | 31 | if barueri: |
39 | 32 | servicos = { |
|
50 | 43 | "NFeLoteBaixarArquivo", endpoint, NFeLoteBaixarArquivo, True |
51 | 44 | ), |
52 | 45 | "consulta_nfse_rps": ServicoNFSe( |
53 | | - "ConsultaNFeRecebidaNumero", 'nfewsxml/wsgeraxml.asmx?WSDL', ConsultarNFeRecebidaNumero, True |
| 46 | + "NFeLoteStatusArquivo", endpoint, NFeLoteStatusArquivo, True |
54 | 47 | ), |
55 | 48 | } |
56 | 49 | else: |
@@ -119,100 +112,44 @@ def _prepara_cancelar_nfse_envio(self, doc_numero): |
119 | 112 | pass |
120 | 113 |
|
121 | 114 | def _prepara_consultar_nfse_rps(self, **kwargs): |
122 | | - rps_numero = kwargs.get("rps_number") |
123 | | - raiz = ConsultarNFeRecebidaNumero.NFeRecebidaNumero( |
124 | | - CPFCNPJTomador=self.cnpj_prestador, |
125 | | - CPFCNPJPrestador=self.cnpj_prestador, |
126 | | - NumeroNota=rps_numero, |
| 115 | + protocolo = kwargs.get("lot_receipt_number") |
| 116 | + raiz = NFeLoteStatusArquivo.NFeLoteStatusArquivo( |
| 117 | + CPFCNPJContrib=self.cnpj_prestador, InscricaoMunicipal=self.im_prestador |
| 118 | + , |
| 119 | + ProtocoloRemessa=protocolo, |
127 | 120 | ) |
128 | 121 | return raiz |
129 | 122 |
|
130 | | - def analisa_retorno_consulta( |
131 | | - self, processo, number, company_cnpj_cpf, company_legal_name |
132 | | - ): |
133 | | - data = serialize_object(processo.resposta, target_cls=dict) |
134 | | - root = etree.Element("ConsultarNfeResposta") |
135 | | - |
136 | | - if processo.webservice == "ConsultaNFeRecebidaNumero": |
137 | | - # if "ListaNfe" in data: |
138 | | - # lista = etree.SubElement(root, "ListaNfe") |
139 | | - # for nfe in data["ListaNfe"]: |
140 | | - # item = etree.SubElement(lista, "CompNfe") |
141 | | - # for k, v in nfe.items(): |
142 | | - # etree.SubElement(item, k).text = str(v) |
143 | | - |
144 | | - if "ListaMensagemRetorno" in data: |
145 | | - msgs = etree.SubElement(root, "ListaMensagemRetorno") |
146 | | - for msg in data["ListaMensagemRetorno"]: |
147 | | - item = etree.SubElement(msgs, "MensagemRetorno") |
148 | | - for k, v in msg.items(): |
149 | | - etree.SubElement(item, k).text = str(v) |
150 | | - mensagem = "" |
151 | | - |
152 | | - retorno = root |
153 | | - enviado = retorno.findall(".//CompNfe") |
154 | | - nao_encontrado = retorno.findall(".//MensagemRetorno") |
155 | | - # TODO: PAREI AQUI |
156 | | - |
157 | | - if enviado: |
158 | | - # NFS-e já foi enviada |
159 | | - |
160 | | - cancelada = retorno.findall( |
161 | | - ".//tipo:NfseCancelamento", namespaces=nsmap |
162 | | - ) |
163 | | - |
164 | | - if cancelada: |
165 | | - # NFS-e enviada foi cancelada |
166 | | - |
167 | | - data = retorno.findall(".//tipo:DataHora", namespaces=nsmap)[0].text |
168 | | - data = datetime.strptime(data, "%Y-%m-%dT%H:%M:%S").strftime( |
169 | | - "%m/%d/%Y" |
| 123 | + def analisa_retorno_consulta(self, processo): |
| 124 | + mensagem = "" |
| 125 | + if processo.webservice == "NFeLoteStatusArquivo": |
| 126 | + |
| 127 | + if processo.resposta: |
| 128 | + lista_msgs = processo.resposta.ListaMensagemRetorno |
| 129 | + |
| 130 | + if lista_msgs.Codigo != "OK200": |
| 131 | + mensagem += ( |
| 132 | + lista_msgs.Codigo |
| 133 | + + " - " |
| 134 | + + lista_msgs.Mensagem |
| 135 | + + " - Correção: " |
| 136 | + + lista_msgs.Correcao |
| 137 | + + "\n" |
170 | 138 | ) |
171 | | - mensagem = "NFS-e cancelada em " + data |
172 | | - |
173 | 139 | else: |
174 | | - numero_retorno = retorno.findall( |
175 | | - ".//tipo:InfNfse/tipo:Numero", namespaces=nsmap |
176 | | - )[0].text |
177 | | - cnpj_prestador_retorno = retorno.findall( |
178 | | - ".//tipo:IdentificacaoPrestador/tipo:Cnpj", namespaces=nsmap |
179 | | - )[0].text |
180 | | - razao_social_prestador_retorno = retorno.findall( |
181 | | - ".//tipo:PrestadorServico/tipo:RazaoSocial", namespaces=nsmap |
182 | | - )[0].text |
183 | | - |
184 | | - variables_error = [] |
185 | | - |
186 | | - if numero_retorno != number: |
187 | | - variables_error.append("Número") |
188 | | - if cnpj_prestador_retorno != misc.punctuation_rm(company_cnpj_cpf): |
189 | | - variables_error.append("CNPJ do prestador") |
190 | | - if razao_social_prestador_retorno != company_legal_name: |
191 | | - variables_error.append("Razão Social de prestador") |
192 | | - |
193 | | - if variables_error: |
194 | | - mensagem = ( |
195 | | - "Os seguintes campos não condizem com" |
196 | | - " o provedor NFS-e: \n" |
197 | | - ) |
198 | | - mensagem += "\n".join(variables_error) |
199 | | - else: |
200 | | - mensagem = "NFS-e enviada e corresponde com o provedor" |
201 | | - |
202 | | - elif nao_encontrado: |
203 | | - # NFS-e não foi enviada |
204 | | - |
205 | | - mensagem_erro = msg.get('Mensagem') |
206 | | - correcao = msg.get('Correcao') |
207 | | - codigo = msg.get('Codigo') |
208 | | - mensagem = ( |
209 | | - codigo + " - " + mensagem_erro + " - Correção: " + correcao + "\n" |
210 | | - ) |
211 | | - |
212 | | - else: |
213 | | - mensagem = "Erro desconhecido." |
214 | | - |
215 | | - return mensagem |
| 140 | + status = int(processo.resposta.ListaNfeArquivosRPS.SituacaoArq) |
| 141 | + if status == 0: |
| 142 | + mensagem = "Validated" |
| 143 | + elif status == 1: |
| 144 | + mensagem = "Successfully Processed" |
| 145 | + elif status == 2: |
| 146 | + mensagem = "Processed with Error" |
| 147 | + elif status == -1: |
| 148 | + mensagem = "Batch not yet processed" |
| 149 | + elif status == -2: |
| 150 | + mensagem = "Batch not yet processed" |
| 151 | + |
| 152 | + return status, mensagem |
216 | 153 |
|
217 | 154 | def analisa_retorno_cancelamento(self, processo): |
218 | 155 | pass |
|
0 commit comments