Skip to content

Commit

Permalink
Fix SelectedAdministrativeCriteria.certification_period
Browse files Browse the repository at this point in the history
The API particulier computed the dateFin with dateDebut + 3 months.
That’s very misleading, as a person who has been a beneficiary since
2009-06-01 would have:
```json
{
    "statut": "beneficiaire",
    "dateDebut": "2009-06-01",
    "dateFin": "2009-09-01",
}
```

However, the `statut` means the person is beneficiary **today**.

The API recently evolved to always set `dateFin` to `null` to avoid
suggesting the end date is known and in the past.

Fix about 11,000 incorrect records, by using `certified_at`: if the API
response for `statut` was "beneficiaire", that person was beneficiary on
the day the API was queried.

The example from above comes from the production environment and is an
example of bad data.
  • Loading branch information
francoisfreitag committed Jan 6, 2025
1 parent 5ac6c50 commit 7200868
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import datetime

from django.db import migrations
from django.utils import timezone

from itou.utils.types import InclusiveDateRange


def set_certification_period_end_date(apps, editor):
SelectedAdministrativeCriteria = apps.get_model("eligibility", "SelectedAdministrativeCriteria")
crits = []
for crit in SelectedAdministrativeCriteria.objects.exclude(certification_period=None):
crit.certification_period = InclusiveDateRange(
crit.certification_period.lower,
timezone.localdate(crit.certified_at) + datetime.timedelta(days=92),
)
crits.append(crit)
updated_objs = SelectedAdministrativeCriteria.objects.bulk_update(crits, fields=["certification_period"])
print(f"Updated {updated_objs} selected administrative criteria.")


class Migration(migrations.Migration):
dependencies = [
("eligibility", "0008_alter_eligibilitydiagnosis_expires_at_and_more"),
]

operations = [
migrations.RunPython(set_certification_period_end_date, elidable=True),
]

0 comments on commit 7200868

Please sign in to comment.