Skip to content

Commit

Permalink
refactor: style
Browse files Browse the repository at this point in the history
- Correction mineure de l'indentation
  • Loading branch information
Shamzic committed Feb 6, 2025
1 parent ee62e45 commit c714a94
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions openfisca_france/model/prestations/bail_reel_solidaire.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pkg_resources
import numpy as np


def bail_reel_solidaire_zones_elligibles():
with pkg_resources.resource_stream(openfisca_france.__name__, 'assets/zonage-communes/zonage-abc-juillet-2024.csv') as csv_file:
utf8_reader = codecs.getreader('utf-8')
Expand All @@ -14,6 +15,7 @@ def bail_reel_solidaire_zones_elligibles():
for row in csv_reader
}


class bail_reel_solidaire_zones_menage(Variable):
value_type = str
label = 'Zone du ménage pour le Bail Réel Solidaire'
Expand All @@ -25,7 +27,8 @@ def formula(menage, period):
return np.fromiter(
(bail_reel_solidaire_zones_elligibles().get(depcom_cell.decode('utf-8')) for depcom_cell in depcom),
dtype='<U4' # String length max for zones (A, Abis, B1, B2, C)
)
)


class bail_reel_solidaire_plafond_total(Variable):
value_type = float
Expand All @@ -46,32 +49,32 @@ def calcul_plafonds_zone(zone):
plafond_base = select(
[nb_personnes == i if i < 6 else nb_personnes >= i for i in range(1, 7)],
[plafond_zone[f'nb_personnes_{i}'] for i in range(1, 7)]
)
)
plafond_supp = where(
nb_personnes > nb_personnes_max,
(nb_personnes - nb_personnes_max) * plafond_zone.nb_personnes_supplementaires,
0
)
)
return plafond_base + plafond_supp

return select(
[zones_menage == zone for zone in zones_abc_eligibles],
[calcul_plafonds_zone(zone) for zone in zones_abc_eligibles]
)
)


class bail_reel_solidaire(Variable):
entity = Menage
value_type = bool
label = 'Éligibilité au Bail Réel Solidaire'
entity = Menage
definition_period = MONTH
reference = [
'https://www.legifrance.gouv.fr/jorf/id/JORFTEXT000032918488',
'https://www.legifrance.gouv.fr/loda/id/JORFTEXT000000437021'
]
label = 'Bail réel solidaire'
definition_period = MONTH

def formula(menage, period):
plafond_total = menage('bail_reel_solidaire_plafond_total', period)
zones_menage = menage('bail_reel_solidaire_zones_menage', period)
rfr = menage.sum(menage.members.foyer_fiscal('rfr', period.n_2), role=FoyerFiscal.DECLARANT_PRINCIPAL)
return where(zones_menage is not None, rfr <= plafond_total, False)

0 comments on commit c714a94

Please sign in to comment.