diff --git a/openfisca_france_local/convert_benefit_conditions_to_parameters.py b/openfisca_france_local/convert_benefit_conditions_to_parameters.py index 91cf821c..b01b44b3 100644 --- a/openfisca_france_local/convert_benefit_conditions_to_parameters.py +++ b/openfisca_france_local/convert_benefit_conditions_to_parameters.py @@ -109,15 +109,28 @@ def create_profils_field(data: dict, profil: dict): data['profils'].update({profil['type']: {}}) def add_profil_with_conditions(data: dict, profil: dict): + def condition_already_exists_in_node(profil_condition, conditions_in_node_data) -> bool: + conditions_with_operator_fields = ['age', 'quotient_familial', 'situation_handicap'] + + for condition_type in profil_condition.keys(): + if condition_type in conditions_in_node_data: + if condition_type in conditions_with_operator_fields: + operator = list(profil_condition[condition_type])[0] + return operator in conditions_in_node_data[condition_type] + else: + return True + return False + 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'] - for type in profil_condition.keys(): - if type in conditions_in_node_data: - raise NotImplementedError('Une aide avec deux profils de même type ne peux pas avoir de conditions de même type pour chacun de ses profils') + 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) 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