Fix: Formateo PEP8 (79 cols) y limpieza flake8 en paquete facho
- Líneas >79 cols reajustadas en todo el paquete - Fix F821: etree.cleanup_namespaces(security) en signature.py (era 'header', NameError) - Fix bug cune_xpath -> xpath en nomina/informacion_general() (NameError) - Elimina clase TaxScheme duplicada en form/__init__.py - Imports explícitos (F403/F405) y __all__ en form_xml/invoice.py, nomina - Elimina imports y variables muertas (F401/F841), E712 (== None -> is None)
This commit is contained in:
@@ -11,18 +11,88 @@ import hashlib
|
||||
|
||||
|
||||
from .. import fe
|
||||
from .. import form
|
||||
from ..data.dian import codelist
|
||||
|
||||
from .devengado import *
|
||||
from .deduccion import *
|
||||
from .trabajador import *
|
||||
from .empleador import *
|
||||
from .pago import *
|
||||
from .lugar import Lugar
|
||||
|
||||
from .amount import Amount
|
||||
from .exception import *
|
||||
from .deduccion import (
|
||||
Deduccion,
|
||||
DeduccionFondoPension,
|
||||
DeduccionSalud,
|
||||
)
|
||||
from .devengado import (
|
||||
Devengado,
|
||||
DevengadoBasico,
|
||||
DevengadoHoraExtra,
|
||||
DevengadoHorasExtrasDiarias,
|
||||
DevengadoHorasExtrasDiariasDominicalesYFestivos,
|
||||
DevengadoHorasExtrasNocturnas,
|
||||
DevengadoHorasExtrasNocturnasDominicalesYFestivos,
|
||||
DevengadoHorasRecargoDiariasDominicalesYFestivos,
|
||||
DevengadoHorasRecargoNocturno,
|
||||
DevengadoHorasRecargoNocturnoDominicalesYFestivos,
|
||||
DevengadoTransporte,
|
||||
)
|
||||
from .empleador import Empleador
|
||||
from .exception import DIANNominaIndividualError
|
||||
from .lugar import Lugar
|
||||
from .pago import (
|
||||
FormaPago,
|
||||
MetodoPago,
|
||||
Pago,
|
||||
)
|
||||
from .trabajador import (
|
||||
LugarTrabajo,
|
||||
SubTipoTrabajador,
|
||||
TipoContrato,
|
||||
TipoDocumento,
|
||||
TipoTrabajador,
|
||||
Trabajador,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
'Amount',
|
||||
'Deduccion',
|
||||
'DeduccionFondoPension',
|
||||
'DeduccionSalud',
|
||||
'Devengado',
|
||||
'DevengadoBasico',
|
||||
'DevengadoHoraExtra',
|
||||
'DevengadoHorasExtrasDiarias',
|
||||
'DevengadoHorasExtrasDiariasDominicalesYFestivos',
|
||||
'DevengadoHorasExtrasNocturnas',
|
||||
'DevengadoHorasExtrasNocturnasDominicalesYFestivos',
|
||||
'DevengadoHorasRecargoDiariasDominicalesYFestivos',
|
||||
'DevengadoHorasRecargoNocturno',
|
||||
'DevengadoHorasRecargoNocturnoDominicalesYFestivos',
|
||||
'DevengadoTransporte',
|
||||
'DIANNominaIndividual',
|
||||
'DIANNominaIndividualDeAjuste',
|
||||
'DIANNominaXML',
|
||||
'DIANNominaIndividualError',
|
||||
'DianXMLExtensionSigner',
|
||||
'Empleador',
|
||||
'Fecha',
|
||||
'FechaPago',
|
||||
'FormaPago',
|
||||
'InformacionGeneral',
|
||||
'Lugar',
|
||||
'LugarTrabajo',
|
||||
'Metadata',
|
||||
'MetodoPago',
|
||||
'Novedad',
|
||||
'NumeroSecuencia',
|
||||
'Pago',
|
||||
'Periodo',
|
||||
'PeriodoNomina',
|
||||
'Proveedor',
|
||||
'SubTipoTrabajador',
|
||||
'TipoContrato',
|
||||
'TipoDocumento',
|
||||
'TipoMoneda',
|
||||
'TipoTrabajador',
|
||||
'Trabajador',
|
||||
]
|
||||
|
||||
|
||||
class Fecha:
|
||||
def __init__(self, fecha):
|
||||
@@ -46,6 +116,7 @@ class Fecha:
|
||||
def __str__(self):
|
||||
return self.value
|
||||
|
||||
|
||||
class FechaPago(Fecha):
|
||||
def apply(self, fragment):
|
||||
fragment.set_element('./FechaPago', self.value)
|
||||
@@ -82,7 +153,8 @@ class NumeroSecuencia:
|
||||
# NIE011
|
||||
Consecutivo=self.consecutivo,
|
||||
# NIE012
|
||||
Numero = numero)
|
||||
Numero=numero)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Periodo:
|
||||
@@ -96,25 +168,28 @@ class Periodo:
|
||||
|
||||
def __post_init__(self):
|
||||
self.fecha_ingreso = Fecha.cast(self.fecha_ingreso)
|
||||
self.fecha_liquidacion_inicio = Fecha.cast(self.fecha_liquidacion_inicio)
|
||||
self.fecha_liquidacion_inicio = Fecha.cast(
|
||||
self.fecha_liquidacion_inicio)
|
||||
self.fecha_liquidacion_fin = Fecha.cast(self.fecha_liquidacion_fin)
|
||||
self.fecha_retiro = Fecha.cast(self.fecha_retiro, optional=True)
|
||||
|
||||
|
||||
def apply(self, fragment):
|
||||
fragment.set_attributes('./Periodo',
|
||||
#NIE002
|
||||
# NIE002
|
||||
FechaIngreso=self.fecha_ingreso,
|
||||
#NIE003
|
||||
# NIE003
|
||||
FechaRetiro=self.fecha_retiro,
|
||||
#NIE004
|
||||
FechaLiquidacionInicio=self.fecha_liquidacion_inicio,
|
||||
#NIE005
|
||||
# NIE004
|
||||
FechaLiquidacionInicio=(
|
||||
self.fecha_liquidacion_inicio),
|
||||
# NIE005
|
||||
FechaLiquidacionFin=self.fecha_liquidacion_fin,
|
||||
#NIE006
|
||||
# NIE006
|
||||
TiempoLaborado=self.tiempo_laborado,
|
||||
#NIE008
|
||||
# NIE008
|
||||
FechaGen=self.fecha_generacion)
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
class Proveedor:
|
||||
razon_social: str
|
||||
@@ -140,29 +215,36 @@ class Proveedor:
|
||||
def post_apply(self, fexml, scopexml, fragment):
|
||||
cune_xpath = scopexml.xpath_from_root('/InformacionGeneral')
|
||||
cune = fexml.get_element_attribute(cune_xpath, 'CUNE')
|
||||
|
||||
ambiente = fexml.get_element_attribute(scopexml.xpath_from_root('/InformacionGeneral'), 'Ambiente')
|
||||
codigo_qr = f"https://catalogo-vpfe.dian.gov.co/document/searchqr?documentkey={cune}"
|
||||
|
||||
ambiente = fexml.get_element_attribute(
|
||||
scopexml.xpath_from_root('/InformacionGeneral'), 'Ambiente')
|
||||
codigo_qr = (
|
||||
f"https://catalogo-vpfe.dian.gov.co/document/"
|
||||
f"searchqr?documentkey={cune}")
|
||||
|
||||
if InformacionGeneral.AMBIENTE_PRUEBAS == ambiente:
|
||||
codigo_qr = f"https://catalogo-vpfe-hab.dian.gov.co/document/searchqr?documentkey={cune}"
|
||||
codigo_qr = (
|
||||
f"https://catalogo-vpfe-hab.dian.gov.co/document/"
|
||||
f"searchqr?documentkey={cune}")
|
||||
elif ambiente is None:
|
||||
raise RuntimeError('fail to get InformacionGeneral/@Ambiente')
|
||||
|
||||
|
||||
scopexml.set_element('./CodigoQR', codigo_qr)
|
||||
|
||||
# NIE020
|
||||
software_code = self._software_security_code(fexml, scopexml)
|
||||
fexml.set_attributes(scopexml.xpath_from_root('/ProveedorXML'), SoftwareSC=software_code)
|
||||
fexml.set_attributes(
|
||||
scopexml.xpath_from_root('/ProveedorXML'),
|
||||
SoftwareSC=software_code)
|
||||
|
||||
def _software_security_code(self, fexml, scopexml):
|
||||
|
||||
|
||||
# 8.2
|
||||
numero = fexml.get_element_attribute(scopexml.xpath_from_root('/NumeroSecuenciaXML'), 'Numero')
|
||||
numero = fexml.get_element_attribute(
|
||||
scopexml.xpath_from_root('/NumeroSecuenciaXML'), 'Numero')
|
||||
if numero is None:
|
||||
raise RuntimeError('fallo obtener NumeroSequenciaXML/@Numero')
|
||||
|
||||
|
||||
id_software = self.software_id
|
||||
software_pin = self.software_pin
|
||||
|
||||
@@ -172,7 +254,8 @@ class Proveedor:
|
||||
h = hashlib.sha384()
|
||||
h.update(code.encode('utf-8'))
|
||||
return h.hexdigest()
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
class Metadata:
|
||||
novedad: Novedad
|
||||
@@ -181,18 +264,33 @@ class Metadata:
|
||||
lugar_generacion: Lugar
|
||||
proveedor: Proveedor
|
||||
|
||||
def apply(self, novedad, numero_secuencia_xml, lugar_generacion_xml, proveedor_xml):
|
||||
def apply(
|
||||
self,
|
||||
novedad,
|
||||
numero_secuencia_xml,
|
||||
lugar_generacion_xml,
|
||||
proveedor_xml):
|
||||
if novedad:
|
||||
self.novedad.apply(novedad)
|
||||
self.secuencia.apply(numero_secuencia_xml)
|
||||
self.lugar_generacion.apply(lugar_generacion_xml, './LugarGeneracionXML')
|
||||
self.lugar_generacion.apply(
|
||||
lugar_generacion_xml,
|
||||
'./LugarGeneracionXML')
|
||||
self.proveedor.apply(proveedor_xml)
|
||||
|
||||
def post_apply(self, fexml, scopexml, novedad, numero_secuencia_xml, lugar_generacion_xml, proveedor_xml):
|
||||
def post_apply(
|
||||
self,
|
||||
fexml,
|
||||
scopexml,
|
||||
novedad,
|
||||
numero_secuencia_xml,
|
||||
lugar_generacion_xml,
|
||||
proveedor_xml):
|
||||
self.proveedor.post_apply(fexml, scopexml, proveedor_xml)
|
||||
if novedad:
|
||||
self.novedad.post_apply(fexml, scopexml, proveedor_xml)
|
||||
|
||||
self.novedad.post_apply(fexml, scopexml, proveedor_xml)
|
||||
|
||||
|
||||
@dataclass
|
||||
class PeriodoNomina:
|
||||
code: str
|
||||
@@ -203,6 +301,7 @@ class PeriodoNomina:
|
||||
raise ValueError("code [%s] not found" % (self.code))
|
||||
self.name = codelist.PeriodoNomina[self.code]['name']
|
||||
|
||||
|
||||
@dataclass
|
||||
class TipoMoneda:
|
||||
code: str
|
||||
@@ -213,6 +312,7 @@ class TipoMoneda:
|
||||
raise ValueError("code [%s] not found" % (self.code))
|
||||
self.name = codelist.TipoMoneda[self.code]['name']
|
||||
|
||||
|
||||
@dataclass
|
||||
class InformacionGeneral:
|
||||
@dataclass
|
||||
@@ -235,7 +335,7 @@ class InformacionGeneral:
|
||||
valor: str = '2'
|
||||
|
||||
def __str__(self):
|
||||
self.valor
|
||||
self.valor
|
||||
|
||||
# TABLA 5.5.7
|
||||
@dataclass
|
||||
@@ -250,7 +350,7 @@ class InformacionGeneral:
|
||||
valor: str = '102'
|
||||
|
||||
def __str__(self):
|
||||
self.valor
|
||||
self.valor
|
||||
|
||||
@dataclass
|
||||
class TIPO_XML_AJUSTES(TIPO_XML):
|
||||
@@ -273,26 +373,26 @@ class InformacionGeneral:
|
||||
def apply(self, fragment, version):
|
||||
fragment.set_attributes('./InformacionGeneral',
|
||||
# NIE022
|
||||
Version = version,
|
||||
Version=version,
|
||||
# NIE023
|
||||
Ambiente = self.tipo_ambiente.valor,
|
||||
Ambiente=self.tipo_ambiente.valor,
|
||||
# NIE202
|
||||
# TABLA 5.5.2
|
||||
# TODO(bit4bit) solo NominaIndividual
|
||||
TipoXML = self.tipo_xml.valor,
|
||||
TipoXML=self.tipo_xml.valor,
|
||||
# NIE024
|
||||
CUNE = None,
|
||||
CUNE=None,
|
||||
# NIE025
|
||||
EncripCUNE = 'CUNE-SHA384',
|
||||
EncripCUNE='CUNE-SHA384',
|
||||
# NIE026
|
||||
FechaGen = self.fecha_generacion,
|
||||
FechaGen=self.fecha_generacion,
|
||||
# NIE027
|
||||
HoraGen = self.hora_generacion,
|
||||
HoraGen=self.hora_generacion,
|
||||
# NIE029
|
||||
PeriodoNomina = self.periodo_nomina.code,
|
||||
PeriodoNomina=self.periodo_nomina.code,
|
||||
# NIE030
|
||||
TipoMoneda = self.tipo_moneda.code,
|
||||
TRM = 0
|
||||
TipoMoneda=self.tipo_moneda.code,
|
||||
TRM=0
|
||||
# TODO(bit4bit) resto...
|
||||
# .....
|
||||
)
|
||||
@@ -321,24 +421,35 @@ class InformacionGeneral:
|
||||
h = hashlib.sha384()
|
||||
h.update(cune.encode('utf-8'))
|
||||
cune_hash = h.hexdigest()
|
||||
|
||||
|
||||
fragment.set_attributes(
|
||||
'./InformacionGeneral',
|
||||
# NIE024
|
||||
CUNE = cune_hash
|
||||
CUNE=cune_hash
|
||||
)
|
||||
|
||||
|
||||
class DianXMLExtensionSigner(fe.DianXMLExtensionSigner):
|
||||
|
||||
def __init__(self, pkcs12_path, passphrase=None, localpolicy=True):
|
||||
super().__init__(pkcs12_path, passphrase=passphrase, localpolicy=localpolicy)
|
||||
super().__init__(
|
||||
pkcs12_path,
|
||||
passphrase=passphrase,
|
||||
localpolicy=localpolicy)
|
||||
|
||||
def _element_extension_content(self, fachoxml):
|
||||
return fachoxml.builder.xpath(fachoxml.root, './ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent')
|
||||
return fachoxml.builder.xpath(
|
||||
fachoxml.root,
|
||||
'./ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent')
|
||||
|
||||
|
||||
class DIANNominaXML:
|
||||
def __init__(self, tag_document, xpath_ajuste=None, schemaLocation=None, namespace_ajuste=None):
|
||||
def __init__(
|
||||
self,
|
||||
tag_document,
|
||||
xpath_ajuste=None,
|
||||
schemaLocation=None,
|
||||
namespace_ajuste=None):
|
||||
self.informacion_general_version = None
|
||||
|
||||
self.tag_document = tag_document
|
||||
@@ -346,21 +457,26 @@ class DIANNominaXML:
|
||||
if namespace_ajuste:
|
||||
self.fexml = fe.FeXML(tag_document, namespace_ajuste)
|
||||
else:
|
||||
self.fexml = fe.FeXML(tag_document, 'dian:gov:co:facturaelectronica:NominaIndividual')
|
||||
self.fexml = fe.FeXML(
|
||||
tag_document,
|
||||
'dian:gov:co:facturaelectronica:NominaIndividual')
|
||||
|
||||
self.fexml.root.set("SchemaLocation", "")
|
||||
self.fexml.root.set("schemaLocation", schemaLocation)
|
||||
|
||||
# layout, la dian requiere que los elementos
|
||||
# esten ordenados segun el anexo tecnico
|
||||
self.fexml.placeholder_for('./ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent')
|
||||
self.fexml.placeholder_for(
|
||||
'./ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent')
|
||||
self.fexml.placeholder_for('./TipoNota', optional=True)
|
||||
|
||||
self.root_fragment = self.fexml
|
||||
if xpath_ajuste is not None:
|
||||
self.root_fragment = self.fexml.fragment(xpath_ajuste)
|
||||
self.root_fragment.placeholder_for('./ReemplazandoPredecesor', optional=True)
|
||||
self.root_fragment.placeholder_for('./EliminandoPredecesor', optional=True)
|
||||
self.root_fragment.placeholder_for(
|
||||
'./ReemplazandoPredecesor', optional=True)
|
||||
self.root_fragment.placeholder_for(
|
||||
'./EliminandoPredecesor', optional=True)
|
||||
if not namespace_ajuste:
|
||||
self.root_fragment.placeholder_for('./Novedad', optional=False)
|
||||
self.root_fragment.placeholder_for('./Periodo')
|
||||
@@ -374,16 +490,20 @@ class DIANNominaXML:
|
||||
self.root_fragment.placeholder_for('./Pago')
|
||||
self.root_fragment.placeholder_for('./FechasPagos')
|
||||
self.root_fragment.placeholder_for('./Devengados/Basico')
|
||||
self.root_fragment.placeholder_for('./Devengados/Transporte', optional=True)
|
||||
self.root_fragment.placeholder_for(
|
||||
'./Devengados/Transporte', optional=True)
|
||||
if not namespace_ajuste:
|
||||
self.novedad = self.root_fragment.fragment('./Novedad')
|
||||
else:
|
||||
self.novedad = None
|
||||
self.informacion_general_xml = self.root_fragment.fragment('./InformacionGeneral')
|
||||
self.informacion_general_xml = self.root_fragment.fragment(
|
||||
'./InformacionGeneral')
|
||||
self.periodo_xml = self.root_fragment.fragment('./Periodo')
|
||||
self.fecha_pagos_xml = self.root_fragment.fragment('./FechasPagos')
|
||||
self.numero_secuencia_xml = self.root_fragment.fragment('./NumeroSecuenciaXML')
|
||||
self.lugar_generacion_xml = self.root_fragment.fragment('./LugarGeneracionXML')
|
||||
self.numero_secuencia_xml = self.root_fragment.fragment(
|
||||
'./NumeroSecuenciaXML')
|
||||
self.lugar_generacion_xml = self.root_fragment.fragment(
|
||||
'./LugarGeneracionXML')
|
||||
self.proveedor_xml = self.root_fragment.fragment('./ProveedorXML')
|
||||
self.empleador = self.root_fragment.fragment('./Empleador')
|
||||
self.trabajador = self.root_fragment.fragment('./Trabajador')
|
||||
@@ -398,14 +518,20 @@ class DIANNominaXML:
|
||||
if not isinstance(metadata, Metadata):
|
||||
raise ValueError('se espera tipo Metadata')
|
||||
self.metadata = metadata
|
||||
|
||||
self.metadata.apply(self.novedad, self.numero_secuencia_xml, self.lugar_generacion_xml, self.proveedor_xml)
|
||||
|
||||
|
||||
self.metadata.apply(
|
||||
self.novedad,
|
||||
self.numero_secuencia_xml,
|
||||
self.lugar_generacion_xml,
|
||||
self.proveedor_xml)
|
||||
|
||||
def asignar_informacion_general(self, general):
|
||||
if not isinstance(general, InformacionGeneral):
|
||||
raise ValueError('se espera tipo InformacionGeneral')
|
||||
self.informacion_general = general
|
||||
self.informacion_general.apply(self.informacion_general_xml, self.informacion_general_version)
|
||||
self.informacion_general.apply(
|
||||
self.informacion_general_xml,
|
||||
self.informacion_general_version)
|
||||
|
||||
def asignar_periodo(self, periodo):
|
||||
if not isinstance(periodo, Periodo):
|
||||
@@ -435,7 +561,7 @@ class DIANNominaXML:
|
||||
if not isinstance(trabajador, Trabajador):
|
||||
raise ValueError('se espera tipo Trabajador')
|
||||
trabajador.apply(self.trabajador)
|
||||
|
||||
|
||||
def adicionar_devengado(self, devengado):
|
||||
if not isinstance(devengado, Devengado):
|
||||
raise ValueError('se espera tipo Devengado')
|
||||
@@ -482,7 +608,7 @@ class DIANNominaXML:
|
||||
self.fexml.xpath_from_root('/Devengados/Basico'),
|
||||
'se requiere DevengadoBasico'
|
||||
)
|
||||
|
||||
|
||||
check_element(
|
||||
self.fexml.xpath_from_root('/Deducciones/Salud'),
|
||||
'se requiere DeduccionSalud'
|
||||
@@ -498,10 +624,13 @@ class DIANNominaXML:
|
||||
def informacion_general(self):
|
||||
xpath = self.root_fragment.xpath_from_root('/InformacionGeneral')
|
||||
return {
|
||||
'cune': self.fexml.get_element_attribute(cune_xpath, 'CUNE'),
|
||||
'fecha_generacion': self.fexml.get_element_attribute(xpath, 'FechaGen'),
|
||||
'numero': self.fexml.get_element_attribute(self.root_fragment('/NumeroSecuenciaXML', 'Numero'))
|
||||
}
|
||||
'cune': self.fexml.get_element_attribute(
|
||||
xpath, 'CUNE'),
|
||||
'fecha_generacion': self.fexml.get_element_attribute(
|
||||
xpath, 'FechaGen'),
|
||||
'numero': self.fexml.get_element_attribute(
|
||||
self.root_fragment(
|
||||
'/NumeroSecuenciaXML', 'Numero'))}
|
||||
|
||||
def toFachoXML(self):
|
||||
self._devengados_total()
|
||||
@@ -509,59 +638,78 @@ class DIANNominaXML:
|
||||
self._comprobante_total()
|
||||
|
||||
if self.informacion_general is not None:
|
||||
#TODO(bit4bit) acoplamiento temporal
|
||||
# TODO(bit4bit) acoplamiento temporal
|
||||
# es importante el orden de ejecucion
|
||||
|
||||
self.informacion_general.post_apply(self.fexml, self.root_fragment, self.informacion_general_xml)
|
||||
self.informacion_general.post_apply(
|
||||
self.fexml, self.root_fragment, self.informacion_general_xml)
|
||||
|
||||
if self.metadata is not None:
|
||||
self.metadata.post_apply(self.fexml, self.root_fragment, self.novedad, self.numero_secuencia_xml, self.lugar_generacion_xml, self.proveedor_xml)
|
||||
self.metadata.post_apply(
|
||||
self.fexml,
|
||||
self.root_fragment,
|
||||
self.novedad,
|
||||
self.numero_secuencia_xml,
|
||||
self.lugar_generacion_xml,
|
||||
self.proveedor_xml)
|
||||
|
||||
return self.fexml
|
||||
|
||||
def _comprobante_total(self):
|
||||
devengados_total = self.root_fragment.get_element_text_or_attribute('./DevengadosTotal', '0.0')
|
||||
deducciones_total = self.root_fragment.get_element_text_or_attribute('./DeduccionesTotal', '0.0')
|
||||
devengados_total = self.root_fragment.get_element_text_or_attribute(
|
||||
'./DevengadosTotal', '0.0')
|
||||
deducciones_total = self.root_fragment.get_element_text_or_attribute(
|
||||
'./DeduccionesTotal', '0.0')
|
||||
|
||||
comprobante_total = Amount(devengados_total) - Amount(deducciones_total)
|
||||
comprobante_total = Amount(devengados_total) - \
|
||||
Amount(deducciones_total)
|
||||
|
||||
self.root_fragment.set_element('./ComprobanteTotal', str(round(comprobante_total, 2)))
|
||||
self.root_fragment.set_element(
|
||||
'./ComprobanteTotal', str(round(comprobante_total, 2)))
|
||||
|
||||
def _deducciones_total(self):
|
||||
xpaths = [
|
||||
self.root_fragment.xpath_from_root('/Deducciones/Salud/@Deduccion'),
|
||||
self.root_fragment.xpath_from_root('/Deducciones/FondoPension/@Deduccion')
|
||||
]
|
||||
self.root_fragment.xpath_from_root(
|
||||
'/Deducciones/Salud/@Deduccion'),
|
||||
self.root_fragment.xpath_from_root(
|
||||
'/Deducciones/FondoPension/@Deduccion')]
|
||||
deducciones = map(lambda valor: Amount(valor),
|
||||
self._values_of_xpaths(xpaths))
|
||||
|
||||
deducciones_total = Amount(0.0)
|
||||
|
||||
|
||||
for deduccion in deducciones:
|
||||
deducciones_total += deduccion
|
||||
|
||||
self.root_fragment.set_element('./DeduccionesTotal', str(round(deducciones_total, 2)))
|
||||
self.root_fragment.set_element(
|
||||
'./DeduccionesTotal', str(round(deducciones_total, 2)))
|
||||
|
||||
def _devengados_total(self):
|
||||
xpaths = [
|
||||
self.root_fragment.xpath_from_root('/Devengados/Basico/@SueldoTrabajado'),
|
||||
self.root_fragment.xpath_from_root('/Devengados/Transporte/@AuxilioTransporte'),
|
||||
self.root_fragment.xpath_from_root('/Devengados/Transporte/@ViaticoManuAlojS'),
|
||||
self.root_fragment.xpath_from_root('/Devengados/Transporte/@ViaticoManuAlojNS')
|
||||
]
|
||||
self.root_fragment.xpath_from_root(
|
||||
'/Devengados/Basico/@SueldoTrabajado'),
|
||||
self.root_fragment.xpath_from_root(
|
||||
'/Devengados/Transporte/@AuxilioTransporte'),
|
||||
self.root_fragment.xpath_from_root(
|
||||
'/Devengados/Transporte/@ViaticoManuAlojS'),
|
||||
self.root_fragment.xpath_from_root(
|
||||
'/Devengados/Transporte/@ViaticoManuAlojNS')]
|
||||
devengados = map(lambda valor: Amount(valor),
|
||||
self._values_of_xpaths(xpaths))
|
||||
|
||||
|
||||
devengados_total = Amount(0.0)
|
||||
for devengado in devengados:
|
||||
devengados_total += devengado
|
||||
# TODO(bit4bit) nque valor va redondeado?
|
||||
# NIE186
|
||||
self.root_fragment.set_element('./Redondeo', str(round(0,2)))
|
||||
self.root_fragment.set_element('./DevengadosTotal', str(round(devengados_total,2)))
|
||||
self.root_fragment.set_element('./Redondeo', str(round(0, 2)))
|
||||
self.root_fragment.set_element(
|
||||
'./DevengadosTotal', str(round(devengados_total, 2)))
|
||||
|
||||
def _values_of_xpaths(self, xpaths):
|
||||
xpaths_values_of_values = map(lambda val: self.fexml.get_element_text_or_attribute(val, multiple=True), xpaths)
|
||||
xpaths_values_of_values = map(
|
||||
lambda val: self.fexml.get_element_text_or_attribute(
|
||||
val, multiple=True), xpaths)
|
||||
xpaths_values = []
|
||||
# toda esta carreta para hacer un aplano de lista
|
||||
for xpath_values in xpaths_values_of_values:
|
||||
@@ -573,15 +721,22 @@ class DIANNominaXML:
|
||||
|
||||
return filter(lambda val: val is not None, xpaths_values)
|
||||
|
||||
|
||||
class DIANNominaIndividual(DIANNominaXML):
|
||||
|
||||
def __init__(self):
|
||||
schema = "dian:gov:co:facturaelectronica:NominaIndividual NominaIndividualElectronicaXSD.xsd"
|
||||
schema = (
|
||||
"dian:gov:co:facturaelectronica:NominaIndividual"
|
||||
" NominaIndividualElectronicaXSD.xsd"
|
||||
)
|
||||
|
||||
super().__init__('NominaIndividual', schemaLocation=schema)
|
||||
self.informacion_general_version = 'V1.0: Documento Soporte de Pago de Nómina Electrónica'
|
||||
self.informacion_general_version = (
|
||||
'V1.0: Documento Soporte de Pago de Nómina Electrónica')
|
||||
|
||||
# TODO(bit4bit) confirmar que no tienen en comun con NominaIndividual
|
||||
|
||||
|
||||
class DIANNominaIndividualDeAjuste(DIANNominaXML):
|
||||
|
||||
class Reemplazar(DIANNominaXML):
|
||||
@@ -593,31 +748,42 @@ class DIANNominaIndividualDeAjuste(DIANNominaXML):
|
||||
|
||||
def apply(self, fragment):
|
||||
# NIAE214
|
||||
fragment.set_element('./TipoNota', '1')
|
||||
fragment.set_element('./Reemplazar/ReemplazandoPredecesor', None,
|
||||
# NIAE090
|
||||
NumeroPred = self.numero,
|
||||
# NIAE191
|
||||
CUNEPred = self.cune,
|
||||
# NIAE192
|
||||
FechaGenPred = self.fecha_generacion
|
||||
fragment.set_element('./TipoNota', '1')
|
||||
fragment.set_element(
|
||||
'./Reemplazar/ReemplazandoPredecesor', None,
|
||||
# NIAE090
|
||||
NumeroPred=self.numero,
|
||||
# NIAE191
|
||||
CUNEPred=self.cune,
|
||||
# NIAE192
|
||||
FechaGenPred=self.fecha_generacion
|
||||
)
|
||||
|
||||
def __init__(self):
|
||||
schema = "dian:gov:co:facturaelectronica:NominaIndividualDeAjuste NominaIndividualDeAjusteElectronicaXSD.xsd"
|
||||
|
||||
super().__init__('NominaIndividualDeAjuste', './Reemplazar', schemaLocation=schema, namespace_ajuste='dian:gov:co:facturaelectronica:NominaIndividualDeAjuste')
|
||||
|
||||
self.informacion_general_version = 'V1.0: Nota de Ajuste de Documento Soporte de Pago de Nómina Electrónica'
|
||||
schema = (
|
||||
"dian:gov:co:facturaelectronica:NominaIndividualDeAjuste"
|
||||
" NominaIndividualDeAjusteElectronicaXSD.xsd"
|
||||
)
|
||||
|
||||
super().__init__(
|
||||
'NominaIndividualDeAjuste',
|
||||
'./Reemplazar',
|
||||
schemaLocation=schema,
|
||||
namespace_ajuste=(
|
||||
'dian:gov:co:facturaelectronica:'
|
||||
'NominaIndividualDeAjuste'))
|
||||
|
||||
self.informacion_general_version = (
|
||||
'V1.0: Nota de Ajuste de Documento Soporte de Pago de '
|
||||
'Nómina Electrónica')
|
||||
|
||||
def asignar_predecesor(self, predecesor):
|
||||
if not isinstance(predecesor, self.Predecesor):
|
||||
raise ValueError("se espera tipo Predecesor")
|
||||
predecesor.apply(self.fexml)
|
||||
|
||||
|
||||
class Eliminar(DIANNominaXML):
|
||||
|
||||
|
||||
@dataclass
|
||||
class Predecesor:
|
||||
numero: str
|
||||
@@ -628,24 +794,34 @@ class DIANNominaIndividualDeAjuste(DIANNominaXML):
|
||||
fragment.set_element('./TipoNota', '2')
|
||||
fragment.set_element('./Eliminar/EliminandoPredecesor', None,
|
||||
# NIAE090
|
||||
NumeroPred = self.numero,
|
||||
NumeroPred=self.numero,
|
||||
# NIAE191
|
||||
CUNEPred = self.cune,
|
||||
CUNEPred=self.cune,
|
||||
# NIAE192
|
||||
FechaGenPred = self.fecha_generacion
|
||||
FechaGenPred=self.fecha_generacion
|
||||
)
|
||||
|
||||
def __init__(self):
|
||||
schema = "dian:gov:co:facturaelectronica:NominaIndividualDeAjuste NominaIndividualDeAjusteElectronicaXSD.xsd"
|
||||
super().__init__('NominaIndividualDeAjuste', './Eliminar', schemaLocation=schema, namespace_ajuste='dian:gov:co:facturaelectronica:NominaIndividualDeAjuste')
|
||||
schema = (
|
||||
"dian:gov:co:facturaelectronica:NominaIndividualDeAjuste"
|
||||
" NominaIndividualDeAjusteElectronicaXSD.xsd"
|
||||
)
|
||||
super().__init__(
|
||||
'NominaIndividualDeAjuste',
|
||||
'./Eliminar',
|
||||
schemaLocation=schema,
|
||||
namespace_ajuste=(
|
||||
'dian:gov:co:facturaelectronica:'
|
||||
'NominaIndividualDeAjuste'))
|
||||
|
||||
self.informacion_general_version = "V1.0: Nota de Ajuste de Documento Soporte de Pago de Nómina Electrónica"
|
||||
self.informacion_general_version = (
|
||||
"V1.0: Nota de Ajuste de Documento Soporte de Pago de "
|
||||
"Nómina Electrónica")
|
||||
|
||||
def asignar_predecesor(self, predecesor):
|
||||
if not isinstance(predecesor, self.Predecesor):
|
||||
raise ValueError("se espera tipo Eliminar.Predecesor")
|
||||
predecesor.apply(self.fexml)
|
||||
|
||||
|
||||
def __init__(self):
|
||||
super().__init__('NominaIndividualDeAjuste')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user