forked from elmau/empresa-libre
Fix - issue #422
This commit is contained in:
parent
3c574425eb
commit
c1e1c5ad7c
|
@ -32,6 +32,7 @@ import subprocess
|
||||||
import threading
|
import threading
|
||||||
import zipfile
|
import zipfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from urllib import request
|
||||||
|
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.base import MIMEBase
|
from email.mime.base import MIMEBase
|
||||||
|
@ -700,7 +701,61 @@ def cancel_xml_sign(invoice, auth, certificado):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def _get_data_sat(xml):
|
||||||
|
BF = 'string(//*[local-name()="{}"]/@{})'
|
||||||
|
NS_CFDI = {'cfdi': 'http://www.sat.gob.mx/cfd/3'}
|
||||||
|
|
||||||
|
try:
|
||||||
|
tree = etree.fromstring(xml.encode())
|
||||||
|
emisor = escape(
|
||||||
|
tree.xpath('string(//cfdi:Emisor/@rfc)', namespaces=NS_CFDI) or
|
||||||
|
tree.xpath('string(//cfdi:Emisor/@Rfc)', namespaces=NS_CFDI)
|
||||||
|
)
|
||||||
|
receptor = escape(
|
||||||
|
tree.xpath('string(//cfdi:Receptor/@rfc)', namespaces=NS_CFDI) or
|
||||||
|
tree.xpath('string(//cfdi:Receptor/@Rfc)', namespaces=NS_CFDI)
|
||||||
|
)
|
||||||
|
total = tree.get('total') or tree.get('Total')
|
||||||
|
uuid = tree.xpath(BF.format('TimbreFiscalDigital', 'UUID'))
|
||||||
|
except Exception as e:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
data = f'?re={emisor}&rr={receptor}&tt={total}&id={uuid}'
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
def get_status_sat(xml):
|
def get_status_sat(xml):
|
||||||
|
data = _get_data_sat(xml)
|
||||||
|
if not data:
|
||||||
|
return 'XML inválido'
|
||||||
|
|
||||||
|
data = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<soap:Envelope
|
||||||
|
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
|
||||||
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<soap:Header/>
|
||||||
|
<soap:Body>
|
||||||
|
<Consulta xmlns="http://tempuri.org/">
|
||||||
|
<expresionImpresa>
|
||||||
|
{}
|
||||||
|
</expresionImpresa>
|
||||||
|
</Consulta>
|
||||||
|
</soap:Body>
|
||||||
|
</soap:Envelope>""".format(data)
|
||||||
|
headers = {
|
||||||
|
'SOAPAction': '"http://tempuri.org/IConsultaCFDIService/Consulta"',
|
||||||
|
'Content-type': 'text/xml; charset="UTF-8"'
|
||||||
|
}
|
||||||
|
URL = 'https://consultaqr.facturaelectronica.sat.gob.mx/consultacfdiservice.svc'
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = requests.post(URL, data=data, headers=headers)
|
||||||
|
tree = etree.fromstring(result.text)
|
||||||
|
node = tree.xpath("//*[local-name() = 'Estado']")[0]
|
||||||
|
except Exception as e:
|
||||||
|
return 'Error: {}'.format(str(e))
|
||||||
|
|
||||||
|
return node.text
|
||||||
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
Loading…
Reference in New Issue