Skip to content

Commit

Permalink
improve logic of next_min_start
Browse files Browse the repository at this point in the history
  • Loading branch information
madjid-asa committed Dec 2, 2021
1 parent e668bc7 commit 7d998fb
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions itou/approvals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,19 +626,24 @@ def next_min_start_at(approval):
"""
Returns the minimum date on which a suspension can begin.
"""
# by default the next min start is the date of last hiring start of user
min_suspension_start_at = approval.user.last_accepted_job_application.hiring_start_at
today = datetime.date.today()

# We set the next min to the date of last old suspension if suspension exist
if approval.last_old_suspension:
min_suspension_start_at = approval.last_old_suspension.end_at + relativedelta(days=1)

# else we set the next min to the date of last accepted job from the pe approval
elif approval.user.last_accepted_job_application.created_from_pe_approval:
min_suspension_start_at = today

is_old_than_max_retroactivity = today - min_suspension_start_at > datetime.timedelta(
days=Suspension.MAX_RETROACTIVITY_DURATION_DAYS
)

return (
min_suspension_start_at
if today - min_suspension_start_at <= datetime.timedelta(days=Suspension.MAX_RETROACTIVITY_DURATION_DAYS)
else today - relativedelta(days=Suspension.MAX_RETROACTIVITY_DURATION_DAYS)
today - relativedelta(days=Suspension.MAX_RETROACTIVITY_DURATION_DAYS)
if is_old_than_max_retroactivity
else min_suspension_start_at
)


Expand Down

0 comments on commit 7d998fb

Please sign in to comment.