Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrige les erreurs de calcul sur les allègements #862

Merged
merged 16 commits into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

### 20.0.8 [#892](https://github.com/openfisca/openfisca-france/pull/862)

* Correction d'un bug
* Zones impactées :
- `prelevements_obligatoires/prelevements_sociaux/cotisations_sociales/allegements`
- `openfisca_france/model/revenus/activite/salarie.py`
* Détails :
- Corrige #844 (erreurs de calcul constatées sur la réduction générale dite "Fillon")
- `base_function` des dates de début et de fin de contrat de travail devient `requested_period_last_or_next_value`

### 20.0.7 [#892](https://github.com/openfisca/openfisca-france/pull/867)

* Évolution du système socio-fiscal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def formula(individu, period, parameters):
# coefficient = (contrat_de_travail >= 2) * (contrat_de_travail <= 3) * (
# forfait_heures_remunerees_volume / 45.7 * 52 / 12
# ) +
return coefficient
return (jours_ouvres_ce_mois_incomplet > 0) * coefficient


class credit_impot_competitivite_emploi(Variable):
Expand Down Expand Up @@ -373,7 +373,6 @@ def compute_allegement_fillon(individu, period, parameters):
ratio_smic_salaire = smic_proratise / (assiette + 1e-16)
# règle d'arrondi: 4 décimales au dix-millième le plus proche
taux_fillon = round_(tx_max * min_(1, max_(seuil * ratio_smic_salaire - 1, 0) / (seuil - 1)), 4)

# Montant de l'allegment
return taux_fillon * assiette

Expand Down Expand Up @@ -413,10 +412,9 @@ def compute_allegement_cotisation_allocations_familiales(individu, period, param
# TODO: Ne semble pas dépendre de la taille de l'entreprise mais à vérifier
# taille_entreprise = individu('taille_entreprise', period)
law = parameters(period).prelevements_sociaux.allegement_cotisation_allocations_familiales
ratio_smic_salaire = assiette / smic_proratise

# Montant de l'allegment
return (ratio_smic_salaire < law.plafond_en_nombre_de_smic) * law.reduction * assiette
return (assiette < law.plafond_en_nombre_de_smic * smic_proratise) * law.reduction * assiette
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bien vu !



###############################
Expand Down
2 changes: 2 additions & 0 deletions openfisca_france/model/revenus/activite/salarie.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class contrat_de_travail_debut(Variable):
entity = Individu
label = u"Date d'arrivée dans l'entreprise"
definition_period = MONTH
base_function = requested_period_last_or_next_value
set_input = set_input_dispatch_by_period


Expand All @@ -275,6 +276,7 @@ class contrat_de_travail_fin(Variable):
entity = Individu
label = u"Date de départ de l'entreprise"
definition_period = MONTH
base_function = requested_period_last_or_next_value
set_input = set_input_dispatch_by_period


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name = 'OpenFisca-France',
version = '20.0.7',
version = '20.0.8',
author = 'OpenFisca Team',
author_email = 'contact@openfisca.fr',
classifiers = [
Expand Down
225 changes: 225 additions & 0 deletions tests/allegement_fillon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,228 @@
2015-10: 0
2015-11: 0
2015-12: 0

- name: "Salarie un seul mois (novembre) - recouvrement fin d'année"
period: 2017
absolute_error_margin: 0.1
input_variables:
salaire_de_base: # un salaire en 2017
2017-01: 0
2017-02: 0
2017-03: 0
2017-04: 0
2017-05: 0
2017-06: 0
2017-07: 0
2017-08: 0
2017-09: 0
2017-10: 0
2017-11: 2300
2017-12: 0
allegement_fillon_mode_recouvrement: "fin_d_annee"
effectif_entreprise: 1
code_postal_entreprise: "75001"
categorie_salarie: prive_non_cadre
contrat_de_travail_debut: "2017-11-01"
contrat_de_travail_fin: "2017-12-01"
output_variables:
allegement_fillon:
2017-01: 0
2017-02: 0
2017-03: 0
2017-04: 0
2017-05: 0
2017-06: 0
2017-07: 0
2017-08: 0
2017-09: 0
2017-10: 0
2017-11: 0
2017-12: 32.04

- name: "Salarie un seul mois (novembre) - recouvrement progressif"
period: 2017
absolute_error_margin: 0.1
input_variables:
salaire_de_base: # un salaire en 2017
2017-01: 0
2017-02: 0
2017-03: 0
2017-04: 0
2017-05: 0
2017-06: 0
2017-07: 0
2017-08: 0
2017-09: 0
2017-10: 0
2017-11: 2300
2017-12: 0
allegement_fillon_mode_recouvrement: "progressif"
effectif_entreprise: 1
code_postal_entreprise: "75001"
categorie_salarie: prive_non_cadre
contrat_de_travail_debut: "2017-11-01"
contrat_de_travail_fin: "2017-12-01"
output_variables:
allegement_fillon:
2017-01: 0
2017-02: 0
2017-03: 0
2017-04: 0
2017-05: 0
2017-06: 0
2017-07: 0
2017-08: 0
2017-09: 0
2017-10: 0
2017-11: 32.04
2017-12: 0

- name: "Salarie un seul mois (novembre) - recouvrement anticipe"
period: 2017
absolute_error_margin: 0.1
input_variables:
salaire_de_base: # un salaire en 2017
2017-01: 0
2017-02: 0
2017-03: 0
2017-04: 0
2017-05: 0
2017-06: 0
2017-07: 0
2017-08: 0
2017-09: 0
2017-10: 0
2017-11: 2300
2017-12: 0
allegement_fillon_mode_recouvrement: "anticipe"
effectif_entreprise: 1
code_postal_entreprise: "75001"
categorie_salarie: prive_non_cadre
contrat_de_travail_debut: "2017-11-01"
contrat_de_travail_fin: "2017-12-01"
output_variables:
allegement_fillon:
2017-01: 0
2017-02: 0
2017-03: 0
2017-04: 0
2017-05: 0
2017-06: 0
2017-07: 0
2017-08: 0
2017-09: 0
2017-10: 0
2017-11: 32.04
2017-12: 0

- name: "Salarie un seul mois (décembre) - recouvrement fin d'année"
period: 2017
absolute_error_margin: 0.1
input_variables:
salaire_de_base: # un salaire en 2017
2017-01: 0
2017-02: 0
2017-03: 0
2017-04: 0
2017-05: 0
2017-06: 0
2017-07: 0
2017-08: 0
2017-09: 0
2017-10: 0
2017-11: 0
2017-12: 2300
allegement_fillon_mode_recouvrement: "fin_d_annee"
effectif_entreprise: 1
code_postal_entreprise: "75001"
categorie_salarie: prive_non_cadre
contrat_de_travail_debut: "2017-12-01"
output_variables:
allegement_fillon:
2017-01: 0
2017-02: 0
2017-03: 0
2017-04: 0
2017-05: 0
2017-06: 0
2017-07: 0
2017-08: 0
2017-09: 0
2017-10: 0
2017-11: 0
2017-12: 32.04

- name: "Salarie un seul mois (décembre) - recouvrement progressif"
period: 2017
absolute_error_margin: 0.1
input_variables:
salaire_de_base: # un salaire en 2017
2017-01: 0
2017-02: 0
2017-03: 0
2017-04: 0
2017-05: 0
2017-06: 0
2017-07: 0
2017-08: 0
2017-09: 0
2017-10: 0
2017-11: 0
2017-12: 2300
allegement_fillon_mode_recouvrement: "progressif"
effectif_entreprise: 1
code_postal_entreprise: "75001"
categorie_salarie: prive_non_cadre
contrat_de_travail_debut: "2017-12-01"
output_variables:
allegement_fillon:
2017-01: 0
2017-02: 0
2017-03: 0
2017-04: 0
2017-05: 0
2017-06: 0
2017-07: 0
2017-08: 0
2017-09: 0
2017-10: 0
2017-11: 0
2017-12: 32.04

- name: "Salarie un seul mois (décembre) - recouvrement anticipe"
period: 2017
absolute_error_margin: 0.1
input_variables:
salaire_de_base: # un salaire en 2017
2017-01: 0
2017-02: 0
2017-03: 0
2017-04: 0
2017-05: 0
2017-06: 0
2017-07: 0
2017-08: 0
2017-09: 0
2017-10: 0
2017-11: 0
2017-12: 2300
allegement_fillon_mode_recouvrement: anticipe
effectif_entreprise: 1
code_postal_entreprise: "75001"
categorie_salarie: prive_non_cadre
contrat_de_travail_debut: "2017-12-01"
output_variables:
allegement_fillon:
2017-01: 0
2017-02: 0
2017-03: 0
2017-04: 0
2017-05: 0
2017-06: 0
2017-07: 0
2017-08: 0
2017-09: 0
2017-10: 0
2017-11: 0
2017-12: 32.04
11 changes: 7 additions & 4 deletions tests/formulas/allegement_cotisation_allocations_familiales.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# allegement mode necessary when requesting on a 1 month salary :
allegement_cotisation_allocations_familiales_mode_recouvrement: anticipe
allegement_fillon_mode_recouvrement: anticipe
contrat_de_travail_debut: 2015-07-01
contrat_de_travail_debut: 2015-01-01
contrat_de_travail_fin: 2015-12-31
effectif_entreprise: 1
output_variables:
allegement_cotisation_allocations_familiales: 26.23
Expand All @@ -19,21 +20,23 @@
# allegement mode necessary when requesting on a 1 month salary :
allegement_cotisation_allocations_familiales_mode_recouvrement: anticipe
allegement_fillon_mode_recouvrement: anticipe
contrat_de_travail_debut: 2015-07-01
contrat_de_travail_debut: 2015-01-01
contrat_de_travail_fin: 2015-12-31
effectif_entreprise: 1
output_variables:
allegement_cotisation_allocations_familiales: 0

- period: "2016-05"
name: 2xSMIC
name: 3.5xSMIC
description: après avril 2016, l'allègement est étendu jusqu'à 3.5 SMIC
relative_error_margin: 0.001
input_variables:
salaire_de_base: 2915
# allegement mode necessary when requesting on a 1 month salary :
allegement_cotisation_allocations_familiales_mode_recouvrement: anticipe
allegement_fillon_mode_recouvrement: anticipe
contrat_de_travail_debut: 2015-07-01
contrat_de_travail_debut: 2016-01-01
contrat_de_travail_fin: 2016-12-31
effectif_entreprise: 1
output_variables:
allegement_cotisation_allocations_familiales: 52.47
41 changes: 41 additions & 0 deletions tests/test_coefficient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-

from nose.tools import assert_equal

from openfisca_france.model.prelevements_obligatoires.prelevements_sociaux.cotisations_sociales.allegements import *
from openfisca_core.periods import *
from openfisca_france import FranceTaxBenefitSystem

def test_coefficient_proratisation_only_contract_periods_wide():
tax_benefit_system = FranceTaxBenefitSystem()
scenario = tax_benefit_system.new_scenario()
scenario.init_single_entity(period='2017', # wide: we simulate for the year
parent1=dict(salaire_de_base={'2017-11':2300},
effectif_entreprise=1,
code_postal_entreprise="75001",
categorie_salarie=u'prive_non_cadre',
contrat_de_travail_debut='2017-11-1',
contrat_de_travail_fin='2017-12-01',
allegement_fillon_mode_recouvrement=u'progressif'))
simulation = scenario.new_simulation()
assert_equal(simulation.calculate('coefficient_proratisation','2017-11'),1)
assert_equal(simulation.calculate('coefficient_proratisation','2017-12'),0)
assert_equal(simulation.calculate('coefficient_proratisation','2017-10'),0)
assert_equal(simulation.calculate_add('coefficient_proratisation','2017'),1)

def test_coefficient_proratisation_only_contract_periods_narrow():
tax_benefit_system = FranceTaxBenefitSystem()
scenario = tax_benefit_system.new_scenario()
scenario.init_single_entity(period='2017-11', # narrow: we simulate for the month
parent1=dict(salaire_de_base={'2017-11':2300},
effectif_entreprise=1,
code_postal_entreprise="75001",
categorie_salarie=u'prive_non_cadre',
contrat_de_travail_debut='2017-11-1',
contrat_de_travail_fin='2017-12-01',
allegement_fillon_mode_recouvrement=u'progressif'))
simulation = scenario.new_simulation()
assert_equal(simulation.calculate('coefficient_proratisation','2017-11'),1)
assert_equal(simulation.calculate('coefficient_proratisation','2017-12'),0)
assert_equal(simulation.calculate('coefficient_proratisation','2017-10'),0)
assert_equal(simulation.calculate_add('coefficient_proratisation','2017'),1)