Skip to content

Commit

Permalink
Fixing some revenu inversion.
Browse files Browse the repository at this point in the history
Added legislation_parameters preprocessing
Added CASA.
Somme cleaning.
  • Loading branch information
benjello committed Mar 3, 2014
1 parent 11653c1 commit 65c4e86
Show file tree
Hide file tree
Showing 31 changed files with 111 additions and 142 deletions.
12 changes: 3 additions & 9 deletions openfisca_france/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@
def init_country(qt = False,
start_from = "imposable",
drop_survey_only_variables = False,
simulate_f6de = False,
test_param = False):
simulate_f6de = False):
"""Add country-specific content to OpenFisca-Core package."""
from openfisca_core.columns import Prestation
from openfisca_core import model as core_model
Expand All @@ -156,14 +155,11 @@ def init_country(qt = False,
from .model.datatrees import columns_name_tree_by_entity
from .model.model import prestation_by_name

from .model.cotisations_sociales.preprocessing import preprocess_legislation_parameters

if qt:
from .widgets.Composition import CompositionWidget

if test_param:
from .model.cotisations_sociales.preprocessing import preprocess_legislation_parameters


assert start_from in ["brut", "imposable"] # TODO: net

if start_from in ['brut', 'net']:
Expand Down Expand Up @@ -244,9 +240,7 @@ def init_country(qt = False,
)

core_simulations.check_consistency = utils.check_consistency
core_simulations.preprocess_legislation_parameters = preprocess_legislation_parameters

if qt:
qt_widgets.CompositionWidget = CompositionWidget

if test_param:
core_simulations.preprocess_legislation_parameters = preprocess_legislation_parameters
3 changes: 2 additions & 1 deletion openfisca_france/decompositions/decomp_contrib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@
<NODE desc= "CRDS (chômage)" shortname="CRDS chôm." code= "crdscho" color = "229,48,56"/>
</NODE>
<NODE desc= "Retraites nettes" shortname="Retraites nettes" code = "rstnet" color = "87,88,138">
<NODE desc= "Retraites" shortname="Retr. décl." code = "rst">
<NODE desc= "Retraites imposables" shortname="Retr. décl." code = "rst">
<NODE desc= "Retraites brutes" shortname="Retr. brutes" code = "rstbrut"/>
<NODE desc= "CSG déductible (retraite)" shortname="CSG déd. ret." code= "csgrstd" color = "235,114,118"/>
</NODE>
<NODE desc= "CSG non déductible (pensions)" shortname="CSG imp. pens." code= "csgrsti" color = "235,114,118"/>
<NODE desc= "CRDS (pensions)" shortname="CRDS (pens.)" code= "crdsrst" color = "229,48,56"/>
<NODE desc= "Contribution additionnelle de solidarité pour l'autonomie" shortname="CASA (pens.)" code= "crdsrst" color = "229,48,56"/>
</NODE>
<NODE desc= "Pensions alimentaires reçues" shortname="P. alim. reç." code = "alr" color = "136,120,178"/>
<NODE desc= "Pensions alimentaires versée" shortname="P. alim. vers." code = "alv" color = "136,120,178"/>
Expand Down
22 changes: 11 additions & 11 deletions openfisca_france/model/cotisations_sociales/capital.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def _prelsoc_cap_bar(rev_cap_bar, _P):
if _P.datesim.year < 2006:
total = P.base_pat
elif _P.datesim.year < 2009:
total = P.base_pat + P.add
total = P.base_pat + P.add_pat
else:
total = P.base_pat + P.add + P.rsa
total = P.base_pat + P.add_pat + P.rsa
return -rev_cap_bar * total

# plus-values de valeurs mobilières
Expand Down Expand Up @@ -104,9 +104,9 @@ def _prelsoc_pv_mo(f3vg, _P):
if _P.datesim.year < 2006:
total = P.base_pat
elif _P.datesim.year < 2009:
total = P.base_pat + P.add
total = P.base_pat + P.add_pat
else:
total = P.base_pat + P.add + P.rsa
total = P.base_pat + P.add_pat + P.rsa
return -f3vg * total


Expand Down Expand Up @@ -134,9 +134,9 @@ def _prelsoc_pv_immo(f3vz, _P):
if _P.datesim.year < 2006:
total = P.base_pat
elif _P.datesim.year < 2009:
total = P.base_pat + P.add
total = P.base_pat + P.add_pat
else:
total = P.base_pat + P.add + P.rsa
total = P.base_pat + P.add_pat + P.rsa
return -f3vz * total


Expand All @@ -147,7 +147,7 @@ def _csg_fon(rev_cat_rfon, _P):
Attention : assiette csg = asiette irpp valable 2006-2014 mais pourrait changer
'''
return -rev_cat_rfon * _P.csg.capital.glob

def _crds_fon(rev_cat_rfon, _P):
'''
Calcule la CRDS sur les revenus fonciers
Expand All @@ -165,9 +165,9 @@ def _prelsoc_fon(rev_cat_rfon, _P):
if _P.datesim.year < 2006:
total = P.base_pat
elif _P.datesim.year < 2009:
total = P.base_pat + P.add
total = P.base_pat + P.add_pat
else:
total = P.base_pat + P.add + P.rsa
total = P.base_pat + P.add_pat + P.rsa
return -rev_cat_rfon * total

# revenus du capital soumis au prélèvement libératoire
Expand Down Expand Up @@ -197,9 +197,9 @@ def _prelsoc_cap_lib(rev_cap_lib, _P):
if _P.datesim.year < 2006:
total = P.base_pat
elif _P.datesim.year < 2009:
total = P.base_pat + P.add
total = P.base_pat + P.add_pat
else:
total = P.base_pat + P.add + P.rsa
total = P.base_pat + P.add_pat + P.rsa
return -rev_cap_lib * total


Expand Down
12 changes: 6 additions & 6 deletions openfisca_france/model/cotisations_sociales/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'public_titulaire_hospitaliere',
'public_non_titulaire'])

DEBUG_SAL_TYPE = 'public_titulaire_hospitaliere'
DEBUG_SAL_TYPE = 'public_titulaire_etat'

from openfisca_core.legislations import CompactNode

Expand Down Expand Up @@ -91,9 +91,9 @@ def build_pat(_P):
for var in ['etat', 'colloc', 'contract' ]:
del pat['fonc'][var]

# Renaiming
# Renaming
pat['public_titulaire_etat'] = pat.pop('etat_t')
del pat['public_titulaire_etat']['rafp']
# del pat['public_titulaire_etat']['rafp']

pat['public_titulaire_territoriale'] = pat.pop('colloc_t')
import copy
Expand Down Expand Up @@ -159,10 +159,10 @@ def preprocess_legislation_parameters(legislation_parameters_list):
sal = build_sal(_P)
pat = build_pat(_P)

_P.cotsoc.__dict__['cotisations_patronales'] = CompactNode()
_P.cotsoc.__dict__['cotisations_salariales'] = CompactNode()
_P.cotsoc.__dict__[u'cotisations_employeur'] = CompactNode()
_P.cotsoc.__dict__[u'cotisations_salarie'] = CompactNode()

for cotisation_name, bareme_dict in {'cotisations_patronales' : pat, 'cotisations_salariales': sal}.iteritems():
for cotisation_name, bareme_dict in {'cotisations_employeur' : pat, 'cotisations_salarie': sal}.iteritems():
for category in bareme_dict:
if category in CAT._nums:
_P.cotsoc.__dict__[cotisation_name].__dict__[category] = bareme_dict[category]
Expand Down
75 changes: 29 additions & 46 deletions openfisca_france/model/cotisations_sociales/remplacement.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@
############################################################################


def _csg_rempl(rfr_n_2, nbpt_n_2, chobrut, rstbrut, _P):
'''
Taux retenu sur la CSG des revenus de remplacment:
0 : Non renseigné/non pertinent
1 : Exonéré (sous plafond de ressource)
2 : Taux réduit (irpp < seuil de non versement)
3 : Taux plein
'''
# TODO: problème avec le rfr n-2
P = _P.cotsoc.gen
seuil_th = P.plaf_th_1 + P.plaf_th_supp * (max_(0, (nbpt_n_2 - 1) / 2))
res = (0
+ max_((chobrut > 0) + (rstbrut > 0), 0) # pertinence la personne est au chômage ou pensionnées
+ (rfr_n_2 >= seuil_th) # la personne n'ont pas assez de ressources
+ 1) # la personne ne satisfait pas à la conditon de ressources mais son impot avant credit > seuil de non imposition
return res


def exo_csg_chom(chobrut, csg_rempl, _P):
'''
Indicatrice d'exonération de la CSG sur les revenus du chômage sans exo
Expand Down Expand Up @@ -74,47 +92,6 @@ def crdscho_sans_exo(chobrut, csg_rempl, _P):
return -crds.calc(chobrut) * (2 <= csg_rempl)


def _csg_rempl(rfr_n_2, nbpt_n_2, chobrut, rstbrut, _P):
'''
Taux retenu sur la CSG des revenus de remplacment:
0 : Non renseigné/non pertinent
1 : Exonéré (sous plafond de ressource)
2 : Taux réduit (irpp < seuil de non versement)
3 : Taux plein
'''
# TODO: problème avec le rfr n-2
P = _P.cotsoc.gen
seuil_th = P.plaf_th_1 + P.plaf_th_supp * (max_(0, (nbpt_n_2 - 1) / 2))
res = (0
+ max_((chobrut > 0) + (rstbrut > 0), 0) # pertinence la personne est au chômage ou pensionnées
+ (rfr_n_2 >= seuil_th) # la personne n'ont pas assez de ressources
+ 1) # la personne ne satisfait pas à la conditon de ressources mais son impot avant credit > seuil de non imposition
return res


def _chobrut(choi, csg_rempl, _defaultP):
'''
Calcule les allocations chômage brute à partir des allocations imposables
'''
# TODO: ajouter la crds ?
P = _defaultP.csg.chom
plaf_ss = 12 * _defaultP.cotsoc.gen.plaf_ss
csg = scaleBaremes(BaremeDict('csg', P), plaf_ss)
taux_plein = csg['plein']['deduc']
taux_reduit = csg['reduit']['deduc']

chom_plein = taux_plein.inverse()
chom_reduit = taux_reduit.inverse()

chobrut_temp = ((csg_rempl == 1) * choi
+ (csg_rempl == 2) * chom_reduit.calc(choi)
+ (csg_rempl == 3) * chom_plein.calc(choi))
isexo = exo_csg_chom(chobrut_temp, csg_rempl, _defaultP)
chobrut = not_(isexo) * chobrut_temp + (isexo) * choi

return chobrut


def _csgchod(chobrut, csg_rempl, _P):
'''
CSG déductible sur les allocations chômage
Expand Down Expand Up @@ -146,8 +123,7 @@ def _cho(chobrut, csgchod, _P):
'''
Chômage imposable (recalculé)
'''
# isexo = exo_csg_chom(chobrut, _P) # TODO: check
return chobrut + csgchod # + not_(isexo)*csgchod
return chobrut + csgchod


def _chonet(cho, csgchoi, crdscho):
Expand All @@ -160,6 +136,7 @@ def _chonet(cho, csgchoi, crdscho):
############################################################################
# # Pensions
############################################################################

def _rstbrut(rsti, csg_rempl, _defaultP):
'''
Calcule les pensions de retraites brutes à partir des pensions imposables
Expand Down Expand Up @@ -208,16 +185,22 @@ def _crdsrst(rstbrut, csg_rempl, _P):
return -crds['rst'].calc(rstbrut) * not_(isexo)


def _casa(rstbrut, csg_rempl, _P):
"""
Contribution additionnelle de solidarité et d'autonomie
"""
return (csg_rempl == 3) * _P.prelsoc.add_ret * rst_brut


def _rst(rstbrut, csgrstd):
'''
Calcule les pensions imposables
'''
return rstbrut + csgrstd


def _rstnet(rst, csgrsti, crdsrst):
def _rstnet(rst, csgrsti, crdsrst, casa):
'''
Retraites nettes
'''
return rst + csgrsti + crdsrst

return rst + csgrsti + crdsrst + casa
Loading

0 comments on commit 65c4e86

Please sign in to comment.