diff --git a/Makefile b/Makefile index 86f94f54..09cbf1b7 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ install: deps @# `make install` installs the editable version of OpenFisca-France. @# This allows contributors to test as they code. pip install -e '.[dev]' --upgrade --use-deprecated=legacy-resolver + pip install --editable git+https://github.com/openfisca/openfisca-core.git@add-weeks#egg=OpenFisca-Core[web-api] # use a specific branch of OpenFisca-Core build: clean deps @# Install OpenFisca-Extension-Template for deployment and publishing. diff --git a/openfisca_country_template/tests/situations/parenting_allowance.yaml b/openfisca_country_template/tests/situations/parenting_allowance.yaml index bce6d594..d0ffe448 100644 --- a/openfisca_country_template/tests/situations/parenting_allowance.yaml +++ b/openfisca_country_template/tests/situations/parenting_allowance.yaml @@ -2,8 +2,8 @@ # We can run this test on our command line using `openfisca-run-test tests/situations/income_tax.yaml` - name: Parenting allowance for a two parent household with little income - description: Parenting allowance relies on the incomes on the parents and ages of the children - period: 2020-01 + description: Parenting allowance relies on the fortnight incomes of the parents and ages of the children + period: 2022 absolute_error_margin: 0 input: household: @@ -12,14 +12,14 @@ persons: Phil: birth: 1981-01-15 - salary: - 2017-01: 250 - 2018-01: 250 + weekly_salary: + week:2022-W01:2: 250 + week:2022-W03:2: 250 Saz: birth: 1982-01-15 - salary: - 2017-01: 250 - 2018-01: 251 + weekly_salary: + week:2022-W01:2: 250 + week:2022-W03:2: 251 Caz: birth: 2010-01-15 Eille: @@ -29,5 +29,5 @@ output: household: parenting_allowance: - 2017-01: 600 - 2018-01: 0 + 2022-W03: 600 + 2022-W05: 0 diff --git a/openfisca_country_template/variables/benefits.py b/openfisca_country_template/variables/benefits.py index 3703113d..56525665 100644 --- a/openfisca_country_template/variables/benefits.py +++ b/openfisca_country_template/variables/benefits.py @@ -7,7 +7,7 @@ """ # Import from openfisca-core the Python objects used to code the legislation in OpenFisca -from openfisca_core.periods import MONTH +from openfisca_core.periods import MONTH, WEEK from openfisca_core.variables import Variable # Import the Entities specifically defined for this tax and benefit system @@ -91,14 +91,13 @@ def formula(person, period, parameters): class parenting_allowance(Variable): value_type = float entity = Household - definition_period = MONTH + definition_period = WEEK label = "Allowance for low income people with children to care for." documentation = "Loosely based on the Australian parenting pension." reference = "https://www.servicesaustralia.gov.au/individuals/services/centrelink/parenting-payment/who-can-get-it" def formula(household, period, parameters): - """ - Parenting allowance for households. + """Parenting allowance for households. A person's parenting allowance depends on how many dependents they have, how much they, and their partner, earn @@ -107,12 +106,12 @@ def formula(household, period, parameters): """ parenting_allowance = parameters(period).benefits.parenting_allowance - household_income = household("household_income", period) + household_income = household("household_weekly_income", period.last_2_weeks, options = ["add"]) income_threshold = parenting_allowance.income_threshold income_condition = household_income <= income_threshold is_single = household.nb_persons(Household.PARENT) == 1 - ages = household.members("age", period) + ages = household.members("age", period.first_month) under_8 = household.any(ages < 8) under_6 = household.any(ages < 6) @@ -132,3 +131,15 @@ def formula(household, period, _parameters): """A household's income.""" salaries = household.members("salary", period) return household.sum(salaries) + + +class household_weekly_income(Variable): + value_type = float + entity = Household + definition_period = WEEK + label = "The sum of the salaries of those living in a household" + + def formula(household, period, _parameters): + """A household's income.""" + salaries = household.members("weekly_salary", period) + return household.sum(salaries) diff --git a/openfisca_country_template/variables/income.py b/openfisca_country_template/variables/income.py index 1b48144c..899c56ec 100644 --- a/openfisca_country_template/variables/income.py +++ b/openfisca_country_template/variables/income.py @@ -8,7 +8,7 @@ # Import from openfisca-core the Python objects used to code the legislation in OpenFisca from openfisca_core.holders import set_input_divide_by_period -from openfisca_core.periods import MONTH +from openfisca_core.periods import MONTH, WEEK from openfisca_core.variables import Variable # Import the Entities specifically defined for this tax and benefit system @@ -25,6 +25,16 @@ class salary(Variable): reference = "https://law.gov.example/salary" # Always use the most official source +# This variable is also a pure input, but with a different definition period +class weekly_salary(Variable): + value_type = float + entity = Person + definition_period = WEEK + set_input = set_input_divide_by_period # Optional attribute. Allows user to declare a salary for a week. OpenFisca will then multiply the weekly amount over the weeks requested. + label = "Weekly Salary" + reference = "https://law.another-gov.example/salary" # Always use the most official source (and https) + + class disposable_income(Variable): value_type = float entity = Person