Agregar addenda 2 de cliente
This commit is contained in:
parent
a55a5eb1c4
commit
9985fd198c
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
from helper import util
|
from helper import util
|
||||||
|
|
|
@ -10,9 +10,6 @@ from settings import DEBUG, log, PATH_XSLT, DELETE_FILES, PAC_AUTH
|
||||||
from helper.comercio import PACComercioDigital as PAC
|
from helper.comercio import PACComercioDigital as PAC
|
||||||
|
|
||||||
|
|
||||||
from . import util2
|
|
||||||
|
|
||||||
|
|
||||||
def _call(args):
|
def _call(args):
|
||||||
return subprocess.check_output(args, shell=True).decode()
|
return subprocess.check_output(args, shell=True).decode()
|
||||||
|
|
||||||
|
@ -239,16 +236,17 @@ class DictToCfdi():
|
||||||
return
|
return
|
||||||
|
|
||||||
def _addenda(self):
|
def _addenda(self):
|
||||||
type_addenda = self._data['addenda'].get('type', '')
|
type_boveda = self._data['addenda'].get('type', '')
|
||||||
|
type_client = self._data['addenda'].get('type_client', '')
|
||||||
data = self._data['addenda'].get('boveda', False)
|
data = self._data['addenda'].get('boveda', False)
|
||||||
self._boveda(data)
|
self._boveda(type_boveda, data)
|
||||||
if type_addenda:
|
if type_client:
|
||||||
data = self._data['addenda'].get('cliente', False)
|
data = self._data['addenda'].get('cliente', False)
|
||||||
partes = self._data['addenda']['partes']
|
partes = self._data['addenda'].get('partes', ())
|
||||||
getattr(self, f'_addenda_{type_addenda}')(data, partes)
|
self._addenda_client(type_client, data, partes)
|
||||||
return
|
return
|
||||||
|
|
||||||
def _boveda(self, data):
|
def _boveda(self, type_boveda, data):
|
||||||
if not data:
|
if not data:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -269,6 +267,7 @@ class DictToCfdi():
|
||||||
node_name = f'{{{XMLNS}}}BOVEDAFISCAL'
|
node_name = f'{{{XMLNS}}}BOVEDAFISCAL'
|
||||||
node = ET.SubElement(self._node_addenda, node_name, schema, nsmap=NSMAP)
|
node = ET.SubElement(self._node_addenda, node_name, schema, nsmap=NSMAP)
|
||||||
|
|
||||||
|
# ~ Type 02
|
||||||
for k, v in data.items():
|
for k, v in data.items():
|
||||||
node_name = f'{{{XMLNS}}}{k}'
|
node_name = f'{{{XMLNS}}}{k}'
|
||||||
n = ET.SubElement(node, node_name)
|
n = ET.SubElement(node, node_name)
|
||||||
|
@ -276,14 +275,21 @@ class DictToCfdi():
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def _addenda_02(self, data, partes):
|
def _addenda_client(self, type_client, data, partes):
|
||||||
if not data:
|
if not data:
|
||||||
return
|
return
|
||||||
|
|
||||||
XMLNS = 'http://www.sas-automative/en/locations/local-offices-and-plants/mexico/plant-puebla.html'
|
if type_client == '1':
|
||||||
NSMAP = {'PMT': XMLNS}
|
XMLNS = 'http://www.vwnovedades.com/volkswagen/kanseilab/shcp/2009/Addenda/PMT'
|
||||||
version = data.pop('version')
|
NSMAP = {'PMT': XMLNS}
|
||||||
attr = {'version': version}
|
elif type_client == '2':
|
||||||
|
XMLNS = 'http://www.vwnovedades.com/volkswagen/kanseilab/shcp/2009/Addenda/PSV'
|
||||||
|
NSMAP = {'PSV': XMLNS}
|
||||||
|
elif type_client == '4':
|
||||||
|
XMLNS = 'http://www.sas-automative/en/locations/local-offices-and-plants/mexico/plant-puebla.html'
|
||||||
|
NSMAP = {'PMT': XMLNS}
|
||||||
|
|
||||||
|
attr = data.pop('Factura')
|
||||||
node_name = f'{{{XMLNS}}}Factura'
|
node_name = f'{{{XMLNS}}}Factura'
|
||||||
node = ET.SubElement(self._node_addenda, node_name, **attr, nsmap=NSMAP)
|
node = ET.SubElement(self._node_addenda, node_name, **attr, nsmap=NSMAP)
|
||||||
|
|
||||||
|
@ -516,35 +522,36 @@ class DataToDict():
|
||||||
|
|
||||||
def _boveda(self, data):
|
def _boveda(self, data):
|
||||||
type_addenda = data[0]
|
type_addenda = data[0]
|
||||||
fields = (
|
if type_addenda == '02':
|
||||||
'Razon_Social_destino',
|
fields = (
|
||||||
'Calle_Destino',
|
'Razon_Social_destino',
|
||||||
'Colonia_Destino',
|
'Calle_Destino',
|
||||||
'Ciudad_Destino',
|
'Colonia_Destino',
|
||||||
'Estado_Destino',
|
'Ciudad_Destino',
|
||||||
'Pais_Destino',
|
'Estado_Destino',
|
||||||
'CP_Destino_consigan',
|
'Pais_Destino',
|
||||||
'RFC_Destino_consigna',
|
'CP_Destino_consigan',
|
||||||
'Telefono_Receptor',
|
'RFC_Destino_consigna',
|
||||||
'Peso_Bruto',
|
'Telefono_Receptor',
|
||||||
'Peso_Neto',
|
'Peso_Bruto',
|
||||||
'Incoterm',
|
'Peso_Neto',
|
||||||
'leyenda_pie',
|
'Incoterm',
|
||||||
'R.vto',
|
'leyenda_pie',
|
||||||
'TIPO_CAMBIO_FACTURA',
|
'R.vto',
|
||||||
'R.cte',
|
'TIPO_CAMBIO_FACTURA',
|
||||||
'RI_Solicitante',
|
'R.cte',
|
||||||
'R.fefa',
|
'RI_Solicitante',
|
||||||
'Razon_Social_facturado',
|
'R.fefa',
|
||||||
'Calle_facturado',
|
'Razon_Social_facturado',
|
||||||
'Colonia_facturado',
|
'Calle_facturado',
|
||||||
'RFC_destino',
|
'Colonia_facturado',
|
||||||
'Telefono_facturado',
|
'RFC_destino',
|
||||||
'NUMCTAPAGO',
|
'Telefono_facturado',
|
||||||
)
|
'NUMCTAPAGO',
|
||||||
boveda = {}
|
)
|
||||||
for i, f in enumerate(fields):
|
boveda = {}
|
||||||
boveda[f] = data[i+1]
|
for i, f in enumerate(fields):
|
||||||
|
boveda[f] = data[i+1]
|
||||||
|
|
||||||
self._cfdi['addenda']['type'] = type_addenda
|
self._cfdi['addenda']['type'] = type_addenda
|
||||||
self._cfdi['addenda']['boveda'] = boveda
|
self._cfdi['addenda']['boveda'] = boveda
|
||||||
|
@ -553,8 +560,30 @@ class DataToDict():
|
||||||
|
|
||||||
def _addenda(self, header):
|
def _addenda(self, header):
|
||||||
self._type_header = header[1]
|
self._type_header = header[1]
|
||||||
if self._type_header == '4':
|
self._cfdi['addenda']['type_client'] = self._type_header
|
||||||
data = {'version': header[3]}
|
data = {}
|
||||||
|
if self._type_header == '2':
|
||||||
|
data['Factura'] = {
|
||||||
|
'version': header[3],
|
||||||
|
'tipoDocumentoFiscal': header[4],
|
||||||
|
'tipoDocumentoVWM': header[5],
|
||||||
|
'division': header[6]}
|
||||||
|
data['Moneda'] = {
|
||||||
|
'tipoMoneda': header[7],
|
||||||
|
'tipoCambio': header[8]}
|
||||||
|
data['Proveedor'] = {
|
||||||
|
'codigo': header[10],
|
||||||
|
'nombre': header[11],
|
||||||
|
'correoContacto': header[12]}
|
||||||
|
data['Origen'] = {'codigo': header[13]}
|
||||||
|
data['Destino'] = {
|
||||||
|
'codigo': header[14],
|
||||||
|
'naveReciboMaterial': header[15]}
|
||||||
|
data['Referencias'] = {'referenciaProveedor': header[16]}
|
||||||
|
data['Solicitante'] = {'correo': header[17]}
|
||||||
|
data['Archivo'] = {'datos': header[20], 'tipo': 'ZIP'}
|
||||||
|
elif self._type_header == '4':
|
||||||
|
data['Factura'] = {'version': header[3]}
|
||||||
data['Moneda'] = {'tipoMoneda': header[7]}
|
data['Moneda'] = {'tipoMoneda': header[7]}
|
||||||
data['Proveedor'] = {'codigo': header[10], 'nombre': header[11]}
|
data['Proveedor'] = {'codigo': header[10], 'nombre': header[11]}
|
||||||
data['Referencias'] = {'referenciaProveedor': header[16]}
|
data['Referencias'] = {'referenciaProveedor': header[16]}
|
||||||
|
@ -563,7 +592,20 @@ class DataToDict():
|
||||||
return
|
return
|
||||||
|
|
||||||
def _addenda_partes(self, parte):
|
def _addenda_partes(self, parte):
|
||||||
if self._type_header == '4':
|
if self._type_header == '2':
|
||||||
|
attr = {'posicion': parte[0],
|
||||||
|
'numeroMaterial': parte[1],
|
||||||
|
'descripcionMaterial': parte[2],
|
||||||
|
'cantidadMaterial': parte[3],
|
||||||
|
'unidadMedida': parte[4],
|
||||||
|
'precioUnitario': parte[5],
|
||||||
|
'montoLinea': parte[6],
|
||||||
|
'codigoImpuesto': parte[8],
|
||||||
|
'referencias': {
|
||||||
|
'ordenCompra': parte[7],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elif self._type_header == '4':
|
||||||
attr = {'posicion': parte[0],
|
attr = {'posicion': parte[0],
|
||||||
'numeroMaterial': parte[1],
|
'numeroMaterial': parte[1],
|
||||||
'descripcionMaterial': parte[2],
|
'descripcionMaterial': parte[2],
|
||||||
|
@ -659,16 +701,3 @@ def stamp_pac(source, target):
|
||||||
f.write(result['xml'])
|
f.write(result['xml'])
|
||||||
log.info(f'\tTimbrada: {new_path}')
|
log.info(f'\tTimbrada: {new_path}')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
# ~ To delete
|
|
||||||
|
|
||||||
def _version33(path, target):
|
|
||||||
from .cfdi_xml import CFDI
|
|
||||||
|
|
||||||
data = util2.load_data(path)
|
|
||||||
cfdi = CFDI()
|
|
||||||
xml = cfdi.get_xml(data)
|
|
||||||
_save_file(path, target, xml)
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
Loading…
Reference in New Issue