Skip to content

Commit

Permalink
import_siae: prefer active conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
xavfernandez committed Jul 9, 2024
1 parent 4689fb1 commit 5a40d8d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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()
}
17 changes: 17 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,22 @@ def setUp(self):
for file in files:
shutil.copy(file, self.tmp_path)

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

0 comments on commit 5a40d8d

Please sign in to comment.