Tax legends in PDF

This commit is contained in:
Mauricio Baeza 2020-03-02 17:27:02 -06:00
parent 2877a68b92
commit 6b4eb36795
3 changed files with 52 additions and 5 deletions

View File

@ -1,8 +1,21 @@
v 1.37.0 [01-mar-2020]
v 1.37.0 [02-mar-2020]
----------------------
- Mejora: Soporte para complemento Leyendas Fiscales
* IMPORTANTE:
Es necesario hacer una migración, y agregar los campos necesarios para mostrar
las leyendas, mira la carpeta pública con la plantilla de ejemplo.
```
git pull origin master
cd source/app/models
python main.py -bk
python main.py -m -r RFC
```
v 1.36.0 [25-feb-2020]
----------------------

View File

@ -1087,6 +1087,28 @@ class LIBO(object):
self._set_cell(f'{{divisas.{k}}}', v)
return
def _leyendas(self, data):
if not data:
return
first = True
for row in data:
leyenda = row['textoLeyenda']
norma = row.get('norma', '')
disposicion = row.get('disposicionFiscal', '')
if first:
first = False
cell1 = self._set_cell('{textoLeyenda}', leyenda)
cell2 = self._set_cell('{norma}', norma)
cell3 = self._set_cell('{disposicionFiscal}', disposicion)
else:
row = cell1.CellAddress.Row + 1
self._sheet.getRows().insertByIndex(row, 1)
cell1 = self._set_cell(v=leyenda, cell=cell1)
cell2 = self._set_cell(v=norma, cell=cell2)
cell3 = self._set_cell(v=disposicion, cell=cell3)
return
def _nomina(self, data):
if not data:
return
@ -1314,6 +1336,7 @@ class LIBO(object):
self._ine(data['ine'])
self._divisas(data.get('divisas', {}))
self._leyendas(data['leyendas'])
self._cancelado(data['cancelada'])
self._clean()

View File

@ -244,10 +244,13 @@ class CfdiToDict(object):
NS = {
'cfdi': 'http://www.sat.gob.mx/cfd/3',
'divisas': 'http://www.sat.gob.mx/divisas',
'leyendasFisc': 'http://www.sat.gob.mx/leyendasFiscales',
}
def __init__(self, xml):
self._values = {}
self._values = {
'leyendas': (),
}
self._root = ET.parse(BytesIO(xml.encode())).getroot()
self._get_values()
@ -260,13 +263,21 @@ class CfdiToDict(object):
return
def _complementos(self):
complemento = self._root.xpath('//cfdi:Complemento', namespaces=self.NS)[0]
path = '//cfdi:Complemento'
complemento = self._root.xpath(path, namespaces=self.NS)[0]
divisas = complemento.xpath('//divisas:Divisas', namespaces=self.NS)
path = '//divisas:Divisas'
divisas = complemento.xpath(path, namespaces=self.NS)
if divisas:
d = CaseInsensitiveDict(divisas[0].attrib)
d.pop('version', '')
self._values.update({'divisas': d})
path = '//leyendasFisc:Leyenda'
node = complemento.xpath(path, namespaces=self.NS)
if node:
leyendas = [CaseInsensitiveDict(n.attrib) for n in node]
self._values['leyendas'] = leyendas
return