diff --git a/functests/toulouse_maelis/conftest.py b/functests/toulouse_maelis/conftest.py index 2caf7759..e50e4989 100644 --- a/functests/toulouse_maelis/conftest.py +++ b/functests/toulouse_maelis/conftest.py @@ -348,6 +348,7 @@ 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 + del rlg['quotients'] # order may change rlg['subscribeActivityList'] = [] # not managed by test yet del rlg['subscribe_natures'] # order may change diff --git a/passerelle/contrib/toulouse_maelis/models.py b/passerelle/contrib/toulouse_maelis/models.py index 395373f1..d981fb17 100644 --- a/passerelle/contrib/toulouse_maelis/models.py +++ b/passerelle/contrib/toulouse_maelis/models.py @@ -414,6 +414,18 @@ class ToulouseMaelis(BaseResource, HTTPResource): result[item['id']] = item data['indicators'] = result + def add_quotients_field(self, data): + quotients = {} + for item in data['quotientList']: + key = item['cdquo'] + if key not in quotients: + quotients[key] = [] + quotients[key].append(item) + data['quotients'] = { + x: sorted(y, key=lambda z: (z['yearRev'], z['dateStart'], z['dateEnd']), reverse=True) + for x, y in quotients.items() + } + def add_nature_subscriptions(self, data): subscribe_natures = {} for item in data['subscribeActivityList'] or []: @@ -483,6 +495,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_quotients_field(data) self.add_nature_subscriptions(data) self.add_text_value_to_birth(data) diff --git a/tests/data/toulouse_maelis/R_read_family.xml b/tests/data/toulouse_maelis/R_read_family.xml index 53b7d284..aca38831 100644 --- a/tests/data/toulouse_maelis/R_read_family.xml +++ b/tests/data/toulouse_maelis/R_read_family.xml @@ -54,6 +54,27 @@ 1500.33 QS + + 2021 + 2021-01-01T00:00:00+01:00 + 2021-01-01T00:00:00+01:00 + 300 + QS + + + 2021 + 2021-01-01T00:00:00+01:00 + 2021-01-02T00:00:00+01:00 + 200 + QS + + + 2021 + 2021-01-02T00:00:00+01:00 + 2021-01-02T00:00:00+01:00 + 100 + QS + 2021 2022-01-01T00:00:00+01:00 diff --git a/tests/data/toulouse_maelis/R_read_family_relax.xml b/tests/data/toulouse_maelis/R_read_family_relax.xml index 4098b4ce..16605ac2 100644 --- a/tests/data/toulouse_maelis/R_read_family_relax.xml +++ b/tests/data/toulouse_maelis/R_read_family_relax.xml @@ -54,6 +54,27 @@ 1500.33 QS + + 2021 + 2021-01-01T00:00:00+01:00 + 2021-01-01T00:00:00+01:00 + 300 + QS + + + 2021 + 2021-01-01T00:00:00+01:00 + 2021-01-02T00:00:00+01:00 + 200 + QS + + + 2021 + 2021-01-02T00:00:00+01:00 + 2021-01-02T00:00:00+01:00 + 100 + QS + 2021 2022-01-01T00:00:00+01:00 diff --git a/tests/data/toulouse_maelis/R_read_family_reordered.xml b/tests/data/toulouse_maelis/R_read_family_reordered.xml index 38864ff1..52ffa8a0 100644 --- a/tests/data/toulouse_maelis/R_read_family_reordered.xml +++ b/tests/data/toulouse_maelis/R_read_family_reordered.xml @@ -54,6 +54,27 @@ 1500.33 QS + + 2021 + 2021-01-01T00:00:00+01:00 + 2021-01-01T00:00:00+01:00 + 300 + QS + + + 2021 + 2021-01-01T00:00:00+01:00 + 2021-01-02T00:00:00+01:00 + 200 + QS + + + 2021 + 2021-01-02T00:00:00+01:00 + 2021-01-02T00:00:00+01:00 + 100 + QS + 2021 2022-01-01T00:00:00+01:00 diff --git a/tests/test_toulouse_maelis.py b/tests/test_toulouse_maelis.py index 9acfd7d2..7752f6d2 100644 --- a/tests/test_toulouse_maelis.py +++ b/tests/test_toulouse_maelis.py @@ -1386,6 +1386,8 @@ def test_read_family(family_service, xml, con, app): del data['profession'] del data['indicatorList'] del data['indicators'] + del data['quotientList'] + del data['quotients'] assert data == { 'num': '613878', 'lastname': 'DOE', @@ -1424,26 +1426,6 @@ def test_read_family(family_service, xml, con, app): 'CAFInfo': None, 'civility_text': 'Monsieur', 'quality_text': 'PERE', - 'quotientList': [ - { - 'cdquo': 'QS', - 'cdquo_text': 'QUOTIENT SCOLAIRE', - 'codeUti': None, - 'dateEnd': '2021-12-31T00:00:00+01:00', - 'dateStart': '2021-01-01T00:00:00+01:00', - 'mtt': 1500.33, - 'yearRev': 2020, - }, - { - 'cdquo': 'MOY ECO', - 'cdquo_text': 'REVENU MOYEN ( MENSUEL OU ANNUEL)', - 'codeUti': None, - 'dateEnd': '2022-12-31T00:00:00+01:00', - 'dateStart': '2022-01-01T00:00:00+01:00', - 'mtt': 1500.44, - 'yearRev': 2021, - }, - ], 'subscribeActivityList': [], 'subscribe_natures': {}, } @@ -1498,6 +1480,104 @@ def test_read_family(family_service, xml, con, app): 'typeDesc': 'NONE', }, } + assert resp.json['data']['RL1']['quotientList'] == [ + { + 'yearRev': 2020, + 'dateStart': '2021-01-01T00:00:00+01:00', + 'dateEnd': '2021-12-31T00:00:00+01:00', + 'mtt': 1500.33, + 'cdquo': 'QS', + 'codeUti': None, + 'cdquo_text': 'QUOTIENT SCOLAIRE', + }, + { + 'yearRev': 2021, + 'dateStart': '2021-01-01T00:00:00+01:00', + 'dateEnd': '2021-01-01T00:00:00+01:00', + 'mtt': 300.0, + 'cdquo': 'QS', + 'codeUti': None, + 'cdquo_text': 'QUOTIENT SCOLAIRE', + }, + { + 'yearRev': 2021, + 'dateStart': '2021-01-01T00:00:00+01:00', + 'dateEnd': '2021-01-02T00:00:00+01:00', + 'mtt': 200.0, + 'cdquo': 'QS', + 'codeUti': None, + 'cdquo_text': 'QUOTIENT SCOLAIRE', + }, + { + 'yearRev': 2021, + 'dateStart': '2021-01-02T00:00:00+01:00', + 'dateEnd': '2021-01-02T00:00:00+01:00', + 'mtt': 100.0, + 'cdquo': 'QS', + 'codeUti': None, + 'cdquo_text': 'QUOTIENT SCOLAIRE', + }, + { + 'yearRev': 2021, + 'dateStart': '2022-01-01T00:00:00+01:00', + 'dateEnd': '2022-12-31T00:00:00+01:00', + 'mtt': 1500.44, + 'cdquo': 'MOY ECO', + 'codeUti': None, + 'cdquo_text': 'REVENU MOYEN ( MENSUEL OU ANNUEL)', + }, + ] + assert resp.json['data']['RL1']['quotients'] == { + 'QS': [ + { + 'yearRev': 2021, + 'dateStart': '2021-01-02T00:00:00+01:00', + 'dateEnd': '2021-01-02T00:00:00+01:00', + 'mtt': 100.0, + 'cdquo': 'QS', + 'codeUti': None, + 'cdquo_text': 'QUOTIENT SCOLAIRE', + }, + { + 'yearRev': 2021, + 'dateStart': '2021-01-01T00:00:00+01:00', + 'dateEnd': '2021-01-02T00:00:00+01:00', + 'mtt': 200.0, + 'cdquo': 'QS', + 'codeUti': None, + 'cdquo_text': 'QUOTIENT SCOLAIRE', + }, + { + 'yearRev': 2021, + 'dateStart': '2021-01-01T00:00:00+01:00', + 'dateEnd': '2021-01-01T00:00:00+01:00', + 'mtt': 300.0, + 'cdquo': 'QS', + 'codeUti': None, + 'cdquo_text': 'QUOTIENT SCOLAIRE', + }, + { + 'yearRev': 2020, + 'dateStart': '2021-01-01T00:00:00+01:00', + 'dateEnd': '2021-12-31T00:00:00+01:00', + 'mtt': 1500.33, + 'cdquo': 'QS', + 'codeUti': None, + 'cdquo_text': 'QUOTIENT SCOLAIRE', + }, + ], + 'MOY ECO': [ + { + 'yearRev': 2021, + 'dateStart': '2022-01-01T00:00:00+01:00', + 'dateEnd': '2022-12-31T00:00:00+01:00', + 'mtt': 1500.44, + 'cdquo': 'MOY ECO', + 'codeUti': None, + 'cdquo_text': 'REVENU MOYEN ( MENSUEL OU ANNUEL)', + } + ], + } data = resp.json['data']['childList'][0] del data['medicalRecord'] del data['authorizedPersonList'] @@ -1723,6 +1803,9 @@ def test_read_rl1(family_service, con, app): assert resp.json['err'] == 0 assert resp.json['data']['firstname'] == 'JHON' + template = '{{ data.quotients.QS.0.mtt }} {{ data.quotients.QS.1.mtt }}' + assert render_to_string(template, resp.json) == '100.0 200.0' + def test_read_rl1_with_income_year(family_service, con, app): family_service.add_soap_response('readFamily', get_xml_file('R_read_family_with_income_year.xml')) @@ -1811,6 +1894,7 @@ def test_read_rl2(family_service, con, app): 'civility_text': 'Madame', 'quality_text': 'MERE', 'quotientList': [], + 'quotients': {}, 'indicatorList': [], 'indicators': { 'AVL': {