@@ -97,6 +97,19 @@ def validate_cesion_and_dte_montos(cesion_value: int, dte_value: int) -> None:
9797 raise ValueError ('Value of "cesión" must be <= value of DTE.' , cesion_value , dte_value )
9898
9999
100+ def validate_cesion_fecha_ultimo_vencimiento_is_consistent_with_dte (
101+ cesion_value : date , dte_value : date
102+ ) -> None :
103+ """
104+ Validate 'fecha_ultimo_vencimiento' of the "cesión" is after or equal
105+ to 'fecha_emision' of the DTE.
106+
107+ :raises ValueError:
108+ """
109+ if not (cesion_value >= dte_value ):
110+ raise ValueError ('Value of "cesión" must be >= value of DTE.' , cesion_value , dte_value )
111+
112+
100113@pydantic .dataclasses .dataclass (
101114 frozen = True ,
102115 config = type ('Config' , (), dict (
@@ -531,6 +544,20 @@ def validate_monto_cedido_does_not_exceed_dte_monto_total(
531544
532545 return values
533546
547+ @pydantic .root_validator (skip_on_failure = True )
548+ def validate_fecha_ultimo_vencimiento_is_consistent_with_dte (
549+ cls , values : Mapping [str , object ],
550+ ) -> Mapping [str , object ]:
551+ fecha_ultimo_vencimiento = values ['fecha_ultimo_vencimiento' ]
552+ dte_fecha_emision = values ['dte_fecha_emision' ]
553+
554+ if isinstance (fecha_ultimo_vencimiento , date ) and isinstance (dte_fecha_emision , date ):
555+ validate_cesion_fecha_ultimo_vencimiento_is_consistent_with_dte (
556+ cesion_value = fecha_ultimo_vencimiento , dte_value = dte_fecha_emision
557+ )
558+
559+ return values
560+
534561
535562@pydantic .dataclasses .dataclass (
536563 frozen = True ,
@@ -694,8 +721,6 @@ def as_dte_data_l2(self) -> dte_data_models.DteDataL2:
694721
695722 # TODO: Validate value of 'fecha_firma_dt' in relation to the DTE data.
696723
697- # TODO: Validate value of 'fecha_ultimo_vencimiento' in relation to the DTE data.
698-
699724 @pydantic .validator ('fecha_cesion_dt' )
700725 def validate_fecha_cesion_dt (cls , v : object ) -> object :
701726 if isinstance (v , datetime ):
@@ -739,3 +764,17 @@ def validate_dte_data_l2(cls, values: Mapping[str, Any]) -> Mapping[str, object]
739764 raise
740765
741766 return values
767+
768+ @pydantic .root_validator (skip_on_failure = True )
769+ def validate_fecha_ultimo_vencimiento_is_consistent_with_dte (
770+ cls , values : Mapping [str , object ],
771+ ) -> Mapping [str , object ]:
772+ fecha_ultimo_vencimiento = values ['fecha_ultimo_vencimiento' ]
773+ dte_fecha_emision = values ['dte_fecha_emision' ]
774+
775+ if isinstance (fecha_ultimo_vencimiento , date ) and isinstance (dte_fecha_emision , date ):
776+ validate_cesion_fecha_ultimo_vencimiento_is_consistent_with_dte (
777+ cesion_value = fecha_ultimo_vencimiento , dte_value = dte_fecha_emision
778+ )
779+
780+ return values
0 commit comments