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.
|
||||
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
import hashlib
|
||||
import typing
|
||||
|
||||
from .. import fe
|
||||
from .. import form
|
||||
@ -22,6 +24,22 @@ from .lugar import Lugar
|
||||
from .amount import Amount
|
||||
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
|
||||
class NumeroSecuencia:
|
||||
consecutivo: int
|
||||
@ -259,7 +277,7 @@ class DIANNominaXML:
|
||||
|
||||
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.proveedor_xml = self.root_fragment.fragment('./ProveedorXML')
|
||||
@ -295,8 +313,13 @@ class DIANNominaXML:
|
||||
raise ValueError('se espera tipo Pago')
|
||||
pago.apply(self.pago_xml)
|
||||
|
||||
def asignar_fecha_pago(self, fecha):
|
||||
self.fexml.set_element('./FechasPagos/FechaPago', fecha)
|
||||
def asignar_fecha_pago(self, data):
|
||||
if isinstance(data, str):
|
||||
fecha = FechaPago(data)
|
||||
elif isinstance(data, FechaPago):
|
||||
fecha = data
|
||||
|
||||
fecha.apply(self.fecha_pagos_xml)
|
||||
|
||||
def asignar_empleador(self, empleador):
|
||||
if not isinstance(empleador, Empleador):
|
||||
|
@ -123,7 +123,7 @@ def test_nomina_xml():
|
||||
|
||||
nomina.asignar_metadata(fe.nomina.Metadata(
|
||||
secuencia=fe.nomina.NumeroSecuencia(
|
||||
numero = 'N00001',
|
||||
prefijo = 'N',
|
||||
consecutivo=232
|
||||
),
|
||||
lugar_generacion=fe.nomina.Lugar(
|
||||
@ -141,7 +141,7 @@ def test_nomina_xml():
|
||||
nit='999999',
|
||||
dv=2,
|
||||
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/@CUNEPred') == 'ABC123456'
|
||||
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