diff --git a/functests/toulouse_maelis/conftest.py b/functests/toulouse_maelis/conftest.py index b776030d..f89f3b97 100644 --- a/functests/toulouse_maelis/conftest.py +++ b/functests/toulouse_maelis/conftest.py @@ -322,6 +322,7 @@ def remove_id_on_child(conn, child): del child['indicators'] # order may change child['subscribeSchoolList'] = [] # not managed by test yet child['subscribeActivityList'] = [] # not managed by test yet + del child['subscribe_natures'] # order may change def remove_id_on_rlg(conn, rlg): @@ -332,6 +333,8 @@ def remove_id_on_rlg(conn, rlg): rlg['indicatorList'].sort(key=lambda x: x['code']) rlg['quotientList'].sort(key=lambda x: (x['yearRev'], x['dateStart'])) del rlg['indicators'] # order may change + rlg['subscribeActivityList'] = [] # not managed by test yet + del rlg['subscribe_natures'] # order may change def remove_id_on_family(conn, family): diff --git a/passerelle/contrib/toulouse_maelis/models.py b/passerelle/contrib/toulouse_maelis/models.py index 30a0f77d..b84ad586 100644 --- a/passerelle/contrib/toulouse_maelis/models.py +++ b/passerelle/contrib/toulouse_maelis/models.py @@ -343,6 +343,25 @@ class ToulouseMaelis(BaseResource, HTTPResource): result[item['id']] = item data['indicators'] = result + def add_nature_subsciptions(self, data): + subscribe_natures = {} + for item in data['subscribeActivityList'] or []: + activity_type = item.get('typeActivity') + activity_nature = activity_type.get('natureSpec') if activity_type else None + if not activity_nature: + continue + for unit in item['subscribesUnit']: + start_year = utils.get_reference_year_from_date(unit.get('dateStart')) + end_year = utils.get_reference_year_from_date(unit.get('dateEnd')) + if not start_year or not end_year: + continue + for year in range(start_year, end_year + 1): + school_year = '%s-%s' % (year, year + 1) + if not subscribe_natures.get(school_year): + subscribe_natures[school_year] = set() + subscribe_natures[school_year].add(activity_nature['code']) + data['subscribe_natures'] = {x: sorted(list(y)) for x, y in subscribe_natures.items()} + def add_text_value_to_rl_indicator(self, data): self.add_text_value('RLIndicator', data, ['code']) @@ -363,6 +382,7 @@ class ToulouseMaelis(BaseResource, HTTPResource): for indicator in data['indicatorList']: self.add_text_value_to_child_indicator(indicator) self.add_indicators_field('ChildIndicator', data) + self.add_nature_subsciptions(data) def add_text_value_to_person(self, data): self.add_text_value('Civility', data, ['civility']) @@ -382,6 +402,7 @@ class ToulouseMaelis(BaseResource, HTTPResource): for quotient in data['quotientList']: self.add_text_value('Quotient', quotient, ['cdquo']) self.add_indicators_field('RLIndicator', data) + self.add_nature_subsciptions(data) def add_text_value_to_family(self, data): self.add_text_value('Category', data, ['category']) diff --git a/tests/data/toulouse_maelis/R_read_family.xml b/tests/data/toulouse_maelis/R_read_family.xml index 2dc17ad8..f354cf6a 100644 --- a/tests/data/toulouse_maelis/R_read_family.xml +++ b/tests/data/toulouse_maelis/R_read_family.xml @@ -238,7 +238,7 @@ RESTAURATION SCOLAIRE 22/23 true 2023-03-01T00:00:00+01:00 - 2023-07-07T00:00:00+02:00 + 2023-09-01T00:00:00+02:00 DUPONT PIERRE ELEMENTAIRE 0010011 diff --git a/tests/data/toulouse_maelis/R_read_family_relax.xml b/tests/data/toulouse_maelis/R_read_family_relax.xml index eb547e23..29f7351e 100644 --- a/tests/data/toulouse_maelis/R_read_family_relax.xml +++ b/tests/data/toulouse_maelis/R_read_family_relax.xml @@ -237,7 +237,7 @@ RESTAURATION SCOLAIRE 22/23 true 2023-03-01T00:00:00+01:00 - 2023-07-07T00:00:00+02:00 + 2023-09-01T00:00:00+02:00 DUPONT PIERRE ELEMENTAIRE 0010011 diff --git a/tests/data/toulouse_maelis/R_read_family_reordered.xml b/tests/data/toulouse_maelis/R_read_family_reordered.xml index cd000e86..6d7e471a 100644 --- a/tests/data/toulouse_maelis/R_read_family_reordered.xml +++ b/tests/data/toulouse_maelis/R_read_family_reordered.xml @@ -238,7 +238,7 @@ RESTAURATION SCOLAIRE 22/23 true 2023-03-01T00:00:00+01:00 - 2023-07-07T00:00:00+02:00 + 2023-09-01T00:00:00+02:00 DUPONT PIERRE ELEMENTAIRE 0010011 diff --git a/tests/test_toulouse_maelis.py b/tests/test_toulouse_maelis.py index 1c1aa98c..2249bcf7 100644 --- a/tests/test_toulouse_maelis.py +++ b/tests/test_toulouse_maelis.py @@ -1321,6 +1321,7 @@ def test_read_family(family_service, xml, con, app): }, ], 'subscribeActivityList': [], + 'subscribe_natures': {}, } assert sorted(resp.json['data']['RL1']['indicatorList'], key=lambda x: x['code']) == [ { @@ -1380,6 +1381,7 @@ def test_read_family(family_service, xml, con, app): del data['indicatorList'] del data['indicators'] del data['subscribeActivityList'] + del data['subscribe_natures'] assert data == { 'num': '613880', 'lastname': 'DOE', @@ -1519,13 +1521,20 @@ def test_read_family(family_service, xml, con, app): 'note': None, }, ] - assert [x['libelle'] for x in resp.json['data']['childList'][0]['subscribeActivityList']] == [ - 'RESTAURATION SCOLAIRE 22/23', - 'CLAE MIDI 22/23', - 'CLAE MATIN 22/23', - 'SEMST2 ADL MERC. ELEM Maourine 22/23', - 'ECOLE DES SPORTS 22/23 SEMESTRE 2 - MULTIACTIVITES', + assert [ + (x['typeActivity']['natureSpec']['code'], x['libelle']) + for x in resp.json['data']['childList'][0]['subscribeActivityList'] + ] == [ + ('R', 'RESTAURATION SCOLAIRE 22/23'), + ('A', 'CLAE MIDI 22/23'), + ('A', 'CLAE MATIN 22/23'), + ('X', 'SEMST2 ADL MERC. ELEM Maourine 22/23'), + ('8', 'ECOLE DES SPORTS 22/23 SEMESTRE 2 - MULTIACTIVITES'), ] + assert resp.json['data']['childList'][0]['subscribe_natures'] == { + '2022-2023': ['8', 'A', 'R', 'X'], + '2023-2024': ['R'], + } def test_read_family_not_linked_error(con, app): @@ -1718,6 +1727,7 @@ def test_read_rl2(family_service, con, app): 'typeActivity': None, } ], + 'subscribe_natures': {}, }