18
18
19
19
import typing as _t
20
20
if _t .TYPE_CHECKING :
21
+ from sedate .types import DateLike
21
22
from sqlalchemy .orm import Query
22
23
from typing_extensions import NotRequired , Self , TypeAlias , TypedDict
23
24
@@ -893,8 +894,8 @@ def remove_allocation(
893
894
894
895
def remove_unused_allocations (
895
896
self ,
896
- start : datetime ,
897
- end : datetime ,
897
+ start : 'DateLike' ,
898
+ end : 'DateLike' ,
898
899
days : _t .Optional [_t .Iterable [_t .Union ['Day' , 'DayNumber' ]]] = None ,
899
900
exclude_groups : bool = False
900
901
) -> int :
@@ -916,7 +917,7 @@ def remove_unused_allocations(
916
917
be excluded, regardless of what this parameter is set to.
917
918
"""
918
919
919
- start , end = self ._prepare_range (
920
+ start_dt , end_dt = self ._prepare_range (
920
921
sedate .as_datetime (start ),
921
922
sedate .as_datetime (end )
922
923
)
@@ -957,22 +958,22 @@ def remove_unused_allocations(
957
958
groups = groups .having (
958
959
and_ (
959
960
func .count (Allocation .id ) == 1 ,
960
- start <= func .min (Allocation ._start ),
961
- func .max (Allocation ._end ) <= end
961
+ start_dt <= func .min (Allocation ._start ),
962
+ func .max (Allocation ._end ) <= end_dt
962
963
)
963
964
)
964
965
else :
965
966
groups = groups .having (
966
967
and_ (
967
- start <= func .min (Allocation ._start ),
968
- func .max (Allocation ._end ) <= end
968
+ start_dt <= func .min (Allocation ._start ),
969
+ func .max (Allocation ._end ) <= end_dt
969
970
)
970
971
)
971
972
972
973
# all allocations
973
974
candidates = self .managed_allocations ()
974
- candidates = candidates .filter (start <= Allocation ._start )
975
- candidates = candidates .filter (Allocation ._end <= end )
975
+ candidates = candidates .filter (start_dt <= Allocation ._start )
976
+ candidates = candidates .filter (Allocation ._end <= end_dt )
976
977
977
978
# .. without the ones with slots
978
979
candidates = candidates .filter (not_ (Allocation .id .in_ (slots )))
0 commit comments