@@ -99,6 +99,19 @@ def validate_cesion_and_dte_montos(cesion_value: int, dte_value: int) -> None:
9999 raise ValueError ('Value of "cesión" must be <= value of DTE.' , cesion_value , dte_value )
100100
101101
102+ def validate_cesion_fecha_ultimo_vencimiento_is_consistent_with_dte (
103+ cesion_value : date , dte_value : date
104+ ) -> None :
105+ """
106+ Validate 'fecha_ultimo_vencimiento' of the "cesión" is after or equal
107+ to 'fecha_emision' of the DTE.
108+
109+ :raises ValueError:
110+ """
111+ if not (cesion_value >= dte_value ):
112+ raise ValueError ('Value of "cesión" must be >= value of DTE.' , cesion_value , dte_value )
113+
114+
102115@pydantic .dataclasses .dataclass (
103116 frozen = True ,
104117 config = type ('Config' , (), dict (
@@ -537,6 +550,20 @@ def validate_monto_cedido_does_not_exceed_dte_monto_total(
537550
538551 return values
539552
553+ @pydantic .root_validator (skip_on_failure = True )
554+ def validate_fecha_ultimo_vencimiento_is_consistent_with_dte (
555+ cls , values : Mapping [str , object ],
556+ ) -> Mapping [str , object ]:
557+ fecha_ultimo_vencimiento = values ['fecha_ultimo_vencimiento' ]
558+ dte_fecha_emision = values ['dte_fecha_emision' ]
559+
560+ if isinstance (fecha_ultimo_vencimiento , date ) and isinstance (dte_fecha_emision , date ):
561+ validate_cesion_fecha_ultimo_vencimiento_is_consistent_with_dte (
562+ cesion_value = fecha_ultimo_vencimiento , dte_value = dte_fecha_emision
563+ )
564+
565+ return values
566+
540567
541568@pydantic .dataclasses .dataclass (
542569 frozen = True ,
@@ -700,8 +727,6 @@ def as_dte_data_l2(self) -> dte_data_models.DteDataL2:
700727
701728 # TODO: Validate value of 'fecha_firma_dt' in relation to the DTE data.
702729
703- # TODO: Validate value of 'fecha_ultimo_vencimiento' in relation to the DTE data.
704-
705730 @pydantic .validator ('fecha_cesion_dt' )
706731 def validate_fecha_cesion_dt (cls , v : object ) -> object :
707732 if isinstance (v , datetime ):
@@ -745,3 +770,17 @@ def validate_dte_data_l2(cls, values: Mapping[str, Any]) -> Mapping[str, object]
745770 raise
746771
747772 return values
773+
774+ @pydantic .root_validator (skip_on_failure = True )
775+ def validate_fecha_ultimo_vencimiento_is_consistent_with_dte (
776+ cls , values : Mapping [str , object ],
777+ ) -> Mapping [str , object ]:
778+ fecha_ultimo_vencimiento = values ['fecha_ultimo_vencimiento' ]
779+ dte_fecha_emision = values ['dte_fecha_emision' ]
780+
781+ if isinstance (fecha_ultimo_vencimiento , date ) and isinstance (dte_fecha_emision , date ):
782+ validate_cesion_fecha_ultimo_vencimiento_is_consistent_with_dte (
783+ cesion_value = fecha_ultimo_vencimiento , dte_value = dte_fecha_emision
784+ )
785+
786+ return values
0 commit comments