Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annexes financières: corrige le calcul du statut actif de la convention #4402

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion itou/companies/management/commands/_import_siae/vue_af.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,6 @@ def get_conventions_by_siae_key(vue_af_df):
end_at=timezone.make_aware(row.end_at).date(),
)
)
return {key: max(conventions, key=lambda i: i.end_at) for key, conventions in siae_conventions.items()}
return {
key: max(conventions, key=lambda i: (i.is_active, i.end_at)) for key, conventions in siae_conventions.items()
}
18 changes: 18 additions & 0 deletions tests/companies/test_import_siae_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)
from itou.companies.management.commands._import_siae.utils import anonymize_fluxiae_df, could_siae_be_deleted
from itou.companies.management.commands._import_siae.vue_af import (
Convention,
get_conventions_by_siae_key,
get_vue_af_df,
)
Expand Down Expand Up @@ -52,6 +53,23 @@ def setUp(self):
for file in files:
shutil.copy(file, self.tmp_path)

@freeze_time("2024-07-09")
def test_get_conventions_by_siae_key(self):
data = [
(1, "ACI", False, pd.Timestamp("2024-12-31 00:00")),
(1, "ACI", True, pd.Timestamp("2024-09-30 00:00")),
(2, "AI", False, pd.Timestamp("2024-08-31 00:00")),
(2, "AI", False, pd.Timestamp("2024-07-31 00:00")),
(3, "AI", False, pd.Timestamp("2024-07-31 00:00")),
]
# This is missing a bunch of columns, but only those are relevant for get_conventions_by_siae_key
vue_af_df_simplified = pd.DataFrame(data, columns=["asp_id", "kind", "has_active_state", "end_at"])
assert get_conventions_by_siae_key(vue_af_df_simplified) == {
(1, "ACI"): Convention(True, datetime.date(2024, 9, 30)),
(2, "AI"): Convention(False, datetime.date(2024, 8, 31)),
(3, "AI"): Convention(False, datetime.date(2024, 7, 31)),
}

def test_uncreatable_conventions_for_active_siae_with_active_convention(self):
siret_to_siae_row = get_siret_to_siae_row(get_vue_structure_df())
conventions_by_siae_key = get_conventions_by_siae_key(get_vue_af_df())
Expand Down