Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benjello committed Dec 13, 2024
1 parent fa65f6d commit b767265
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
description: Age légal de de départ à la retraite pour certains enseignants du supérieur
description: Age de départ à la retraite pour certains enseignants du supérieur
values:
1959-02-01:
value: 60
2019-04-01:
value: 65
metadata:
unit: year
documentation: |-
Loi n° 2009-20 du 13 avril 2009, portant dispositions exceptionnelles relatives à la retraite des professeurs de l’enseignement supérieur
Les enseignants concernés sont:
- les professeurs de l’enseignement supérieur et les maîtres de conférences de l’enseignement supérieur aux établissements universitaires et aux établissements de recherche scientifique civils et militaires,
- les professeurs de l’enseignement supérieur et les maîtres de conférences de l’enseignement supérieur rattachés aux établissements universitaires et aux établissements de recherche scientifique civils et militaires
- les professeurs hospitalo-universitaires et les maîtres de conférences agrégés hospitalo-universitaires
Néanmoins, ils peuvent être maintenus en activité par décret jusqu’à l’âge de soixante-dix (70) ans au maximum.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
description: Âge de départ à la retraite dans le service public civil
metadata:
short_label: Âge de départ des civils
order:
- cadre_commun
- cadre_actifs
- ensegnants_du_superieur
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: Âge de départ à la retraite
metadata:
short_label: Âge de départ
order:
- civil
- militaire
11 changes: 10 additions & 1 deletion openfisca_tunisia_pension/parameters/retraite/rsna/index.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
description: Régime des salariés non agricoles
description: Régime des salariés non agricoles (RSNA)
metadata:
short_label: RSNA
order:
- age_legal
- age_dep_anticipe
- stage_requis
- stage_derog
- bareme_annuite
- pension_minimale
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ values:
1974-01-01:
value: 0.5
metadata:
unit: Smig
unit: smig
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ values:
1974-01-01:
value: 0.66666
metadata:
unit: Smig
unit: smig
99 changes: 51 additions & 48 deletions openfisca_tunisia_pension/regimes/cnrps.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,49 @@ class RegimeCNRPS(AbstractRegimeEnAnnuites):
variable_prefix = 'cnrps'
parameters_prefix = 'cnrps'

class eligible(Variable):
value_type = bool
entity = Individu
label = "L'individu est éligible à une pension CNRPS"
definition_period = YEAR

def formula(individu, period, parameters):
duree_assurance = individu('regime_name_duree_assurance', period = period)
salaire_de_reference = individu('regime_name_salaire_de_reference', period = period)
age = individu('age', period = period)
cnrps = parameters(period).retraite.regime_name
duree_de_service_minimale_accomplie = duree_assurance > 4 * cnrps.duree_de_service_minimale
critere_age_verifie = age >= cnrps.age_legal.civil.cadre_commun
return duree_de_service_minimale_accomplie * critere_age_verifie * (salaire_de_reference > 0)

class pension_minimale(Variable):
value_type = float
default_value = 0 # Pas de pension minimale par défaut, elle est à zéro
entity = Individu
definition_period = YEAR
label = 'Pension minimale'

def formula(individu, period, parameters):
cnrps = parameters(period).retraite.regime_name
pension_minimale = cnrps.pension_minimale
duree_de_service_minimale = cnrps.duree_de_service_minimale
# TODO Annualiser le Smig
smig_annuel = 12 * parameters(period).marche_travail.smig_40h_mensuel
duree_assurance = individu('regime_name_duree_assurance', period)
return apply_thresholds(
duree_assurance / 4,
[
pension_minimale.duree_service_allocation_vieillesse,
duree_de_service_minimale,
],
[
0,
pension_minimale.allocation_vieillesse * smig_annuel,
pension_minimale.minimum_garanti * smig_annuel,
]

)

class salaire_de_reference_calcule_sur_demande(Variable):
value_type = bool
entity = Individu
Expand All @@ -79,11 +122,11 @@ def formula(individu, period):
moyenne_2_salaires_plus_eleves = apply_along_axis(
mean_over_largest,
axis = 0,
arr = vstack([individu('regime_name_salaire_de_base', period = year) for year in range(period.start.year, period.start.year - n, -1)]),
arr = vstack([individu('regime_name_salaire_de_base', period = year, options = [ADD]) for year in range(period.start.year, period.start.year - n, -1)]),
)
p = 3
moyenne_3_derniers_salaires = sum(
individu('regime_name_salaire_de_base', period = year)
individu('regime_name_salaire_de_base', period = year, options = [ADD])
for year in range(period.start.year, period.start.year - p, -1)
) / p

Expand All @@ -94,55 +137,15 @@ def formula(individu, period):
)
return salaire_refererence

# class pension_maximale(Variable):
# value_type = float
# default_value = np.inf # Pas de pension maximale par défaut
# entity = Individu
# definition_period = YEAR
# label = 'Pension maximale'

# def formula(individu, period, parameters):
# NotImplementedError

class pension_minimale(Variable):
class bonifications(Variable):
value_type = float
default_value = 0 # Pas de pension minimale par défaut, elle est à zéro
entity = Individu
label = 'Bonifications'
definition_period = YEAR
label = 'Pension minimale'

def formula(individu, period, parameters):
cnrps = parameters(period).retraite.regime_name
pension_minimale = cnrps.pension_minimale
duree_de_service_minimale = cnrps.duree_de_service_minimale
# TODO Annualiser le Smig
smig_annuel = 12 * parameters(period).marche_travail.smig_40h_mensuel
duree_assurance = individu('regime_name_duree_assurance', period)
return apply_thresholds(
duree_assurance / 4,
[
pension_minimale.duree_service_allocation_vieillesse,
duree_de_service_minimale,
],
[
0,
pension_minimale.allocation_vieillesse * smig_annuel,
pension_minimale.minimum_garanti * smig_annuel,
]
def formula(individu, period):

return (
individu('bonfication_retraite_pour_limite_d_age', period),
+ individu('bonfication_retraite_avant_age_legal', period)
)

class eligible(Variable):
value_type = bool
entity = Individu
label = "L'individu est éligible à une pension CNRPS"
definition_period = YEAR

def formula(individu, period, parameters):
duree_assurance = individu('regime_name_duree_assurance', period = period)
salaire_de_reference = individu('regime_name_salaire_de_reference', period = period)
age = individu('age', period = period)
cnrps = parameters(period).retraite.regime_name
duree_de_service_minimale_accomplie = duree_assurance > 4 * cnrps.duree_de_service_minimale
critere_age_verifie = age >= cnrps.age_legal.civil.cadre_commun
return duree_de_service_minimale_accomplie * critere_age_verifie * (salaire_de_reference > 0)
2 changes: 1 addition & 1 deletion openfisca_tunisia_pension/regimes/regime.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def formula(individu, period, parameters):
class salaire_de_base(Variable):
value_type = float
entity = Individu
definition_period = YEAR
definition_period = MONTH
label = 'Salaire de base (salaire brut)'
set_input = set_input_divide_by_period

Expand Down
2 changes: 1 addition & 1 deletion openfisca_tunisia_pension/regimes/rsna.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def formula(individu, period):
mean_over_largest,
axis = 0,
arr = vstack([
individu('regime_name_salaire_de_base', period = year)
individu('regime_name_salaire_de_base', period = year, options = [ADD])
for year in range(period.start.year, period.start.year - n, -1)
]),
)
Expand Down
15 changes: 12 additions & 3 deletions openfisca_tunisia_pension/variables/cnrps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
from numpy import apply_along_axis, vstack
from openfisca_tunisia_pension.tools import make_mean_over_consecutive_largest

class cnrps_bonifications(Variable):
value_type = float
entity = Individu
label = 'Bonifications'
definition_period = YEAR

def formula(individu, period):
return (individu('bonfication_retraite_pour_limite_d_age', period), +individu('bonfication_retraite_avant_age_legal', period))

class cnrps_cotisation(Variable):
value_type = float
entity = Individu
Expand Down Expand Up @@ -136,7 +145,7 @@ def formula(individu, period, parameters):
class cnrps_salaire_de_base(Variable):
value_type = float
entity = Individu
definition_period = YEAR
definition_period = MONTH
label = 'Salaire de base (salaire brut)'
set_input = set_input_divide_by_period

Expand All @@ -151,9 +160,9 @@ def formula(individu, period):
n = 40
k = 2
mean_over_largest = make_mean_over_consecutive_largest(k)
moyenne_2_salaires_plus_eleves = apply_along_axis(mean_over_largest, axis=0, arr=vstack([individu('cnrps_salaire_de_base', period=year) for year in range(period.start.year, period.start.year - n, -1)]))
moyenne_2_salaires_plus_eleves = apply_along_axis(mean_over_largest, axis=0, arr=vstack([individu('cnrps_salaire_de_base', period=year, options=[ADD]) for year in range(period.start.year, period.start.year - n, -1)]))
p = 3
moyenne_3_derniers_salaires = sum((individu('cnrps_salaire_de_base', period=year) for year in range(period.start.year, period.start.year - p, -1))) / p
moyenne_3_derniers_salaires = sum((individu('cnrps_salaire_de_base', period=year, options=[ADD]) for year in range(period.start.year, period.start.year - p, -1))) / p
salaire_refererence = where(individu('cnrps_salaire_de_reference_calcule_sur_demande', period), moyenne_2_salaires_plus_eleves, moyenne_3_derniers_salaires)
return salaire_refererence

Expand Down
2 changes: 1 addition & 1 deletion openfisca_tunisia_pension/variables/rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def formula(individu, period, parameters):
class rsa_salaire_de_base(Variable):
value_type = float
entity = Individu
definition_period = YEAR
definition_period = MONTH
label = 'Salaire de base (salaire brut)'
set_input = set_input_divide_by_period

Expand Down
4 changes: 2 additions & 2 deletions openfisca_tunisia_pension/variables/rsna.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def formula(individu, period, parameters):
class rsna_salaire_de_base(Variable):
value_type = float
entity = Individu
definition_period = YEAR
definition_period = MONTH
label = 'Salaire de base (salaire brut)'
set_input = set_input_divide_by_period

Expand All @@ -157,7 +157,7 @@ def formula(individu, period):
k = 10
mean_over_largest = make_mean_over_largest(k=k)
n = 40
salaire_refererence = apply_along_axis(mean_over_largest, axis=0, arr=vstack([individu('rsna_salaire_de_base', period=year) for year in range(period.start.year, period.start.year - n, -1)]))
salaire_refererence = apply_along_axis(mean_over_largest, axis=0, arr=vstack([individu('rsna_salaire_de_base', period=year, options=[ADD]) for year in range(period.start.year, period.start.year - n, -1)]))
return salaire_refererence

class rsna_taux_de_liquidation(Variable):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ requires-python = ">= 3.9"
dependencies = [
"numba>=0.54,<1.0.0",
'numpy >=1.24.3, <2',
'openfisca-core[web-api] >=41.5.0, <41.5.3',
'openfisca-core[web-api] >=43.0.0, <44.0.0',
'scipy >= 0.12',
]

Expand Down

0 comments on commit b767265

Please sign in to comment.