diff --git a/source/util.py b/source/util.py
index 33a608c..864f9c4 100644
--- a/source/util.py
+++ b/source/util.py
@@ -40,7 +40,7 @@ def _exists(path):
return Path(path).exists()
-def _join(*paths):
+def join(*paths):
return str(Path(paths[0]).joinpath(*paths[1:]))
@@ -63,6 +63,13 @@ class CFDI(object):
'ns': {'nomina12': _nomina},
'schema': f' {_nomina} http://www.sat.gob.mx/sitio_internet/cfd/nomina/nomina12.xsd',
}
+ _cartaporte = 'http://www.sat.gob.mx/CartaPorte20'
+ CARTAPORTE = {
+ 'version': '2.0',
+ 'prefix': _cartaporte,
+ 'ns': {'cartaporte20': _cartaporte},
+ 'schema': f' {_cartaporte} http://www.sat.gob.mx/sitio_internet/cfd/CartaPorte/CartaPorte20.xsd',
+ }
def __init__(self, data):
self.error = ''
@@ -97,6 +104,7 @@ class CFDI(object):
self._schema = self.schema
self._exists_pagos = 'pagos' in data
self._exists_nomina = 'nomina' in data
+ self._exists_cartaporte = 'cartaporte' in data
self._node_complement = False
if self._exists_pagos:
@@ -105,6 +113,9 @@ class CFDI(object):
if self._exists_nomina:
self._node_complement = True
self._schema += self.NOMINA['schema']
+ if self._exists_cartaporte:
+ self._node_complement = True
+ self._schema += self.CARTAPORTE['schema']
return
def _comprobante(self, attr):
@@ -116,6 +127,8 @@ class CFDI(object):
NSMAP.update(self.PAGOS['ns'])
if self._exists_nomina:
NSMAP.update(self.NOMINA['ns'])
+ if self._exists_cartaporte:
+ NSMAP.update(self.CARTAPORTE['ns'])
attr_qname = ET.QName(
'http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation')
@@ -211,6 +224,9 @@ class CFDI(object):
if self._exists_nomina:
self._nomina(complemento, data['nomina'])
+
+ if self._exists_cartaporte:
+ self._cartaporte(complemento, data['cartaporte'])
return
def _pagos(self, complemento, data):
@@ -273,6 +289,47 @@ class CFDI(object):
ET.SubElement(sub_node, sub_name, subsidio)
return
+ def _cartaporte(self, complemento, data):
+ ubicaciones = data.pop('ubicaciones')
+ mercancias = data.pop('mercancias')
+
+ if not 'Version' in data:
+ data['Version'] = self.CARTAPORTE['version']
+
+ node_name = f"{{{self.CARTAPORTE['prefix']}}}CartaPorte"
+ node_carta = ET.SubElement(complemento, node_name, data)
+
+ node_name = f"{{{self.CARTAPORTE['prefix']}}}Ubicaciones"
+ node = ET.SubElement(node_carta, node_name)
+
+ for ubicacion in ubicaciones:
+ node_name = f"{{{self.CARTAPORTE['prefix']}}}Ubicacion"
+ sub_node = ET.SubElement(node, node_name, ubicacion)
+
+ attr = mercancias
+ mercancias = attr.pop('mercancias')
+ autotransporte = attr.pop('autotransporte')
+ node_name = f"{{{self.CARTAPORTE['prefix']}}}Mercancias"
+ node = ET.SubElement(node_carta, node_name, attr)
+
+ for mercancia in mercancias:
+ node_name = f"{{{self.CARTAPORTE['prefix']}}}Mercancia"
+ sub_node = ET.SubElement(node, node_name, mercancia)
+
+ identificacion = autotransporte.pop('identificacion')
+ seguros = autotransporte.pop('seguros')
+
+ node_name = f"{{{self.CARTAPORTE['prefix']}}}Autotransporte"
+ sub_node = ET.SubElement(node, node_name, autotransporte)
+
+ node_name = f"{{{self.CARTAPORTE['prefix']}}}IdentificacionVehicular"
+ ET.SubElement(sub_node, node_name, identificacion)
+
+ node_name = f"{{{self.CARTAPORTE['prefix']}}}Seguros"
+ ET.SubElement(sub_node, node_name, seguros)
+
+ return
+
def _validate_args_validar_cert(args):
data = {}
@@ -284,9 +341,9 @@ def _validate_args_validar_cert(args):
log.error(msg)
return False, data
- path_cer = _join(path_cert, f'{name}.cer')
- path_key = _join(path_cert, f'{name}.key')
- path_enc = _join(path_cert, f'{name}.enc')
+ path_cer = join(path_cert, f'{name}.cer')
+ path_key = join(path_cert, f'{name}.key')
+ path_enc = join(path_cert, f'{name}.enc')
if not _exists(path_cer):
msg = f'No se encontró el archivo CER en: {path_cer}'
diff --git a/source/xslt/cadena.xslt b/source/xslt/cadena.xslt
index 4c6e2d5..285b0cf 100644
--- a/source/xslt/cadena.xslt
+++ b/source/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