Skip to content

Commit d41a7de

Browse files
Réforme dynamique : Corrige le problème de non création de conditions lorsqu'un profil est présent deux fois (#194)
1 parent cba7f14 commit d41a7de

File tree

9 files changed

+109
-5
lines changed

9 files changed

+109
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
# Changelog
2+
## [6.11.2] - 2023-12-06
3+
4+
_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)_
5+
6+
### Fixed
7+
8+
- 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
9+
210
## [6.11.1] - 2023-12-06
311

412
_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)_

openfisca_france_local/convert_benefit_conditions_to_parameters.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,38 @@ def conditions_to_node_data(conditions: 'list[dict]') -> dict:
105105

106106
def profils_to_node_data(profils: 'list[dict]'):
107107
def create_profils_field(data: dict, profil: dict):
108-
data['profils'].update({profil['type']: {}})
108+
if profil['type'] not in data['profils']:
109+
data['profils'].update({profil['type']: {}})
109110

110111
def add_profil_with_conditions(data: dict, profil: dict):
111-
data['profils'][profil['type']].update(conditions_to_node_data(profil['conditions']))
112+
def condition_already_exists_in_node(profil_condition, conditions_in_node_data) -> bool:
113+
conditions_with_operator_fields = ['age', 'quotient_familial', 'situation_handicap']
114+
115+
conditions_types = profil_condition.keys()
116+
117+
if len(conditions_types) == 0:
118+
return False
119+
120+
for type in conditions_types:
121+
if type in conditions_in_node_data:
122+
if type in conditions_with_operator_fields:
123+
operator = list(profil_condition[type])[0]
124+
return operator in conditions_in_node_data[type]
125+
else:
126+
return True
127+
128+
if 'conditions' not in data['profils'][profil['type']]:
129+
data['profils'][profil['type']] = {'conditions': {}}
130+
131+
profil_condition = data['profils'][profil['type']]['conditions']
132+
conditions_in_node_data = conditions_to_node_data(profil['conditions'])['conditions']
133+
134+
if condition_already_exists_in_node(profil_condition, conditions_in_node_data):
135+
raise NotImplementedError(
136+
'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'
137+
)
138+
139+
profil_condition.update(conditions_in_node_data)
112140

113141
def add_boolean_profil(data: dict, profil: dict):
114142
date = '2020-01-01'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name='OpenFisca-France-Local',
6-
version='6.11.1',
6+
version='6.11.2',
77
author='OpenFisca Team',
88
author_email='[email protected]',
99
classifiers=[
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
label: "Carte Génération - Apprentis : aide au transport"
2+
conditions_generales: []
3+
profils:
4+
- type: apprenti
5+
conditions:
6+
- type: age
7+
operator: <
8+
value: 26
9+
- type: apprenti
10+
conditions:
11+
- type: age
12+
operator: '>'
13+
value: 27
14+
type: float
15+
montant: 200
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
label: "Carte Génération - Apprentis : aide au transport"
2+
conditions_generales: []
3+
profils:
4+
- type: apprenti
5+
conditions:
6+
- type: age
7+
operator: <
8+
value: 26
9+
- type: apprenti
10+
conditions:
11+
- type: departements
12+
values:
13+
- "01"
14+
type: float
15+
montant: 200
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
label: "Carte Génération - Apprentis : aide au transport"
2+
conditions_generales: []
3+
profils:
4+
- type: apprenti
5+
conditions:
6+
- type: age
7+
operator: <
8+
value: 26
9+
- type: apprenti
10+
conditions:
11+
- type: boursier
12+
type: float
13+
montant: 200
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
label: "Carte Génération - Apprentis : aide au transport"
2+
conditions_generales: []
3+
profils:
4+
- type: apprenti
5+
conditions:
6+
- type: age
7+
operator: <
8+
value: 26
9+
- type: apprenti
10+
conditions:
11+
- type: age
12+
operator: <
13+
value: 27
14+
type: float
15+
montant: 200

tests/reforms/aides_jeunes/test_aides_jeunes_reform.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
@pytest.mark.parametrize("bogus_benefit_folder", [
88
'test_missing_condition_key',
99
'test_missing_profile_key',
10+
'test_2_same_type_profils_with_same_type_condition',
1011
])
1112
def test_bogus_benefit_structure(bogus_benefit_folder):
1213
with pytest.raises(NotImplementedError):

tests/reforms/aides_jeunes/test_aides_jeunes_reform.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@
261261
output:
262262
test_condition_attached_to_institution_communes: [16.8, 0]
263263

264-
265264
- period: 2022-11
266265
name: Condition attached_to_institution départements
267266
reforms:
@@ -271,7 +270,6 @@
271270
output:
272271
test_condition_attached_to_institution_departements: [17.8]
273272

274-
275273
- period: 2022-11
276274
name: Condition attached_to_institution epcis
277275
reforms:
@@ -290,3 +288,14 @@
290288
depcom: ['01100']
291289
output:
292290
test_condition_attached_to_institution_caf: [19]
291+
292+
- period: 2022-11
293+
name: Test fichier d'aide avec 2 profils de même type
294+
reforms:
295+
- openfisca_france_local.aides_jeunes_reform.aides_jeunes_reform_dynamic
296+
input:
297+
age: [20, 29]
298+
apprenti: [True, True]
299+
boursier: [False, True]
300+
output:
301+
test_multiple_profil_meme_type: [200, 200]

0 commit comments

Comments
 (0)