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

Premiers ajouts #1

Merged
merged 22 commits into from
Jul 30, 2024
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
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Thanks for contributing to OpenFisca ! Please remove this line, as well as, for

These changes _(remove lines which are not relevant to your contribution)_:

- Impact the OpenFisca-France Firms public API (for instance renaming or removing a variable)
- Impact the OpenFisca-France UniteLegales public API (for instance renaming or removing a variable)
- Add a new feature (for instance adding a variable)
- Fix or improve an already existing calculation.
- Change non-functional parts of this repository (for instance editing the README)
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 1.0.0 - [#1](https://github.com/pzuldp/openfisca-france-firms/pull/1)

* Tax and benefit system evolution.
* Impacted periods: all.
* Impacted areas: all
* Details:
- Adaptation du template avec la création des entités UniteLegale et Etablissement
- Création du bilan et de ses variables
- Création du compte de résultat et de ses variables
- Création des TICC et TICGN
- Premiers tests

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

Expand Down
8 changes: 4 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.

A secondary benefit of defending all users' freedom is that
A secondaire benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
Expand Down Expand Up @@ -143,7 +143,7 @@ same work.

All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
conditions are met. This License explicitly afunite_legales your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
Expand Down Expand Up @@ -284,7 +284,7 @@ included in conveying the object code work.

A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
or unite_legale purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
Expand Down Expand Up @@ -449,7 +449,7 @@ Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.

You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
rights granted or afunite_legaleed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OpenFisca France Firms
# OpenFisca France UniteLegales


The country whose law is modelled here has a very simple tax and benefit system.
Expand Down
4 changes: 2 additions & 2 deletions openfisca_france_firms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self):

# We define which variable, parameter and simulation example will be used in the OpenAPI specification
self.open_api_config = {
"variable_example": "disposable_income",
"parameter_example": "taxes.income_tax_rate",
"variable_example": "example_disposable_income",
"parameter_example": "example_taxes.example_income_tax_rate_flat",
"simulation_example": couple,
}
58 changes: 26 additions & 32 deletions openfisca_france_firms/entities.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,58 @@
"""
This file defines the entities needed by our legislation.

Taxes and benefits can be calculated for different entities: persons, household, companies, etc.
Taxes and benefits can be calculated for different entities: etablissements, unite_legale, companies, etc.

See https://openfisca.org/doc/key-concepts/person,_entities,_role.html
See https://openfisca.org/doc/key-concepts/etablissement,_entities,_role.html
"""

from openfisca_core.entities import build_entity

Household = build_entity(
key = "household",
plural = "households",
label = "All the people in a family or group who live together in the same place.",
UniteLegale = build_entity(
key = "unite_legale",
plural = "unite_legales",
label = "All the etablissements in a legal unit defined by a SIREN.",
doc = """
Household is an example of a group entity.
A group entity contains one or more individual·s.
Each individual in a group entity has a role (e.g. parent or children). Some roles can only be held by a limited number of individuals (e.g. a 'first_parent' can only be held by one individual), while others can have an unlimited number of individuals (e.g. 'children').

Example:
Housing variables (e.g. housing_tax') are usually defined for a group entity such as 'Household'.
A unite_legale entity contains one or more etablissements.
Each etablissement in a unite_legale has a role (e.g. siege_social or secondaire etablissement). There can only be one siege_social etablissement.

Usage:
Check the number of individuals of a specific role (e.g. check if there is a 'second_parent' with household.nb_persons(Household.SECOND_PARENT)).
Calculate a variable applied to each individual of the group entity (e.g. calculate the 'salary' of each member of the 'Household' with salaries = household.members("salary", period = MONTH); sum_salaries = household.sum(salaries)).
Check the number of etablissements of a specific role (e.g. check if there is a unique 'siege_social' etablissement within a unite_legale).

For more information, see: https://openfisca.org/doc/coding-the-legislation/50_entities.html
""",
roles = [
{
"key": "parent",
"plural": "parents",
"label": "Parents",
"max": 2,
"subroles": ["first_parent", "second_parent"],
"doc": "The one or two adults in charge of the household.",
"key": "siege_social",
"plural": "siege_social",
"label": "Siege Social",
"max": 1,
"doc": "The one etablissement that is siege_social to the unite_legale.",
},
{
"key": "child",
"plural": "children",
"label": "Child",
"doc": "Other individuals living in the household.",
"key": "secondaire",
"plural": "secondaires",
"label": "Etablissements secondaires",
"doc": "Other etablissements in the unite_legale.",
},
],
)

Person = build_entity(
key = "person",
plural = "persons",
label = "An individual. The minimal legal entity on which a legislation might be applied.",
Etablissement = build_entity(
key = "etablissement",
plural = "etablissements",
label = "An etablissement. The minimal legal entity on which a legislation might be applied.",
doc = """

Variables like 'salary' and 'income_tax' are usually defined for the entity 'Person'.
Variables like 'masse_salariale' and 'consommation_energie' are usually defined for the entity 'Etablissement'.

Usage:
Calculate a variable applied to a 'Person' (e.g. access the 'salary' of a specific month with person("salary", "2017-05")).
Check the role of a 'Person' in a group entity (e.g. check if a the 'Person' is a 'first_parent' in a 'Household' entity with person.has_role(Household.FIRST_PARENT)).
Calculate a variable applied to a 'Etablissement' (e.g. access the 'example_salary' of a specific month with etablissement("example_salary", "2017-05")).
Check the role of a 'Etablissement' in a group entity (e.g. check if a the 'Etablissement' is a 'siege_social' in a 'unite_legale' entity with etablissement.has_role(unite_legale.SIEGE_SOCIAL)).

For more information, see: https://openfisca.org/doc/coding-the-legislation/50_entities.html
""",
is_person = True,
)

entities = [Household, Person]
entities = [UniteLegale, Etablissement]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description: Parenting allowance amount
metadata:
reference: https://law.gov.example/parenting_allowance/amount
reference: https://law.gov.example/example_parenting_allowance/amount
unit: currency-EUR
values:
# This parameter is only defined since the 1st of Dec 2015.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description: Parenting allowance income threshold
metadata:
reference: https://law.gov.example/parenting_allowance/income_threshold
reference: https://law.gov.example/example_parenting_allowance/income_threshold
unit: currency-EUR
values:
# This parameter is only defined since the 1st of Dec 2015.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
description: Natural gas consumption rate
values:
# This parameter is only defined since the 1st of Dec 2015.
2000-01-01:
value: 0.02
metadata:
reference:
2000-01-01:
href: https://law.gov.example/basic-income/amount/2015-12
15 changes: 0 additions & 15 deletions openfisca_france_firms/parameters/taxes/housing_tax.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from openfisca_core.variables import Variable

# Import the Entities specifically defined for this tax and benefit system
from openfisca_france_firms.entities import Person
from openfisca_france_firms.entities import Etablissement


def create_dynamic_variable(name, **variable):
Expand Down Expand Up @@ -40,13 +40,13 @@ def apply(self):
See https://openfisca.org/doc/coding-the-legislation/reforms.html#writing-a-reform
"""
NewVariable = create_dynamic_variable(
name = "goes_to_school",
name = "is_euets",
value_type = bool,
entity = Person,
entity = Etablissement,
default_value = True,
definition_period = MONTH,
label = "The person goes to school (only relevant for children)",
reference = "https://law.gov.example/goes_to_school",
label = "The etablissement is subject to EUETS",
reference = "https://law.gov.example/is_euets",
)

self.add_variable(NewVariable)
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,36 @@
from openfisca_core.variables import Variable

# Import the Entities specifically defined for this tax and benefit system
from openfisca_france_firms.entities import Person
from openfisca_france_firms.entities import Etablissement


class has_car(Variable):
value_type = bool
entity = Person
entity = Etablissement
default_value = True
definition_period = MONTH
label = "The person has a car"
label = "The etablissement has a car"
reference = "https://law.gov.example/new_tax" # Always use the most official source


class new_tax(Variable):
value_type = float
entity = Person
entity = Etablissement
definition_period = MONTH
label = "New tax"
reference = "https://law.gov.example/new_tax" # Always use the most official source

def formula(person, period, _parameters):
def formula(etablissement, period, _parameters):
"""
New tax reform.

Our reform adds a new variable `new_tax` that is calculated based on
the current `income_tax`, if the person has a car.
the current `income_tax`, if the etablissement has a car.
"""
income_tax = person("income_tax", period)
has_car = person("has_car", period)
example_income_tax_flat = etablissement("example_income_tax_flat", period)
has_car = etablissement("has_car", period)

return (income_tax + 100.0) * has_car
return (example_income_tax_flat + 100.0) * has_car


class add_new_tax(Reform):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
from openfisca_core.variables import Variable


class social_security_contribution(Variable):
class example_income_tax_flat(Variable):
# Variable metadata don't need to be redefined. By default, the reference variable metadatas will be used.

def formula(person, period, _parameters):
def formula(etablissement, period, _parameters):
"""
Social security contribution reform.

Our reform replaces `social_security_contribution` (the "reference" variable) by the following variable.
Our reform replaces `income_tax_flat` (the "reference" variable) by the following variable.
"""
return person("salary", period) * 0.03
return etablissement("example_salary", period) * 0.03


class flat_social_security_contribution(Reform):
class example_flatten_income_tax(Reform):
def apply(self):
"""
Apply reform.

A reform always defines an `apply` method that builds the reformed tax and benefit system from the reference one.
See https://openfisca.org/doc/coding-the-legislation/reforms.html#writing-a-reform
"""
self.update_variable(social_security_contribution)
self.update_variable(example_income_tax_flat)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from openfisca_core.reforms import Reform


class modify_social_security_taxation(Reform):
class modify_income_tax_progressive(Reform):
def apply(self):
"""
Apply reform.
Expand All @@ -35,7 +35,7 @@ def modify_brackets(parameters):
of the YAML parameters. It can be modified and must be returned.
"""
# Access the right parameter node:
brackets = parameters.taxes.social_security_contribution.brackets
brackets = parameters.example_taxes.example_income_tax_rate_progressive.brackets

# Add 0.1 to the rates of the second bracket, keeping the same thresholds:
for rate in brackets[1].rate.values_list:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from openfisca_core.reforms import Reform


class removal_basic_income(Reform):
class removal_example_basic_income(Reform):
def apply(self):
"""
Apply reform.

A reform always defines an `apply` method that builds the reformed tax and benefit system from the reference one.
See https://openfisca.org/doc/coding-the-legislation/reforms.html#writing-a-reform

Our reform neutralizes the `basic_income` variable. When this reform is applied, calculating `basic_income` will always return its default value, 0.
Our reform neutralizes the `example_basic_income` variable. When this reform is applied, calculating `example_basic_income` will always return its default value, 0.
"""
self.neutralize_variable("basic_income")
self.neutralize_variable("example_basic_income")
19 changes: 10 additions & 9 deletions openfisca_france_firms/situation_examples/couple.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
{
"persons": {
"etablissements": {
"Alicia": {
"birth": {
"example_birth": {
"ETERNITY": "1980-01-01"
},
"salary": {
"example_salary": {
"2017-01": 4000
},
"disposable_income": {
"example_disposable_income": {
"2017-01": null
}
},
"Javier": {
"birth": {
"example_birth": {
"ETERNITY": "1984-01-01"
},
"salary": {
"example_salary": {
"2017-01": 2500
},
"disposable_income": {
"example_disposable_income": {
"2017-01": null
}
}
},
"households": {
"unite_legales": {
"_": {
"parents": ["Alicia", "Javier"],
"siege_social": ["Alicia"],
"secondaires" : ["Javier"],
"total_benefits": {
"2017-01": null
},
Expand Down
Loading
Loading