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

Add reform modifying brackets of a scale #7

Merged
merged 3 commits into from
May 31, 2017
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
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# 1.1.0 - [#7](https://github.com/openfisca/country-template/pull/7)

* Tax and benefit system evolution: add a reform modifying the brackets of a scale
* Impacted periods: from 2013-01-01
* Impacted areas: `openfisca_country_template/parameters/taxes.xml`
* Details:
- Show how to add, modify and remove a bracket.
- Add corresponding tests.

# 1.0.0 - [#4](https://github.com/openfisca/country-template/pull/4)

* Tax and benefit system evolution.
* Impacted periods: all.
* Impacted periods: all.
* Impacted areas:
- `benefits`
- `demographics`
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ These elements are described in different folders. All the modelling happens wit

- The rates are in the `parameters` folder.
- The formulas are in the `variables` folder.
- This country template comes also with *reforms* in the `reforms` folder. This is optional: your country may exist without defining any reform.
- In this country, there is [a reform project](./openfisca_country_template/reforms/modify_social_security_taxation.py) aiming to modify the social security taxation, deleting the first bracket, raising the intermediary ones and adding a new bracket with a higher tax rate of `40 %` for people earning more than `40000`. This reform project would apply starting from `2017-01-01`.

The files that are outside from the `openfisca_country_template` folder are used to set up the development environment.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-

# This file defines a reform.
# A reform is a set of modifications to be applied to a reference tax and benefit system to carry out experiments.
# See https://doc.openfisca.fr/reforms.html


# Import from openfisca-core the common python objects used to code the legislation in OpenFisca
from openfisca_core.model_api import *


class modify_social_security_taxation(Reform):
# A reform always defines an `apply` method that builds the reformed tax and benefit system from the reference one.
# See https://doc.openfisca.fr/coding-the-legislation/reforms.html#writing-a-reform
def apply(self):
# Our reform modifies the `social_security_contribution` parameter, which is a scale.
# This parameter is declared in `taxes.xml` using a `<BAREME>` XML element, the French name for "scale".
#
# See https://doc.openfisca.fr/coding-the-legislation/legislation_parameters.html
self.modify_legislation_json(modifier_function=self.modify_brackets)

def modify_brackets(self, reference_legislation_json_copy):
# This function takes an argument `reference_legislation_json_copy` which is a JSON-like representation
# of the XML element. It can be modified and must be returned.

# Access the right legislation node:
scale = reference_legislation_json_copy['children']['taxes']['children']['social_security_contribution']
brackets = scale['brackets']

# Add 0.1 to the rates of the second bracket, keeping the same thresholds:
for rate in brackets[1]['rate']:
rate['value'] += 0.1

# Remove the first bracket:
del brackets[0]

# Add a new bracket with a higher tax rate for rich people:
brackets.append({
'rate': [{'start': '2017-01-01', 'value': 0.4}],
'threshold': [{'start': '2017-01-01', 'value': 40000}]
})

return reference_legislation_json_copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Test files describe situations and their expected outcomes
# We can run this test on our command line using `openfisca-run-test modify_social_security_taxation.yaml`

# This test is a partial adaptation of `social_security_contribution.yaml` to match the modifications introduced by the reform of the same name.

# Note the `reforms: ` key in the below YAML blocks.

- name: No social security contribution on small salaries
reforms: openfisca_country_template.reforms.modify_social_security_taxation.modify_social_security_taxation
period: 2017-01
input_variables:
salary: 2000
output_variables:
social_security_contribution: 0

- name: Increased social security contribution on medium salaries
reforms: openfisca_country_template.reforms.modify_social_security_taxation.modify_social_security_taxation
period: 2017-01
input_variables:
salary: 15000
output_variables:
social_security_contribution: 1336

- name: High social security contribution on high salaries
reforms: openfisca_country_template.reforms.modify_social_security_taxation.modify_social_security_taxation
period: 2017-01
input_variables:
salary: 50000
output_variables:
social_security_contribution: 8336
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-Country-Template',
version='1.0.0',
version='1.1.0',
author='OpenFisca Team',
author_email='contact@openfisca.fr',
description=u'OpenFisca tax and benefit system for Country-Template',
Expand Down