se crea tipo Fecha para gestion de fechas
FossilOrigin-Name: ca4b0b511cb9ac37e174fbda1f53e8590e5615b0779916781ca4c1fdc002325a
This commit is contained in:
parent
4ceec2ca53
commit
248ec4304d
@ -6,7 +6,9 @@
|
|||||||
# creando las estructuras minimas necesaras.
|
# creando las estructuras minimas necesaras.
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from datetime import datetime
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import typing
|
||||||
|
|
||||||
from .. import fe
|
from .. import fe
|
||||||
from .. import form
|
from .. import form
|
||||||
@ -22,6 +24,22 @@ from .lugar import Lugar
|
|||||||
from .amount import Amount
|
from .amount import Amount
|
||||||
from .exception import *
|
from .exception import *
|
||||||
|
|
||||||
|
class Fecha:
|
||||||
|
def __init__(self, fecha):
|
||||||
|
try:
|
||||||
|
datetime.strptime(fecha, "%Y-%m-%d")
|
||||||
|
except ValueError:
|
||||||
|
raise ValueError("fecha debe ser formato 2000-01-01")
|
||||||
|
|
||||||
|
self.value = fecha
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.value
|
||||||
|
|
||||||
|
class FechaPago(Fecha):
|
||||||
|
def apply(self, fragment):
|
||||||
|
fragment.set_element('./FechaPago', self.value)
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class NumeroSecuencia:
|
class NumeroSecuencia:
|
||||||
consecutivo: int
|
consecutivo: int
|
||||||
@ -259,7 +277,7 @@ class DIANNominaXML:
|
|||||||
|
|
||||||
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.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.numero_secuencia_xml = self.root_fragment.fragment('./NumeroSecuenciaXML')
|
||||||
self.lugar_generacion_xml = self.root_fragment.fragment('./LugarGeneracionXML')
|
self.lugar_generacion_xml = self.root_fragment.fragment('./LugarGeneracionXML')
|
||||||
self.proveedor_xml = self.root_fragment.fragment('./ProveedorXML')
|
self.proveedor_xml = self.root_fragment.fragment('./ProveedorXML')
|
||||||
@ -295,8 +313,13 @@ class DIANNominaXML:
|
|||||||
raise ValueError('se espera tipo Pago')
|
raise ValueError('se espera tipo Pago')
|
||||||
pago.apply(self.pago_xml)
|
pago.apply(self.pago_xml)
|
||||||
|
|
||||||
def asignar_fecha_pago(self, fecha):
|
def asignar_fecha_pago(self, data):
|
||||||
self.fexml.set_element('./FechasPagos/FechaPago', fecha)
|
if isinstance(data, str):
|
||||||
|
fecha = FechaPago(data)
|
||||||
|
elif isinstance(data, FechaPago):
|
||||||
|
fecha = data
|
||||||
|
|
||||||
|
fecha.apply(self.fecha_pagos_xml)
|
||||||
|
|
||||||
def asignar_empleador(self, empleador):
|
def asignar_empleador(self, empleador):
|
||||||
if not isinstance(empleador, Empleador):
|
if not isinstance(empleador, Empleador):
|
||||||
|
@ -123,7 +123,7 @@ def test_nomina_xml():
|
|||||||
|
|
||||||
nomina.asignar_metadata(fe.nomina.Metadata(
|
nomina.asignar_metadata(fe.nomina.Metadata(
|
||||||
secuencia=fe.nomina.NumeroSecuencia(
|
secuencia=fe.nomina.NumeroSecuencia(
|
||||||
numero = 'N00001',
|
prefijo = 'N',
|
||||||
consecutivo=232
|
consecutivo=232
|
||||||
),
|
),
|
||||||
lugar_generacion=fe.nomina.Lugar(
|
lugar_generacion=fe.nomina.Lugar(
|
||||||
@ -141,7 +141,7 @@ def test_nomina_xml():
|
|||||||
nit='999999',
|
nit='999999',
|
||||||
dv=2,
|
dv=2,
|
||||||
software_id='xx',
|
software_id='xx',
|
||||||
software_sc='yy'
|
software_pin='12'
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
|
|
||||||
@ -343,3 +343,8 @@ def test_adicionar_eliminar_asignar_predecesor():
|
|||||||
assert xml.get_element_text_or_attribute('/fe:NominaIndividualDeAjuste/Eliminar/EliminandoPredecesor/@NumeroPred') == '123456'
|
assert xml.get_element_text_or_attribute('/fe:NominaIndividualDeAjuste/Eliminar/EliminandoPredecesor/@NumeroPred') == '123456'
|
||||||
assert xml.get_element_text_or_attribute('/fe:NominaIndividualDeAjuste/Eliminar/EliminandoPredecesor/@CUNEPred') == 'ABC123456'
|
assert xml.get_element_text_or_attribute('/fe:NominaIndividualDeAjuste/Eliminar/EliminandoPredecesor/@CUNEPred') == 'ABC123456'
|
||||||
assert xml.get_element_text_or_attribute('/fe:NominaIndividualDeAjuste/Eliminar/EliminandoPredecesor/@FechaGenPred') == '2021-11-16'
|
assert xml.get_element_text_or_attribute('/fe:NominaIndividualDeAjuste/Eliminar/EliminandoPredecesor/@FechaGenPred') == '2021-11-16'
|
||||||
|
|
||||||
|
|
||||||
|
def test_fecha_validacion():
|
||||||
|
with pytest.raises(ValueError) as e:
|
||||||
|
fe.nomina.Fecha('535-35-3')
|
||||||
|
Loading…
Reference in New Issue
Block a user