@@ -99,6 +99,25 @@ 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+ > Que la fecha del último vencimiento sea mayor o igual a la fecha
110+ > consignada en el documento.
111+ Source: https://github.com/cl-sii-extraoficial/archivos-oficiales/blob/master/src/docs/rtc/2013-02-11-instructivo-tecnico.pdf
112+
113+
114+
115+ :raises ValueError:
116+ """ # noqa: E501
117+ if not (cesion_value >= dte_value ):
118+ raise ValueError ('Value of "cesión" must be >= value of DTE.' , cesion_value , dte_value )
119+
120+
102121@pydantic .dataclasses .dataclass (
103122 frozen = True ,
104123 config = type ('Config' , (), dict (
@@ -537,6 +556,20 @@ def validate_monto_cedido_does_not_exceed_dte_monto_total(
537556
538557 return values
539558
559+ @pydantic .root_validator (skip_on_failure = True )
560+ def validate_fecha_ultimo_vencimiento_is_consistent_with_dte (
561+ cls , values : Mapping [str , object ],
562+ ) -> Mapping [str , object ]:
563+ fecha_ultimo_vencimiento = values ['fecha_ultimo_vencimiento' ]
564+ dte_fecha_emision = values ['dte_fecha_emision' ]
565+
566+ if isinstance (fecha_ultimo_vencimiento , date ) and isinstance (dte_fecha_emision , date ):
567+ validate_cesion_fecha_ultimo_vencimiento_is_consistent_with_dte (
568+ cesion_value = fecha_ultimo_vencimiento , dte_value = dte_fecha_emision
569+ )
570+
571+ return values
572+
540573
541574@pydantic .dataclasses .dataclass (
542575 frozen = True ,
@@ -700,8 +733,6 @@ def as_dte_data_l2(self) -> dte_data_models.DteDataL2:
700733
701734 # TODO: Validate value of 'fecha_firma_dt' in relation to the DTE data.
702735
703- # TODO: Validate value of 'fecha_ultimo_vencimiento' in relation to the DTE data.
704-
705736 @pydantic .validator ('fecha_cesion_dt' )
706737 def validate_fecha_cesion_dt (cls , v : object ) -> object :
707738 if isinstance (v , datetime ):
@@ -745,3 +776,17 @@ def validate_dte_data_l2(cls, values: Mapping[str, Any]) -> Mapping[str, object]
745776 raise
746777
747778 return values
779+
780+ @pydantic .root_validator (skip_on_failure = True )
781+ def validate_fecha_ultimo_vencimiento_is_consistent_with_dte (
782+ cls , values : Mapping [str , object ],
783+ ) -> Mapping [str , object ]:
784+ fecha_ultimo_vencimiento = values ['fecha_ultimo_vencimiento' ]
785+ dte_fecha_emision = values ['dte_fecha_emision' ]
786+
787+ if isinstance (fecha_ultimo_vencimiento , date ) and isinstance (dte_fecha_emision , date ):
788+ validate_cesion_fecha_ultimo_vencimiento_is_consistent_with_dte (
789+ cesion_value = fecha_ultimo_vencimiento , dte_value = dte_fecha_emision
790+ )
791+
792+ return values
0 commit comments