Skip to content

Commit

Permalink
Réforme dynamique : Corrige le problème de non création de conditions…
Browse files Browse the repository at this point in the history
… lorsqu'un profil est présent deux fois (#194)
  • Loading branch information
Allan-CodeWorks authored Dec 6, 2023
1 parent cba7f14 commit d41a7de
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)_
Expand Down
32 changes: 30 additions & 2 deletions openfisca_france_local/convert_benefit_conditions_to_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='OpenFisca-France-Local',
version='6.11.1',
version='6.11.2',
author='OpenFisca Team',
author_email='[email protected]',
classifiers=[
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
15 changes: 15 additions & 0 deletions test_data/benefits/test_double_profile_meme_type.yml
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: departements
values:
- "01"
type: float
montant: 200
13 changes: 13 additions & 0 deletions test_data/benefits/test_multiple_profil_meme_type.yaml
Original file line number Diff line number Diff line change
@@ -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
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
1 change: 1 addition & 0 deletions tests/reforms/aides_jeunes/test_aides_jeunes_reform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 11 additions & 2 deletions tests/reforms/aides_jeunes/test_aides_jeunes_reform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -271,7 +270,6 @@
output:
test_condition_attached_to_institution_departements: [17.8]


- period: 2022-11
name: Condition attached_to_institution epcis
reforms:
Expand All @@ -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]

0 comments on commit d41a7de

Please sign in to comment.