diff --git a/CHANGELOG.md b/CHANGELOG.md index fbd6b7ae..f163972a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ # Changelog +## [6.11.2] - 2023-12-06 + +_Pour les changements détaillés et les discussions associées, référencez la pull request [#194](https://github.com/openfisca/openfisca-france-local/pull/194)_ + +### Fixed + +- Corrige le problème de la réforme dynamique qui ne crée qu'une condition lorsqu'un profil est présent plus d'une fois + ## [6.11.1] - 2023-12-06 _Pour les changements détaillés et les discussions associées, référencez la pull request [#196](https://github.com/openfisca/openfisca-france-local/pull/196)_ diff --git a/openfisca_france_local/convert_benefit_conditions_to_parameters.py b/openfisca_france_local/convert_benefit_conditions_to_parameters.py index 7a4e25a4..d2ec6f23 100644 --- a/openfisca_france_local/convert_benefit_conditions_to_parameters.py +++ b/openfisca_france_local/convert_benefit_conditions_to_parameters.py @@ -105,10 +105,38 @@ def conditions_to_node_data(conditions: 'list[dict]') -> dict: def profils_to_node_data(profils: 'list[dict]'): def create_profils_field(data: dict, profil: dict): - data['profils'].update({profil['type']: {}}) + if profil['type'] not in data['profils']: + data['profils'].update({profil['type']: {}}) def add_profil_with_conditions(data: dict, profil: dict): - data['profils'][profil['type']].update(conditions_to_node_data(profil['conditions'])) + def condition_already_exists_in_node(profil_condition, conditions_in_node_data) -> bool: + conditions_with_operator_fields = ['age', 'quotient_familial', 'situation_handicap'] + + conditions_types = profil_condition.keys() + + if len(conditions_types) == 0: + return False + + for type in conditions_types: + if type in conditions_in_node_data: + if type in conditions_with_operator_fields: + operator = list(profil_condition[type])[0] + return operator in conditions_in_node_data[type] + else: + return True + + if 'conditions' not in data['profils'][profil['type']]: + data['profils'][profil['type']] = {'conditions': {}} + + profil_condition = data['profils'][profil['type']]['conditions'] + conditions_in_node_data = conditions_to_node_data(profil['conditions'])['conditions'] + + if condition_already_exists_in_node(profil_condition, conditions_in_node_data): + raise NotImplementedError( + 'La réforme dynamique ne gère pas encore les aides avec deux profils de même type qui ont des conditions de même type pour chacun de ses profils identiques' + ) + + profil_condition.update(conditions_in_node_data) def add_boolean_profil(data: dict, profil: dict): date = '2020-01-01' diff --git a/setup.py b/setup.py index 688d8982..e28ad652 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='OpenFisca-France-Local', - version='6.11.1', + version='6.11.2', author='OpenFisca Team', author_email='contact@openfisca.fr', classifiers=[ diff --git a/test_data/benefits/test_2_same_type_profils with_same_type_condition_different_operator.yml b/test_data/benefits/test_2_same_type_profils with_same_type_condition_different_operator.yml new file mode 100644 index 00000000..bd0b23ff --- /dev/null +++ b/test_data/benefits/test_2_same_type_profils with_same_type_condition_different_operator.yml @@ -0,0 +1,15 @@ +label: "Carte Génération - Apprentis : aide au transport" +conditions_generales: [] +profils: + - type: apprenti + conditions: + - type: age + operator: < + value: 26 + - type: apprenti + conditions: + - type: age + operator: '>' + value: 27 +type: float +montant: 200 diff --git a/test_data/benefits/test_double_profile_meme_type.yml b/test_data/benefits/test_double_profile_meme_type.yml new file mode 100644 index 00000000..5ebc6346 --- /dev/null +++ b/test_data/benefits/test_double_profile_meme_type.yml @@ -0,0 +1,15 @@ +label: "Carte Génération - Apprentis : aide au transport" +conditions_generales: [] +profils: + - type: apprenti + conditions: + - type: age + operator: < + value: 26 + - type: apprenti + conditions: + - type: departements + values: + - "01" +type: float +montant: 200 diff --git a/test_data/benefits/test_multiple_profil_meme_type.yaml b/test_data/benefits/test_multiple_profil_meme_type.yaml new file mode 100644 index 00000000..ce934d03 --- /dev/null +++ b/test_data/benefits/test_multiple_profil_meme_type.yaml @@ -0,0 +1,13 @@ +label: "Carte Génération - Apprentis : aide au transport" +conditions_generales: [] +profils: + - type: apprenti + conditions: + - type: age + operator: < + value: 26 + - type: apprenti + conditions: + - type: boursier +type: float +montant: 200 diff --git a/test_data/bogus_benefits/test_2_same_type_profils_with_same_type_condition/benefit.yml b/test_data/bogus_benefits/test_2_same_type_profils_with_same_type_condition/benefit.yml new file mode 100644 index 00000000..2124093b --- /dev/null +++ b/test_data/bogus_benefits/test_2_same_type_profils_with_same_type_condition/benefit.yml @@ -0,0 +1,15 @@ +label: "Carte Génération - Apprentis : aide au transport" +conditions_generales: [] +profils: + - type: apprenti + conditions: + - type: age + operator: < + value: 26 + - type: apprenti + conditions: + - type: age + operator: < + value: 27 +type: float +montant: 200 diff --git a/tests/reforms/aides_jeunes/test_aides_jeunes_reform.py b/tests/reforms/aides_jeunes/test_aides_jeunes_reform.py index f776a43d..ad59fc83 100644 --- a/tests/reforms/aides_jeunes/test_aides_jeunes_reform.py +++ b/tests/reforms/aides_jeunes/test_aides_jeunes_reform.py @@ -7,6 +7,7 @@ @pytest.mark.parametrize("bogus_benefit_folder", [ 'test_missing_condition_key', 'test_missing_profile_key', + 'test_2_same_type_profils_with_same_type_condition', ]) def test_bogus_benefit_structure(bogus_benefit_folder): with pytest.raises(NotImplementedError): diff --git a/tests/reforms/aides_jeunes/test_aides_jeunes_reform.yaml b/tests/reforms/aides_jeunes/test_aides_jeunes_reform.yaml index b2139bf6..4c84d1df 100644 --- a/tests/reforms/aides_jeunes/test_aides_jeunes_reform.yaml +++ b/tests/reforms/aides_jeunes/test_aides_jeunes_reform.yaml @@ -261,7 +261,6 @@ output: test_condition_attached_to_institution_communes: [16.8, 0] - - period: 2022-11 name: Condition attached_to_institution départements reforms: @@ -271,7 +270,6 @@ output: test_condition_attached_to_institution_departements: [17.8] - - period: 2022-11 name: Condition attached_to_institution epcis reforms: @@ -290,3 +288,14 @@ depcom: ['01100'] output: test_condition_attached_to_institution_caf: [19] + +- period: 2022-11 + name: Test fichier d'aide avec 2 profils de même type + reforms: + - openfisca_france_local.aides_jeunes_reform.aides_jeunes_reform_dynamic + input: + age: [20, 29] + apprenti: [True, True] + boursier: [False, True] + output: + test_multiple_profil_meme_type: [200, 200]