Skip to content

Commit

Permalink
fix(aah): msa_master fix aah conjugalise
Browse files Browse the repository at this point in the history
  • Loading branch information
robinguill committed Dec 6, 2024
1 parent 720ba21 commit 6d924a7
Show file tree
Hide file tree
Showing 26 changed files with 222 additions and 171 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -337,36 +337,6 @@ jobs:
path: /tmp/conda
retention-days: 30

test-on-windows:
runs-on: "windows-latest"
needs: [ build-conda ]
steps:
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: "3.9.9"
# Add conda-forge for OpenFisca-Core
channels: openfisca,conda-forge
activate-environment: true
- uses: actions/checkout@v3
- name: Test max path length
run: "python3 openfisca_france/scripts/check_path_length.py"
- name: Get version
run: |
# chcp 65001 #set code page to utf-8
echo ("PACKAGE_VERSION=" + (python3 ./setup.py --version) ) >> $env:GITHUB_ENV
echo "Version setup.py: ${{ env.PACKAGE_VERSION }}"
- name: Download conda build
uses: actions/download-artifact@v3
with:
name: conda-build-${{ env.PACKAGE_VERSION }}-${{ github.sha }}
path: conda-build-tmp
- name: Install with conda
run: |
conda install -c ./conda-build-tmp/noarch/openfisca-france-dev-${{ env.PACKAGE_VERSION }}-py_0.tar.bz2 openfisca-france-dev
- name: openfisca test
run: openfisca test --country-package openfisca_france tests

publish-to-conda:
runs-on: windows-latest
needs: [ deploy, test-on-windows ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4089,7 +4089,7 @@ def formula(foyer_fiscal, period, parameters):
class plus_values_gains_divers(Variable):
value_type = float
entity = FoyerFiscal
label = "Plus-values et gains divers"
label = 'Plus-values et gains divers'
definition_period = YEAR


Expand Down
9 changes: 5 additions & 4 deletions openfisca_france/model/prestations/aides_logement.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,21 +256,21 @@ class etat_logement(Variable):
class assistant_maternel(Variable):
value_type = bool
entity = Individu
label = "Assistant maternel"
label = 'Assistant maternel'
definition_period = MONTH


class assistant_familial(Variable):
value_type = bool
entity = Individu
label = "Assistant familial"
label = 'Assistant familial'
definition_period = MONTH


class journaliste(Variable):
value_type = bool
entity = Individu
label = "Journaliste"
label = 'Journaliste'
definition_period = MONTH


Expand Down Expand Up @@ -605,12 +605,13 @@ def formula_2021_01_01(individu, period, parameters):

abattement_frais_pro = where(frais_reels > abattement_forfaitaire, frais_reels, abattement_forfaitaire)

rpns = individu('rpns_imposables', period.n_2)
rpns_pvce = individu('rpns_pvce', period.n_2)
rpns_pvct = individu('rpns_pvct', period.n_2)
rpns_mvct = individu('moins_values_court_terme_non_salaries', period.n_2)
rpns_mvlt = individu('moins_values_long_terme_non_salaries', period.n_2)

rpns = rpns_pvce + rpns_pvct + rpns_mvct + rpns_mvlt
rpns = rpns + rpns_pvce + rpns_pvct + rpns_mvct + rpns_mvlt
# TO DO : compléter la formule pour prendre en compte la disposition particulière concernant les indépendants ayant commencé une activité entre N-2 et N.
# Non implémentée car diffile à comprendre ce qui est fait exactement

Expand Down
155 changes: 109 additions & 46 deletions openfisca_france/model/prestations/minima_sociaux/aah.py

Large diffs are not rendered by default.

75 changes: 37 additions & 38 deletions openfisca_france/model/prestations/minima_sociaux/cs/ressources.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from numpy import absolute as abs_, logical_and as and_, logical_or as or_, logical_not as not_, maximum as max_, select, where, sum as sum_
from numpy import absolute as abs_, logical_or as or_, logical_not as not_, select

from openfisca_core.periods import Period

from openfisca_france.model.base import (
Variable,
Individu,
Famille,
FoyerFiscal,
MONTH,
ADD,
max_,
Expand Down Expand Up @@ -34,16 +33,13 @@ class css_cmu_base_ressources_individu(Variable):
def formula(individu, period, parameters):
# Rolling year
previous_year = compute_previous_year(period).offset(-1, 'month')
previous_year = compute_previous_year(period)
# N-1
last_year = period.last_year
last_month = period.last_month

parametres_cmu = parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.cs.cmu
parametres_cmu = parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.cs.cmu

ressources_a_inclure = [
'css_base_ressources_aah_individu',
'allocation_securisation_professionnelle',
'ass',
'bourse_recherche',
Expand Down Expand Up @@ -88,10 +84,10 @@ def formula(individu, period, parameters):
+ revenus_tns(individu, previous_year, last_year)
- pensions_alim_versees
- abattement_chomage(individu, period, previous_year, parametres_cmu)
- abattement_chomage(individu, period, previous_year, parametres_cmu)
- neutralisation_stage_formation_pro(individu, previous_year, last_month)
)


class css_base_ressources_aah_individu(Variable):
value_type = float
label = "Base de ressources AAH de l'individu prise en compte pour l'éligibilité à la CSS après application de l'abattement"
Expand All @@ -100,69 +96,78 @@ class css_base_ressources_aah_individu(Variable):
'https://sante.gouv.fr/fichiers/bo/2021/2021.6.sante.pdf#page=75',
'Bulletin officiel Santé - Protection sociale - Solidarité n° 2023/24 du 29 décembre 2023 - Instruction interministérielle N° DSS/SD2A/2023/98 du 22 décembre 2023',
'https://sante.gouv.fr/fichiers/bo/2023/2023.24.sante.pdf#page=82',
]
]
entity = Individu
definition_period = MONTH
set_input = set_input_divide_by_period

def formula(individu, period, parameters):
return individu('aah', period)

def formula_2021_04_01(individu, period, parameters):
def formula_2021_04(individu, period, parameters):
return max_(individu('aah', period) - parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.cs.css.abattements.aah, 0)

class css_abattement_asi_individu(Variable):

class css_base_ressources_asi_individu(Variable):
value_type = float
label = "Base de ressources ASI de l'individu prise en compte pour l'éligibilité à la CSS après application de l'abattement"
reference = [
'Bulletin officiel Santé - Protection sociale - Solidarité n° 2021/6 du 16 avril 2021 - Instruction interministérielle N° DSS/SD2A/2021/71 du 30 mars 2021',
'https://sante.gouv.fr/fichiers/bo/2021/2021.6.sante.pdf#page=75'
]
]
entity = Individu
definition_period = MONTH
set_input = set_input_divide_by_period

def formula(individu, period, parameters):
return 0
return individu('asi', period)

def formula_2021_04_01(individu, period, parameters):
def formula_2021_04(individu, period, parameters):

abattement_asi_personne_seule = parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.cs.css.abattements.asi.personne_seule
abattement_asi_couple = parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.cs.css.abattements.asi.couple/2
adulte_ayant_asi = where(and_(
individu.has_role(FoyerFiscal.DECLARANT),
individu('asi', period)),
True, False)
appliquer_abattement_couple = sum_(adulte_ayant_asi) > 1
aah = individu('aah', period)
return select(
[aah > 0, appliquer_abattement_couple and adulte_ayant_asi, adulte_ayant_asi],
[0, abattement_asi_couple, abattement_asi_personne_seule],
asi = individu('asi', period)
asi_famille = individu.famille.members('asi', period)
nb_allocataire_asi = individu.famille.sum(asi_famille > 0, role=Famille.PARENT)

abattement_asi_personne_seule = parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.cs.css.abattements.asi.personne_seule
abattement_asi_couple = parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.cs.css.abattements.asi.couple

condition_abattement_asi_couple = nb_allocataire_asi > 1
condition_abattement_asi_personne_seule = asi > 0
abattement_asi = select(
[aah > 0, condition_abattement_asi_couple, condition_abattement_asi_personne_seule],
[0, abattement_asi_couple / 2, abattement_asi_personne_seule],
0)

montant_asi = asi - abattement_asi
return max_(montant_asi, 0)


class css_base_ressources_aspa_asv(Variable):
value_type = float
label = "Base de ressources ASPA/ASV de pour une famille prise en compte pour l'éligibilité à la CSS après application de l'abattement"
reference = [
'Bulletin officiel Santé - Protection sociale - Solidarité n° 2021/6 du 16 avril 2021 - Instruction interministérielle N° DSS/SD2A/2021/71 du 30 mars 2021',
'https://sante.gouv.fr/fichiers/bo/2021/2021.6.sante.pdf#page=75'
]
]
entity = Famille
definition_period = MONTH
set_input = set_input_divide_by_period

def formula(famille, period, parameters):
return famille('aspa', period)
def formula_2021_04_01(famille, period, parameters):

def formula_2021_04(famille, period, parameters):
aspa = famille('aspa', period)
aspa_couple = famille('aspa_couple', period)
abattement_aspa_personne_seule = parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.cs.css.abattements.aspa_asv.personne_seule
abattement_aspa_couple = parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.cs.css.abattements.aspa_asv.couple
return select(
[aspa > 0 and aspa_couple, aspa > 0],
[(aspa > 0) * aspa_couple, aspa > 0],
[max_(aspa - abattement_aspa_couple, 0), max_(aspa - abattement_aspa_personne_seule, 0)],
aspa)


class css_cmu_base_ressources(Variable):
value_type = float
label = "Base de ressources prise en compte pour l'éligibilité à la ACS / CMU-C / CSS"
Expand All @@ -171,13 +176,12 @@ class css_cmu_base_ressources(Variable):
set_input = set_input_divide_by_period

def formula(famille, period, parameters):
previous_year = compute_previous_year(period)
previous_year = compute_previous_year(period).offset(-1, 'month')

ressources_famille_a_inclure = [
'af',
'asf',
'css_base_ressources_aspa_asv',
'css_base_ressources_aspa_asv',
'cf',
'paje_clca',
'paje_prepare',
Expand All @@ -192,7 +196,6 @@ def formula(famille, period, parameters):
css_cmu_forfait_logement_base = famille('css_cmu_forfait_logement_base', period)
css_cmu_forfait_logement_al = famille('css_cmu_forfait_logement_al', period)

parametres_cmu = parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.cs.cmu
parametres_cmu = parameters(period).prestations_sociales.solidarite_insertion.minima_sociaux.cs.cmu

proprietaire = (statut_occupation_logement == TypesStatutOccupationLogement.proprietaire)
Expand All @@ -205,29 +208,26 @@ def formula(famille, period, parameters):
)

ressources_individuelles = famille.members('css_cmu_base_ressources_individu', period)
ressources_individuelles_asi = famille.members('asi', previous_year, options = [ADD])
abattements_asi_individuelles = famille.members('css_abattement_asi_individu', previous_year, options = [ADD])

ressources_asi_parents = max_(famille.sum(ressources_individuelles_asi, role = Famille.PARENT) - famille.sum(abattements_asi_individuelles), 0)
ressources_parents = famille.sum(ressources_individuelles, role = Famille.PARENT) + ressources_asi_parents
ressources_parents = famille.sum(ressources_individuelles, role = Famille.PARENT)

age = famille.members('age', period)
condition_enfant_a_charge = (age >= 0) * (age <= parametres_cmu.age_limite_pac)
ressources_asi_enfants = famille.sum(ressources_individuelles_asi * condition_enfant_a_charge, role = Famille.ENFANT)
ressources_enfants = famille.sum(ressources_individuelles * condition_enfant_a_charge, role = Famille.ENFANT) + ressources_asi_enfants
ressources_enfants = famille.sum(ressources_individuelles * condition_enfant_a_charge, role = Famille.ENFANT)

return forfait_logement + ressources_famille + ressources_parents + ressources_enfants

# Helper functions

def compute_previous_year(period):
return Period(('year', period.start, 1)).offset(-1).offset(-1, 'month')

def compute_previous_year(period):
return Period(('year', period.start, 1)).offset(-1)
# Abattement sur revenus d'activité si :
# - IJ maladie
# - chômage
# - ass
# - formation professionnelle


def abattement_chomage(individu, period, previous_year, parametres_cmu):
indemnites_journalieres_maladie = individu('indemnites_journalieres_maladie', period)

Expand All @@ -249,7 +249,6 @@ def abattement_chomage(individu, period, previous_year, parametres_cmu):
salaire_net = individu('salaire_net', previous_year, options = [ADD])

return eligibilite_abattement_chomage * salaire_net * parametres_cmu.abattement_chomage
return eligibilite_abattement_chomage * salaire_net * parametres_cmu.abattement_chomage


# Revenus de stage de formation professionnelle exclus si plus perçus depuis 1 mois
Expand Down
10 changes: 2 additions & 8 deletions openfisca_france/model/prestations/minima_sociaux/ppa.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,16 +503,10 @@ class ppa(Variable):
reference = 'https://www.service-public.fr/particuliers/vosdroits/F2882'

def formula_2024_10(famille, period, parameters):
departement_experimentation_rsa = famille('departement_experimentation_rsa', period)
experimentation = ppa_base_formula(famille=famille, parameters=parameters, period=period, three_months_of_reference=last_3_months_offset_minus_1(period))
normal = ppa_base_formula(famille=famille, parameters=parameters, period=period, three_months_of_reference=period.last_3_months)
return where(departement_experimentation_rsa, experimentation, normal)
return ppa_base_formula(famille=famille, parameters=parameters, period=period, three_months_of_reference=last_3_months_offset_minus_1(period))

def formula_2016_01_01(famille, period, parameters):
return ppa_base_formula(famille= famille, parameters= parameters, period= period, three_months_of_reference= period.last_3_months)

def formula_2024_10(famille, period, parameters):
return ppa_base_formula(famille= famille, parameters= parameters, period= period, three_months_of_reference= last_3_months_offset_minus_1(period))
return ppa_base_formula(famille=famille, parameters=parameters, period=period, three_months_of_reference=period.last_3_months)


class crds_ppa(Variable):
Expand Down
6 changes: 3 additions & 3 deletions openfisca_france/model/revenus/activite/salarie.py
Original file line number Diff line number Diff line change
Expand Up @@ -1711,23 +1711,23 @@ class salaire_imposable_agents_assurance(Variable):
class cer_ou_ppae(Variable):
value_type = bool
entity = Individu
label = "Avoir un CER (Contrat dengagement réciproque) et/ou un PPAE (Projet personnalisé daccès à lemploi) en cours"
label = "Avoir un CER (Contrat d'engagement réciproque) et/ou un PPAE (Projet personnalisé d'accès à l'emploi) en cours"
definition_period = MONTH
set_input = set_input_dispatch_by_period


class formation(Variable):
value_type = bool
entity = Individu
label = "Etre en formation"
label = 'Etre en formation'
definition_period = MONTH
set_input = set_input_dispatch_by_period


class duree_contrat_ou_formation(Variable):
value_type = int
entity = Individu
label = "Durée en mois du CDD ou de la formation"
label = 'Durée en mois du CDD ou de la formation'
definition_period = MONTH
set_input = set_input_dispatch_by_period

Expand Down
17 changes: 10 additions & 7 deletions tests/formulas/aah/aah.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@
2015-10: 400
2015-09: 400
2015-08: 400
activite:
2018: actif
activite:
2018: actif
output:
aah_base_ressources_conjugalisee:
2015-11: 80
Expand Down Expand Up @@ -171,9 +171,9 @@
2018: inactif
output:
aah_base_ressources_conjugalisee:
2015-11: 154 / 12
2015-11: 108 / 12
aah_base:
2015-11: 795
2015-11: 799

- name: AAH demandeur sans ressource et conjoint salarié
period: month:2015-04
Expand All @@ -186,13 +186,14 @@
age: 40
taux_incapacite: 0.9
activite:
2018: inactif
2015: inactif
parent2:
age: 40
salaire_imposable:
2013: 1128.70 * 12
2015: 1128.70 * 12
activite:
2018: actif
2015: actif
output:
aah_base_ressources_conjugalisee:
2015-11:
Expand Down Expand Up @@ -844,6 +845,8 @@
2023-05: 200
2023-04: 200
2023-03: 200
activite:
2023: actif
albertjr:
age: 10
pensions_alimentaires_percues:
Expand Down Expand Up @@ -871,5 +874,5 @@
2023-01: actif
2022-12: actif
output:
aah_base_ressources: 696.41
aah_base_ressources_conjugalisee: 696.41
aah: 260
Loading

0 comments on commit 6d924a7

Please sign in to comment.