Skip to content

Commit

Permalink
Ajoute une abstraction sur la vérification des types de conditions id…
Browse files Browse the repository at this point in the history
…entiques pour les aides avec profiles identiques
  • Loading branch information
Allan-CodeWorks committed Dec 6, 2023
1 parent 84d4193 commit 761a411
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
19 changes: 16 additions & 3 deletions openfisca_france_local/convert_benefit_conditions_to_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 761a411

Please sign in to comment.