From 12e0c0823d56de7505d0652b106ecb1870194464 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 21 Mar 2021 18:49:16 +0100 Subject: [PATCH 1/7] Update formula to use weeks --- openfisca_country_template/variables/benefits.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openfisca_country_template/variables/benefits.py b/openfisca_country_template/variables/benefits.py index 3703113d..2be86e39 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,7 +91,7 @@ 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" From 3ee3b9d41b8f4f1ac3a8f34649b800164e2e6458 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 11 Mar 2021 19:14:55 +0100 Subject: [PATCH 2/7] Update test to use weeks --- .../tests/situations/parenting_allowance.yaml | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/openfisca_country_template/tests/situations/parenting_allowance.yaml b/openfisca_country_template/tests/situations/parenting_allowance.yaml index bce6d594..a7956983 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: 2018-W3 absolute_error_margin: 0 input: household: @@ -13,13 +13,17 @@ Phil: birth: 1981-01-15 salary: - 2017-01: 250 - 2018-01: 250 + 2017-W1: 125 + 2017-W2: 125 + 2018-W1: 125 + 2018-W2: 125 Saz: birth: 1982-01-15 salary: - 2017-01: 250 - 2018-01: 251 + 2017-W1: 125 + 2017-W2: 125 + 2018-W1: 125 + 2018-W2: 126 Caz: birth: 2010-01-15 Eille: @@ -29,5 +33,5 @@ output: household: parenting_allowance: - 2017-01: 600 - 2018-01: 0 + 2017-W2: 600 + 2018-W2: 0 From eb2213d67486dfdbfbd96f5a44811a7e50f2ce24 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 11 Mar 2021 19:29:16 +0100 Subject: [PATCH 3/7] [TO REVERT] Use weeks branch --- Makefile | 1 + 1 file changed, 1 insertion(+) 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. From 857c0dd93038dd0268dca24e143fdb536c947e78 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Fri, 29 Jul 2022 00:37:51 +0200 Subject: [PATCH 4/7] Update test with fortnights --- .../tests/situations/parenting_allowance.yaml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/openfisca_country_template/tests/situations/parenting_allowance.yaml b/openfisca_country_template/tests/situations/parenting_allowance.yaml index a7956983..ee239e5a 100644 --- a/openfisca_country_template/tests/situations/parenting_allowance.yaml +++ b/openfisca_country_template/tests/situations/parenting_allowance.yaml @@ -3,7 +3,7 @@ - name: Parenting allowance for a two parent household with little income description: Parenting allowance relies on the fortnight incomes of the parents and ages of the children - period: 2018-W3 + period: 2022-W5 absolute_error_margin: 0 input: household: @@ -13,17 +13,13 @@ Phil: birth: 1981-01-15 salary: - 2017-W1: 125 - 2017-W2: 125 - 2018-W1: 125 - 2018-W2: 125 + week:2022-W1:2: 300 + week:2022-W3:2: 300 Saz: birth: 1982-01-15 salary: - 2017-W1: 125 - 2017-W2: 125 - 2018-W1: 125 - 2018-W2: 126 + week:2022-W1:2: 300 + week:2022-W3:2: 301 Caz: birth: 2010-01-15 Eille: @@ -33,5 +29,5 @@ output: household: parenting_allowance: - 2017-W2: 600 - 2018-W2: 0 + week:2022-W1:2: 600 + week:2022-W3:2: 0 From 6f1c4294810182ff1019353f795903c26f371cbf Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 2 Aug 2022 04:29:13 +0200 Subject: [PATCH 5/7] Update week syntax --- .../tests/situations/parenting_allowance.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/openfisca_country_template/tests/situations/parenting_allowance.yaml b/openfisca_country_template/tests/situations/parenting_allowance.yaml index ee239e5a..db873dea 100644 --- a/openfisca_country_template/tests/situations/parenting_allowance.yaml +++ b/openfisca_country_template/tests/situations/parenting_allowance.yaml @@ -3,7 +3,7 @@ - name: Parenting allowance for a two parent household with little income description: Parenting allowance relies on the fortnight incomes of the parents and ages of the children - period: 2022-W5 + period: 2022-W05 absolute_error_margin: 0 input: household: @@ -13,13 +13,13 @@ Phil: birth: 1981-01-15 salary: - week:2022-W1:2: 300 - week:2022-W3:2: 300 + week:2022-W01:2: 300 + week:2022-W03:2: 300 Saz: birth: 1982-01-15 salary: - week:2022-W1:2: 300 - week:2022-W3:2: 301 + week:2022-W01:2: 300 + week:2022-W03:2: 301 Caz: birth: 2010-01-15 Eille: @@ -29,5 +29,5 @@ output: household: parenting_allowance: - week:2022-W1:2: 600 - week:2022-W3:2: 0 + week:2022-W01:2: 600 + week:2022-W03:2: 0 From ccb37cc3846a9c98483b21ede702948646307ea0 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 2 Aug 2022 06:40:50 +0200 Subject: [PATCH 6/7] Finish implementation --- .../tests/situations/parenting_allowance.yaml | 18 ++++++++-------- .../variables/benefits.py | 21 +++++++++++++++---- .../variables/income.py | 12 ++++++++++- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/openfisca_country_template/tests/situations/parenting_allowance.yaml b/openfisca_country_template/tests/situations/parenting_allowance.yaml index db873dea..d0ffe448 100644 --- a/openfisca_country_template/tests/situations/parenting_allowance.yaml +++ b/openfisca_country_template/tests/situations/parenting_allowance.yaml @@ -3,7 +3,7 @@ - name: Parenting allowance for a two parent household with little income description: Parenting allowance relies on the fortnight incomes of the parents and ages of the children - period: 2022-W05 + period: 2022 absolute_error_margin: 0 input: household: @@ -12,14 +12,14 @@ persons: Phil: birth: 1981-01-15 - salary: - week:2022-W01:2: 300 - week:2022-W03:2: 300 + weekly_salary: + week:2022-W01:2: 250 + week:2022-W03:2: 250 Saz: birth: 1982-01-15 - salary: - week:2022-W01:2: 300 - week:2022-W03:2: 301 + 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: - week:2022-W01:2: 600 - week:2022-W03:2: 0 + 2022-W03: 600 + 2022-W05: 0 diff --git a/openfisca_country_template/variables/benefits.py b/openfisca_country_template/variables/benefits.py index 2be86e39..f00258d1 100644 --- a/openfisca_country_template/variables/benefits.py +++ b/openfisca_country_template/variables/benefits.py @@ -97,8 +97,7 @@ class parenting_allowance(Variable): 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,14 @@ def formula(household, period, parameters): """ parenting_allowance = parameters(period).benefits.parenting_allowance - household_income = household("household_income", period) + income_last_fortnight = household("household_weekly_income", period.last_fortnight) + income_last_week = household("household_weekly_income", period.last_week) + household_income = income_last_fortnight + income_last_week 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 +133,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 From bd7a637ad6022a7496fe50bcb1a1080b264f4220 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 2 Aug 2022 06:54:49 +0200 Subject: [PATCH 7/7] Use options add --- openfisca_country_template/variables/benefits.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/openfisca_country_template/variables/benefits.py b/openfisca_country_template/variables/benefits.py index f00258d1..56525665 100644 --- a/openfisca_country_template/variables/benefits.py +++ b/openfisca_country_template/variables/benefits.py @@ -106,9 +106,7 @@ def formula(household, period, parameters): """ parenting_allowance = parameters(period).benefits.parenting_allowance - income_last_fortnight = household("household_weekly_income", period.last_fortnight) - income_last_week = household("household_weekly_income", period.last_week) - household_income = income_last_fortnight + income_last_week + household_income = household("household_weekly_income", period.last_2_weeks, options = ["add"]) income_threshold = parenting_allowance.income_threshold income_condition = household_income <= income_threshold