forked from elmau/empresa-libre
Fix get status sat, issue #422
This commit is contained in:
commit
537cecbb0b
|
@ -1,3 +1,8 @@
|
|||
v 1.40.1 [10-Feb-2021]
|
||||
----------------------
|
||||
- Fix #422
|
||||
|
||||
|
||||
v 1.40.0 [05-ene-2021]
|
||||
----------------------
|
||||
- Error: Al parsear XML en Python 3.9+
|
||||
|
|
|
@ -430,9 +430,9 @@ def _get_uuid_fecha(xml):
|
|||
return node.attrib['UUID'], node.attrib['FechaTimbrado']
|
||||
|
||||
|
||||
def get_sat(xml):
|
||||
from .pac import get_status_sat
|
||||
return get_status_sat(xml)
|
||||
# ~ def get_sat(xml):
|
||||
# ~ from .pac import get_status_sat
|
||||
# ~ return get_status_sat(xml)
|
||||
|
||||
|
||||
class LIBO(object):
|
||||
|
|
|
@ -32,6 +32,7 @@ import subprocess
|
|||
import threading
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
from urllib import request
|
||||
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.base import MIMEBase
|
||||
|
@ -698,3 +699,63 @@ def cancel_xml_sign(invoice, auth, certificado):
|
|||
data = {'ok': True, 'msg': msg, 'row': {'estatus': 'Cancelada'},
|
||||
'date': result['date'], 'acuse': result['acuse']}
|
||||
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):
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -5155,7 +5155,7 @@ class Facturas(BaseModel):
|
|||
@classmethod
|
||||
def get_status_sat(cls, id):
|
||||
obj = Facturas.get(Facturas.id == id)
|
||||
estatus_sat = util.get_sat(obj.xml)
|
||||
estatus_sat = utils.get_status_sat(obj.xml)
|
||||
if obj.estatus_sat != estatus_sat:
|
||||
obj.estatus_sat = estatus_sat
|
||||
obj.save()
|
||||
|
|
|
@ -42,7 +42,7 @@ except ImportError:
|
|||
|
||||
|
||||
DEBUG = DEBUG
|
||||
VERSION = '1.40.0'
|
||||
VERSION = '1.40.1'
|
||||
EMAIL_SUPPORT = ('soporte@empresalibre.mx',)
|
||||
TITLE_APP = '{} v{}'.format(TITLE_APP, VERSION)
|
||||
|
||||
|
|
Loading…
Reference in New Issue