diff --git a/source/app/controllers/utils.py b/source/app/controllers/utils.py index 73f2651..38c196a 100644 --- a/source/app/controllers/utils.py +++ b/source/app/controllers/utils.py @@ -841,9 +841,9 @@ def make_xml(data, certificado): def get_pac_by_rfc(cfdi): tree = ET.fromstring(cfdi.encode()) version = tree.attrib['Version'] - NAME_SPACES = {'cfdi': PRE[version][1:-1], 'tdf': PRE['TIMBRE'][1:-1]} + namespaces = {'cfdi': PRE[version][1:-1], 'tdf': PRE['TIMBRE'][1:-1]} path = 'string(//cfdi:Complemento/tdf:TimbreFiscalDigital/@RfcProvCertif)' - rfc_pac = tree.xpath(path, namespaces=NAME_SPACES) + rfc_pac = tree.xpath(path, namespaces=namespaces) return RFCS[rfc_pac] @@ -909,17 +909,20 @@ def cancel_xml_sign(invoice, args, auth, certificado): def _get_data_sat(xml): BF = 'string(//*[local-name()="{}"]/@{})' - NS_CFDI = {'cfdi': 'http://www.sat.gob.mx/cfd/3'} + # ~ NS_CFDI = {'cfdi': 'http://www.sat.gob.mx/cfd/3'} try: tree = ET.fromstring(xml.encode()) + version = tree.attrib['Version'] + namespaces = {'cfdi': PRE[version][1:-1]} + emisor = escape( - tree.xpath('string(//cfdi:Emisor/@rfc)', namespaces=NS_CFDI) or - tree.xpath('string(//cfdi:Emisor/@Rfc)', namespaces=NS_CFDI) + tree.xpath('string(//cfdi:Emisor/@rfc)', namespaces=namespaces) or + tree.xpath('string(//cfdi:Emisor/@Rfc)', namespaces=namespaces) ) receptor = escape( - tree.xpath('string(//cfdi:Receptor/@rfc)', namespaces=NS_CFDI) or - tree.xpath('string(//cfdi:Receptor/@Rfc)', namespaces=NS_CFDI) + tree.xpath('string(//cfdi:Receptor/@rfc)', namespaces=namespaces) or + tree.xpath('string(//cfdi:Receptor/@Rfc)', namespaces=namespaces) ) total = tree.get('total') or tree.get('Total') uuid = tree.xpath(BF.format('TimbreFiscalDigital', 'UUID'))