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 wombat COVID rules to OpenFisca #191

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ clean:
find . -name '*.pyc' -exec rm \{\} \;

test:
openfisca-run-test --country-package openfisca_aotearoa openfisca_aotearoa/tests
openfisca test --country-package openfisca_aotearoa openfisca_aotearoa/tests
32 changes: 31 additions & 1 deletion openfisca_aotearoa/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,34 @@
]
)

entities = [Titled_Property, Person, Family]
Business = build_entity(
key="business",
plural="businesses",
label=u'business',
doc='''
This term includes:
self-employed and sole traders
contractors
incorporated societies
registered charities
Non-government organisations (NGOs)
and post-settlement governance entities.
''',

roles = [
mermop marked this conversation as resolved.
Show resolved Hide resolved
mermop marked this conversation as resolved.
Show resolved Hide resolved
{
'key': 'business owner',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it a bit strange to have a space in this key?

'plural': 'business owners',
'label': u'Business owner',
'doc': u'The one or more persons who are owners of the business.'
},
{
'key': 'other',
'plural': 'others',
'label': u'Others',
'doc': u'People who are not in any other role'
}
]
)

entities = [Titled_Property, Person, Family, Business]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
- name: Sole trader, eligible for wage subsidy
Copy link
Contributor Author

@mermop mermop May 4, 2020

Choose a reason for hiding this comment

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

These tests are both failing in CI - with the errors:

AssertionError: In test 'Sole trader, does not have IRD number, not eligible for wage subsidy', in file '/root/project/openfisca_aotearoa/tests/social_security/covid_19_wage_subsidy.yaml', covid_19_wage_subsidy__eligibility@2020-6: [0.] differs from 1.0 with an absolute margin [1.] > 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As below - some debugging with @JacOng17 reveals that it's because of the missing located_in_NZ parameter. If you make those changes, the tests should pass @asgharkazi @sarafalamaki

period: 2020-6
input:
sole_trader_operates_business: True
sole_trader_has_IRD_number: True
sole_trader_has_applicable_licenses: True
qualifications_or_registration_for_trade: True
registered_in_NZ: True
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
registered_in_NZ: True
registered_in_NZ: True
located_in_NZ: True

employees_legally_work_in_NZ: True
decline_in_business_revenue_due_to_covid_19: True
already_applied_for_wage_subsidy: False
output:
covid_19_wage_subsidy__eligibility: True
- name: Sole trader, does not have IRD number, not eligible for wage subsidy
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests here don't seem to match the name - have made suggestions on the relevant lines

period: 2020-6
input:
sole_trader_operates_business: True
sole_trader_has_IRD_number: True
sarafalamaki marked this conversation as resolved.
Show resolved Hide resolved
sole_trader_has_applicable_licenses: True
qualifications_or_registration_for_trade: True
registered_in_NZ: True
sarafalamaki marked this conversation as resolved.
Show resolved Hide resolved
employees_legally_work_in_NZ: True
decline_in_business_revenue_due_to_covid_19: True
already_applied_for_wage_subsidy: False
output:
covid_19_wage_subsidy__eligibility: True
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
covid_19_wage_subsidy__eligibility: True
covid_19_wage_subsidy__eligibility: False

101 changes: 101 additions & 0 deletions openfisca_aotearoa/variables/acts/wage_subsidy_covid_19/eligibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
from openfisca_core.model_api import *
from openfisca_aotearoa.entities import Business


class registered_in_NZ(Variable):
value_type = bool
entity = Business
definition_period = MONTH
label = u"Is the business registered with the New Zealand Companies Office?"
reference = "https://workandincome.govt.nz/products/a-z-benefits/covid-19-support.html"


class located_in_NZ(Variable):
value_type = bool
entity = Business
definition_period = MONTH
label = u"Is the business physically located and operates in NZ?"
reference = "https://workandincome.govt.nz/products/a-z-benefits/covid-19-support.html"


class sole_trader_operates_business(Variable):
value_type = bool
entity = Business
definition_period = MONTH
label = u"Is the person a sole trader?"
reference = "https://workandincome.govt.nz/products/a-z-benefits/covid-19-support.html"


class sole_trader_has_IRD_number(Variable):
value_type = bool
entity = Business
definition_period = MONTH
label = u"Does the person have a personal IRD number used for paying income tax and GST?"
reference = "https://workandincome.govt.nz/products/a-z-benefits/covid-19-support.html"


class sole_trader_has_applicable_licenses(Variable):
value_type = bool
entity = Business
definition_period = MONTH
label = u"Does the sole trader have applicable licenses and permits for their business needs?"
reference = "https://workandincome.govt.nz/products/a-z-benefits/covid-19-support.html"


class qualifications_or_registration_for_trade(Variable):
value_type = bool
entity = Business
definition_period = MONTH
label = u"Does the sole trader have qualifications or registrations for their trade or profession?"
reference = "https://workandincome.govt.nz/products/a-z-benefits/covid-19-support.html"


class employees_legally_work_in_NZ(Variable):
value_type = bool
entity = Business
definition_period = MONTH
label = u"Are all the named employees legally entitled to work in NZ?"
'''Legally working in New Zealand means a person is both working in New Zealand and is legally entitled to work in New Zealand. A person is legally entitled to work in New Zealand if they:
are a New Zealand or Australian citizen (including a person born in the Cook Islands, Niue or Tokelau), or
have a New Zealand residence class visa, or
have a New Zealand work visa or a condition on their New Zealand temporary visa that allows them to work in New Zealand.'''
reference = "https://workandincome.govt.nz/products/a-z-benefits/covid-19-support.html"


class decline_in_business_revenue_due_to_covid_19(Variable):
value_type = bool
entity = Business
definition_period = MONTH
label = u"Has the business observed in actual or predicted (due to reduction in bookings, etc) revenue by more than 30% due to COVID-19?"
''' The business must experience this decline between January 2020 and 9 June 2020.'''
reference = "https://workandincome.govt.nz/products/a-z-benefits/covid-19-support.html"


class already_applied_for_wage_subsidy(Variable):
value_type = bool
entity = Business
definition_period = MONTH
label = u"Has the business already applied for a wage subsidy?"


class covid_19_wage_subsidy__eligibility(Variable):
value_type = bool
entity = Business
definition_period = MONTH
label = u"Conditions for checking eligibility for wage subsidy"
reference = "https://workandincome.govt.nz/products/a-z-benefits/covid-19-support.html"

def formula(business, period, parameters):
conditions_for_sole_traders = business('sole_trader_has_IRD_number', period) \
* business('sole_trader_has_applicable_licenses', period) \
* business('qualifications_or_registration_for_trade', period)

conditions_for_all_businesses = business('registered_in_NZ', period) \
* business('located_in_NZ', period) \
* business('employees_legally_work_in_NZ', period) \
* business('decline_in_business_revenue_due_to_covid_19', period) \
* not_(business('already_applied_for_wage_subsidy', period))

return conditions_for_all_businesses \
* (business('sole_trader_operates_business', period) * conditions_for_sole_traders) \
+ (not_(business('sole_trader_operates_business', period)))