Skip to content

Commit

Permalink
Merge pull request #240 from openfisca/fix_appel_reforms
Browse files Browse the repository at this point in the history
Rapatrie des anciennes réformes d'Openfisca France
  • Loading branch information
clallemand authored Sep 8, 2023
2 parents 0b17740 + 6efd91a commit e63d54f
Show file tree
Hide file tree
Showing 22 changed files with 951 additions and 9 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

### 2.0.5 [#238(https://github.com/openfisca/openfisca-france-data/pull/238)
### 2.0.6 [#240](https://github.com/openfisca/openfisca-france-data/pull/240)
* Technical changes
- Rapatrie certaines réformes qui ont été supprimés dans openfisca france par la (PR 2177)[https://github.com/Supprime vieilles réformes non utilisées openfisca-france#2177] mais qui sont encore utilisées dans ce dépôt

### 2.0.5 [#238](https://github.com/openfisca/openfisca-france-data/pull/238)
* Technical changes
- Corrige le calcul du smic annuel en fonction du smic horaire dans openfisca_france_data/erfs_fpr/input_data_builder/step_04_famille.py

Expand Down
4 changes: 2 additions & 2 deletions openfisca_france_data/base_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from openfisca_france.entities import Famille
from openfisca_france_data import france_data_tax_benefit_system

from openfisca_france.reforms import (
from openfisca_france_data.reforms.old_openfisca_france_reforms import (
allocations_familiales_imposables,
cesthra_invalidee,
# inversion_directe_salaires, # We use a custom inversion_directe_salaires, not merged in the openfisca-france yet
Expand Down Expand Up @@ -37,7 +37,7 @@
scipy = None

if scipy is not None:
from openfisca_france.reforms import de_net_a_brut
from openfisca_france_data.reforms.old_openfisca_france_reforms import de_net_a_brut
reform_list['de_net_a_brut'] = de_net_a_brut.de_net_a_brut

reform_by_full_key = {}
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import os

from openfisca_france.model.base import *


dir_path = os.path.join(os.path.dirname(__file__), 'parameters')


def modify_parameters(parameters):
file_path = os.path.join(dir_path, 'allocations_familiales_imposables.yaml')
reform_parameters_subtree = load_parameter_file(name='allocations_familiales_imposables', file_path=file_path)
parameters.add_child('allocations_familiales_imposables', reform_parameters_subtree)
return parameters


class allocations_familiales_imposables(Reform):
name = 'Allocations familiales imposables'

class rbg(Variable):
label = 'Nouveau revenu brut global intégrant les allocations familiales'
definition_period = YEAR

def formula(foyer_fiscal, period, parameters):
allocations_familiales_imposables = foyer_fiscal('allocations_familiales_imposables', period, options = [ADD])
deficit_ante = foyer_fiscal('deficit_ante', period)
f6gh = foyer_fiscal('f6gh', period)

nacc_pvce_i = foyer_fiscal.members('nacc_pvce', period)
nbic_impm_i = foyer_fiscal.members('nbic_impm', period)

revenu_categoriel = foyer_fiscal('revenu_categoriel', period)
cga = parameters(period).impot_revenu.calcul_revenus_imposables.rpns.cga_taux2

nacc_pvce = foyer_fiscal.sum(nacc_pvce_i)
return max_(
0,
allocations_familiales_imposables
+ revenu_categoriel
+ f6gh
+ (foyer_fiscal.sum(nbic_impm_i) + nacc_pvce)
* (1 + cga)
- deficit_ante
)

class rfr(Variable):
label = 'Nouveau revenu fiscal de référence intégrant les allocations familiales'
definition_period = YEAR

def formula(foyer_fiscal, period, parameters):
allocations_familiales_imposables = foyer_fiscal('allocations_familiales_imposables')
abattements_plus_values = foyer_fiscal('abattements_plus_values')
f3vi_holder = foyer_fiscal.members('f3vi')
f3vz = foyer_fiscal('f3vz')
rfr_cd = foyer_fiscal('rfr_cd')
rni = foyer_fiscal('rni')
rpns_exon_holder = foyer_fiscal.members('rpns_exon')
rfr_rvcm_abattements_a_reintegrer = foyer_fiscal('rfr_rvcm_abattements_a_reintegrer') # Supprimée en 2018
revenus_capitaux_prelevement_liberatoire = foyer_fiscal('revenus_capitaux_prelevement_liberatoire', period, options = [ADD]) # Supprimée en 2018
revenus_capitaux_prelevement_forfaitaire_unique_ir = foyer_fiscal('revenus_capitaux_prelevement_forfaitaire_unique_ir', period, options = [ADD]) # Existe à partir de 2018
microentreprise = foyer_fiscal('microentreprise')

f3vi = foyer_fiscal.sum(f3vi_holder)
rpns_exon = foyer_fiscal.sum(rpns_exon_holder)

return (
max_(0, rni - allocations_familiales_imposables)
+ rfr_cd
+ rfr_rvcm_abattements_a_reintegrer
+ revenus_capitaux_prelevement_liberatoire
+ revenus_capitaux_prelevement_forfaitaire_unique_ir
+ f3vi
+ rpns_exon
+ abattements_plus_values
+ f3vz
+ microentreprise
)

# TO CHECK : f3vb after 2015 (abattements sur moins-values = interdits)

class allocations_familiales_imposables(Variable):
value_type = float
entity = FoyerFiscal
label = 'Allocations familiales imposables'
definition_period = YEAR

def formula(foyer_fiscal, period, parameters):
imposition = parameters(period).allocations_familiales_imposables.imposition
af = foyer_fiscal.declarant_principal.famille('af', period, options = [ADD])

return af * imposition

def apply(self):
self.update_variable(self.rbg)
self.update_variable(self.rfr)
self.add_variable(self.allocations_familiales_imposables)
self.modify_parameters(modifier_function = modify_parameters)
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os

from openfisca_france.model.base import *

from openfisca_france import entities


dir_path = os.path.join(os.path.dirname(__file__), 'parameters')


def modify_parameters(parameters):
file_path = os.path.join(dir_path, 'cesthra_invalidite.yaml')
reform_parameters_subtree = load_parameter_file(name='cesthra', file_path=file_path)
parameters.add_child('cesthra', reform_parameters_subtree)
return parameters


class cesthra(Variable):
value_type = float
entity = entities.FoyerFiscal
label = "Contribution exceptionnelle de solidarité sur les très hauts revenus d'activité"
definition_period = YEAR
# PLF 2013 (rejeté) : 'taxe à 75%'

def formula(foyer_fiscal, period, parameters):
salaire_imposable_i = foyer_fiscal.members('salaire_imposable', period, options = [ADD])
_cesthra = parameters(period).cesthra

cesthra_i = max_(salaire_imposable_i - _cesthra.seuil, 0) * _cesthra.taux

return foyer_fiscal.sum(cesthra_i)


class irpp(Variable):
label = 'Impôt sur le revenu des personnes physiques (réformée pour intégrer la cesthra)'
definition_period = YEAR

def formula(foyer_fiscal, period, parameters):
'''
Montant après seuil de recouvrement (hors ppe)
'''
iai = foyer_fiscal('iai', period)
credits_impot = foyer_fiscal('credits_impot', period)
acomptes_ir = foyer_fiscal('acomptes_ir', period)
contribution_exceptionnelle_hauts_revenus = foyer_fiscal('contribution_exceptionnelle_hauts_revenus', period)
cesthra = foyer_fiscal('cesthra', period = period)
recouvrement = parameters(period).impot_revenu.calcul_impot_revenu.recouvrement

pre_result = iai - credits_impot - acomptes_ir + contribution_exceptionnelle_hauts_revenus + cesthra

return (
(iai > recouvrement.seuil)
* ((pre_result < recouvrement.min) * (pre_result > 0) * iai * 0
+ ((pre_result <= 0) + (pre_result >= recouvrement.min)) * (- pre_result))
+ (iai <= recouvrement.seuil) * ((pre_result < 0) * (-pre_result)
+ (pre_result >= 0) * 0 * iai)
)


class cesthra_invalidee(Reform):
name = "Contribution execptionnelle sur les très hauts revenus d'activité (invalidée par le CC)"

def apply(self):
self.add_variable(cesthra)
self.update_variable(irpp)
self.modify_parameters(modifier_function = modify_parameters)
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from openfisca_core.reforms import Reform

try:
from scipy.optimize import fsolve
except ImportError:
fsolve = None

from openfisca_france import entities
from openfisca_france.model.base import *


def calculate_net_from(salaire_de_base, individu, period):

# We're not wanting to calculate salaire_de_base again, but instead manually set it as an input variable
individu.get_holder('salaire_de_base').put_in_cache(salaire_de_base, period)

# Work in isolation
temp_simulation = individu.simulation.clone()
temp_individu = temp_simulation.individu

# Force recomputing of salaire_net
temp_individu.get_holder('salaire_net_a_payer').delete_arrays()

net = temp_individu('salaire_net_a_payer', period)[0]

return net


class salaire_de_base(Variable):
value_type = float
entity = entities.Individu
label = 'Salaire brut'
definition_period = MONTH

def formula(individu, period, parameters):
# Calcule le salaire brut à partir du salaire net par inversion numérique.

net = individu.get_holder('salaire_net_a_payer').get_array(period)

if net is None:
return individu.empty_array()

def solve_func(net):
def innerfunc(essai):
return calculate_net_from(essai, individu, period) - net
return innerfunc
brut_calcule = fsolve(
solve_func(net),
net * 1.5, # on entend souvent parler cette méthode...
xtol = 1 / 10 # précision
)

return brut_calcule


class de_net_a_brut(Reform):
name = 'Inversion du calcul brut -> net'

def apply(self):
self.update_variable(salaire_de_base)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
description: Intégration au revenu imposable des allocations familiales
imposition:
description: "Indicatrice d'imposition"
values:
'2015-01-01':
value: null
'2000-01-01':
value: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
description: Contribution execptionnelle sur les très hauts revenus d'activité
seuil:
description: Seuil
values:
'2014-01-01':
value: null
'2012-01-01':
value: 1000000
taux:
description: Taux
values:
'2014-01-01':
value: null
'2012-01-01':
value: 0.75
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
description: Impôt à base large proposé par Landais Piketty et Saez
bareme:
unit: currency
description: Barème de l'impôt
brackets:
- average_rate:
'2015-01-01':
value: null
'2000-01-01':
value: 0.02
threshold:
'2015-01-01':
value: null
'2000-01-01':
value: 1100
- average_rate:
'2015-01-01':
value: null
'2000-01-01':
value: 0.1
threshold:
'2015-01-01':
value: null
'2000-01-01':
value: 2200
- average_rate:
'2015-01-01':
value: null
'2000-01-01':
value: 0.13
threshold:
'2015-01-01':
value: null
'2000-01-01':
value: 5000
- average_rate:
'2015-01-01':
value: null
'2000-01-01':
value: 0.25
threshold:
'2015-01-01':
value: null
'2000-01-01':
value: 10000
- average_rate:
'2015-01-01':
value: null
'2000-01-01':
value: 0.5
threshold:
'2015-01-01':
value: null
'2000-01-01':
value: 40000
- average_rate:
'2015-01-01':
value: null
'2000-01-01':
value: 0.6
threshold:
'2015-01-01':
value: null
'2000-01-01':
value: 100000
imposition:
description: "Indicatrice d'imposition"
values:
'2015-01-01':
value: null
'2000-01-01':
value: true
credit_enfant:
description: "Crédit d'impôt forfaitaire par enfant"
values:
'2015-01-01':
value: null
'2000-01-01':
value: 0
reduc_enfant:
description: "Réduction d'impôt forfaitaire par enfant"
values:
'2015-01-01':
value: null
'2000-01-01':
value: 0
abatt_enfant:
description: Abattement forfaitaire sur le revenu par enfant
values:
'2015-01-01':
value: null
'2000-01-01':
value: 0
reduc_conj:
description: "Réduction d'impôt forfaitaire si conjoint"
values:
'2015-01-01':
value: null
'2000-01-01':
value: 0
abatt_conj:
description: Abattement forfaitaire sur le revenu si conjoint
values:
'2015-01-01':
value: null
'2000-01-01':
value: 0
Loading

0 comments on commit e63d54f

Please sign in to comment.