Skip to content

Commit

Permalink
Change GYR filing years to calculate valid filing years precisely (#4629
Browse files Browse the repository at this point in the history
)

Co-authored-by: Jenny Heath <[email protected]>
  • Loading branch information
mrotondo and jenny-heath authored Aug 12, 2024
1 parent 3ef9b52 commit bd78afa
Show file tree
Hide file tree
Showing 25 changed files with 223 additions and 118 deletions.
15 changes: 15 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,21 @@ def post_deadline_withdrawal_date(state_code)
end
helper_method :post_deadline_withdrawal_date

def gyr_filing_years
MultiTenantService.gyr.filing_years(app_time)
end
helper_method :gyr_filing_years

def gyr_backtax_years
MultiTenantService.gyr.backtax_years(app_time)
end
helper_method :gyr_backtax_years

def client_has_return_for_every_gyr_filing_year?(client)
(gyr_filing_years - client.tax_returns.pluck(:year)).empty?
end
helper_method :client_has_return_for_every_gyr_filing_year?

def state_code_for_page_style
if params.include?(:us_state)
params[:us_state]
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/hub/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def index

def new
@current_year = MultiTenantService.new(:gyr).current_tax_year
@form = CreateClientForm.new
@form = CreateClientForm.new(gyr_filing_years)
end

def create
@current_year = MultiTenantService.new(:gyr).current_tax_year
@form = CreateClientForm.new(create_client_form_params)
@form = CreateClientForm.new(gyr_filing_years, create_client_form_params)
assigned_vita_partner = @vita_partners.find_by(id: create_client_form_params["vita_partner_id"])

if can?(:read, assigned_vita_partner) && @form.save(current_user)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/hub/tax_returns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TaxReturnsController < Hub::BaseController

def new
redirect_to hub_client_path(@client.id) unless @client.intake
@form = TaxReturnForm.new(@client)
@form = TaxReturnForm.new(@client, gyr_filing_years)
@tax_return = @form.tax_return

if @form.remaining_years.blank?
Expand All @@ -23,7 +23,7 @@ def new
end

def create
@form = TaxReturnForm.new(@client, tax_return_params)
@form = TaxReturnForm.new(@client, gyr_filing_years, tax_return_params)
@tax_return = @form.tax_return
if @form.valid?
@form.save
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/questions/backtaxes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Questions
class BacktaxesController < QuestionsController
include AnonymousIntakeConcern
before_action :load_possible_filing_years, only: [:edit, :update]
layout "intake"

private
Expand All @@ -10,8 +9,5 @@ def illustration_path
"calendar.svg"
end

def load_possible_filing_years
@possible_filing_years = MultiTenantService.new(:gyr).filing_years
end
end
end
24 changes: 20 additions & 4 deletions app/forms/hub/create_client_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,25 @@ class CreateClientForm < ClientForm
validates_presence_of :primary_ssn_confirmation, if: :primary_ssn
validates_presence_of :spouse_ssn_confirmation, if: :spouse_ssn
validates :primary_ssn, social_security_number: true, if: -> { ["ssn", "ssn_no_employment"].include? primary_tin_type }
validates :primary_ssn, individual_taxpayer_identification_number: true, if: -> { primary_tin_type == "itin"}
validates :primary_ssn, individual_taxpayer_identification_number: true, if: -> { primary_tin_type == "itin" }
validates_confirmation_of :spouse_ssn, if: -> { filing_joint == "yes" }
validates :spouse_ssn, social_security_number: true, if: -> { ["ssn", "ssn_no_employment"].include?(spouse_tin_type) && filing_joint == "yes"}
validates :spouse_ssn, social_security_number: true, if: -> { ["ssn", "ssn_no_employment"].include?(spouse_tin_type) && filing_joint == "yes" }
validates :spouse_ssn, individual_taxpayer_identification_number: true, if: -> { spouse_tin_type == "itin" && filing_joint == "yes" }

def initialize(attributes = {})
@tax_returns = MultiTenantService.new(:gyr).filing_years.map { |year| TaxReturn.new(year: year) }
def initialize(gyr_filing_years, attributes = {})
@gyr_filing_years = gyr_filing_years
@tax_returns = selectable_years.map { |year| TaxReturn.new(year: year) }
super(attributes)
end

def save(current_user)
return false unless valid?

# Default to no, since some may be nil if there were less than 3 previous years displayed on the form
self.needs_help_previous_year_1 ||= "no"
self.needs_help_previous_year_2 ||= "no"
self.needs_help_previous_year_3 ||= "no"

@client = Client.create!(
vita_partner_id: attributes_for(:intake)[:vita_partner_id],
intake_attributes: attributes_for(:intake).merge(default_intake_attributes),
Expand Down Expand Up @@ -105,6 +112,15 @@ def self.permitted_params

private

def selectable_years
# Ensure that hub users can select current_tax_year - 3, regardless of whether it's past its filing deadline
years = @gyr_filing_years
if years.count < 4
years += [years[-1] - 1]
end
years
end

def default_intake_attributes
{
type: "Intake::GyrIntake",
Expand Down
5 changes: 3 additions & 2 deletions app/forms/hub/tax_return_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ class TaxReturnForm < Form
validates :current_state, presence: true
validates :year, presence: true

def initialize(client, params={})
def initialize(client, gyr_filing_years, params={})
@client = client
super(params)
@service_type ||= client.tax_returns.pluck(:service_type).include?("drop_off") ? "drop_off" : "online_intake"
@current_state ||= "intake_in_progress"
@tax_return = @client.tax_returns.new
@gyr_filing_years = gyr_filing_years
end

def save
Expand All @@ -36,7 +37,7 @@ def tax_return_years
end

def remaining_years
MultiTenantService.new(:gyr).filing_years - tax_return_years
@gyr_filing_years - tax_return_years
end
end
end
10 changes: 6 additions & 4 deletions app/services/multi_tenant_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,18 @@ def prior_tax_year
current_tax_year - 1
end

def filing_years
def filing_years(now = DateTime.now)
if service_type == :ctc || service_type == :state_file
[current_tax_year]
else
((current_tax_year - 3)..current_tax_year).to_a.reverse.freeze
Rails.configuration.tax_year_filing_seasons.select do |_, (season_start, deadline)|
deadline > now - 3.years && season_start <= now
end.keys.freeze
end
end

def backtax_years
filing_years.without(current_tax_year)
def backtax_years(now = DateTime.now)
filing_years(now).without(current_tax_year)
end

class << self
Expand Down
13 changes: 8 additions & 5 deletions app/views/questions/backtaxes/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
<%=t("views.questions.backtaxes.select_all_that_apply") %>
</p>
<div class="form-card__stacked-checkboxes spacing-above-0">
<% if app_time.before?(Rails.configuration.tax_deadline) %>
<%= f.cfa_checkbox("needs_help_previous_year_3".to_sym, @possible_filing_years[3].to_s, options: { checked_value: "yes", unchecked_value: "no" }) %>
<% gyr_backtax_years.reverse.each do |backtax_year| %>
<% previous_year_index = MultiTenantService.gyr.current_tax_year - backtax_year %>
<%= f.cfa_checkbox("needs_help_previous_year_#{previous_year_index}".to_sym,
backtax_year.to_s,
options: { checked_value: "yes", unchecked_value: "no" }) %>
<% end %>
<%= f.cfa_checkbox("needs_help_previous_year_2".to_sym, @possible_filing_years[2].to_s, options: { checked_value: "yes", unchecked_value: "no" }) %>
<%= f.cfa_checkbox("needs_help_previous_year_1".to_sym, @possible_filing_years[1].to_s, options: { checked_value: "yes", unchecked_value: "no" }) %>
<%= f.cfa_checkbox("needs_help_current_year".to_sym, @possible_filing_years[0].to_s, options: { checked_value: "yes", unchecked_value: "no" }) %>
<%= f.cfa_checkbox("needs_help_current_year".to_sym,
MultiTenantService.gyr.current_tax_year.to_s,
options: { checked_value: "yes", unchecked_value: "no" }) %>
</div>

<%= f.continue %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/questions/triage/_gyr_tile.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="bottom-section">
<div>
<ul class="list--bulleted">
<% filing_years = MultiTenantService.new(:gyr).filing_years %>
<% filing_years = gyr_filing_years %>
<li><%= t('.list.file', oldest_filing_year: filing_years.last, current_tax_year: filing_years.first) %></li>
<li><%= t('.list.income') %></li>
<li><%= t('.list.ssn') %></li>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_client_filters.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<div class="form-group">
<label for="year" class="form-question"><%= t("hub.clients.index.filing_year").humanize %></label>
<div class="select">
<%= select_tag :year, options_for_select(MultiTenantService.new(:gyr).filing_years, filters[:year]), include_blank: true, class: "select__element" %>
<%= select_tag :year, options_for_select(gyr_filing_years, filters[:year]), include_blank: true, class: "select__element" %>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_service_comparison.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
</div>
<div class="service-set__services">
<div class="service full-service">
<%= MultiTenantService.new(:gyr).filing_years.last %>-<%= MultiTenantService.new(:gyr).filing_years.first %>
<%= gyr_filing_years.last %>-<%= gyr_filing_years.first %>
</div>
<div class="service diy">
<%= MultiTenantService.new(:gyr).current_tax_year %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_tax_return_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<% end %>
</li>
<% end %>
<% if tax_return_creatable && client.tax_returns.pluck(:year).sort != MultiTenantService.new(:gyr).filing_years.sort %>
<% if tax_return_creatable && !client_has_return_for_every_gyr_filing_year?(client) %>
<%= link_to t("views.shared.tax_return_list.add_tax_year"), new_hub_client_tax_return_path(client_id: client.id), class: "button button--small" %>
<% end %>
</ul>
55 changes: 35 additions & 20 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,47 @@ class Application < Rails::Application
config.statefile_current_tax_year = 2023
config.product_year = 2024

pt = Time.find_zone('America/Los_Angeles')
et = Time.find_zone('America/New_York')

# These defaults can be overridden per-environment if needed
# GetYourRefund
config.start_of_unique_links_only_intake = Time.find_zone('America/Los_Angeles').parse('2024-01-24 12:00:00')
config.start_of_open_intake = Time.find_zone('America/Los_Angeles').parse('2024-01-31 09:59:59')
config.tax_deadline = Time.find_zone('America/New_York').parse('2024-04-15 23:59:59')
config.end_of_intake = Time.find_zone('America/New_York').parse('2024-10-01 23:59:59')
config.end_of_docs = Time.find_zone('America/New_York').parse('2024-10-08 23:59:59')
config.doc_submission_deadline = Time.find_zone('America/New_York').parse('2024-04-01 23:59:59')
config.end_of_closing = Time.find_zone('America/New_York').parse('2024-10-15 23:59:59')
config.end_of_in_progress_intake = Time.find_zone('America/New_York').parse('2024-10-16 23:59:59')
config.end_of_login = Time.find_zone('America/New_York').parse('2024-10-23 23:59:00')
config.start_of_unique_links_only_intake = pt.parse('2024-01-24 12:00:00')
config.start_of_open_intake = pt.parse('2024-01-31 09:59:59')
config.tax_deadline = et.parse('2024-04-15 23:59:59')
config.end_of_intake = et.parse('2024-10-01 23:59:59')
config.end_of_docs = et.parse('2024-10-08 23:59:59')
config.doc_submission_deadline = et.parse('2024-04-01 23:59:59')
config.end_of_closing = et.parse('2024-10-15 23:59:59')
config.end_of_in_progress_intake = et.parse('2024-10-16 23:59:59')
config.end_of_login = et.parse('2024-10-23 23:59:00')

config.tax_year_filing_seasons = {
2023 => [et.parse("2024-01-29 00:00:00"), et.parse("2024-04-15 23:59:59")],
2022 => [et.parse("2023-01-23 00:00:00"), et.parse("2023-04-18 23:59:59")],
2021 => [et.parse("2022-01-24 00:00:00"), et.parse("2022-04-18 23:59:59")],
2020 => [et.parse("2021-02-12 00:00:00"), et.parse("2021-05-17 23:59:59")],
2019 => [et.parse("2020-01-27 00:00:00"), et.parse("2020-07-15 23:59:59")],
2018 => [et.parse("2019-01-28 00:00:00"), et.parse("2019-04-15 23:59:59")],
2017 => [et.parse("2018-01-29 00:00:00"), et.parse("2018-04-17 23:59:59")],
2016 => [et.parse("2017-01-23 00:00:00"), et.parse("2017-04-18 23:59:59")],
2015 => [et.parse("2016-01-19 00:00:00"), et.parse("2016-04-18 23:59:59")]
}

# GetCTC
config.ctc_soft_launch = Time.find_zone("America/New_York").parse("2022-05-04 09:00:00")
config.ctc_full_launch = Time.find_zone("America/New_York").parse("2022-05-11 09:00:00")
config.eitc_soft_launch = Time.find_zone("America/New_York").parse("2022-09-30 09:00:00")
config.eitc_full_launch = Time.find_zone("America/New_York").parse("2022-10-11 09:00:00")
config.ctc_end_of_intake = Time.find_zone("America/New_York").parse("2022-11-16 23:59:00")
config.ctc_end_of_read_write = Time.find_zone("America/New_York").parse("2022-11-19 23:59:00")
config.ctc_end_of_login = Time.find_zone("America/New_York").parse("2024-12-31 23:59:00")
config.ctc_soft_launch = et.parse("2022-05-04 09:00:00")
config.ctc_full_launch = et.parse("2022-05-11 09:00:00")
config.eitc_soft_launch = et.parse("2022-09-30 09:00:00")
config.eitc_full_launch = et.parse("2022-10-11 09:00:00")
config.ctc_end_of_intake = et.parse("2022-11-16 23:59:00")
config.ctc_end_of_read_write = et.parse("2022-11-19 23:59:00")
config.ctc_end_of_login = et.parse("2024-12-31 23:59:00")

# StateFile
config.state_file_start_of_open_intake = Time.find_zone('America/New_York').parse('2024-02-08 09:00:00')
config.state_file_end_of_new_intakes = Time.find_zone('America/Los_Angeles').parse('2024-04-15 23:59:59')
config.state_file_withdrawal_date_deadline_ny = Time.find_zone('America/New_York').parse('2024-04-15 23:59:59')
config.state_file_end_of_in_progress_intakes = Time.find_zone('America/Los_Angeles').parse('2024-04-25 23:59:59')
config.state_file_start_of_open_intake = et.parse('2024-02-08 09:00:00')
config.state_file_end_of_new_intakes = pt.parse('2024-04-15 23:59:59')
config.state_file_withdrawal_date_deadline_ny = et.parse('2024-04-15 23:59:59')
config.state_file_end_of_in_progress_intakes = pt.parse('2024-04-25 23:59:59')

config.allow_magic_verification_code = (Rails.env.demo? || Rails.env.development? || Rails.env.heroku? || Rails.env.staging?)
config.allow_magic_ssn = (Rails.env.demo? || Rails.env.development? || Rails.env.heroku? || Rails.env.staging?)
Expand Down
27 changes: 27 additions & 0 deletions spec/controllers/application_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,33 @@ def index
end
end

describe "#client_has_return_for_every_gyr_filing_year?" do
let(:client) { create(:client, intake: (build :intake)) }

context "client has no tax returns" do
it "returns false" do
expect(subject.client_has_return_for_every_gyr_filing_year?(client)).to be false
end
end

context "client has one tax return" do
it "returns false" do
create :gyr_tax_return, client: client
expect(subject.client_has_return_for_every_gyr_filing_year?(client)).to be false
end
end

context "client has tax returns for every current filing year" do
it "returns true" do
MultiTenantService.new(:gyr).filing_years.each do |year|
create :tax_return, client: client, year: year
end
expect(subject.client_has_return_for_every_gyr_filing_year?(client)).to be true
end
end

end

context "when receiving invalid requests from robots" do
before do
allow(DatadogApi).to receive(:increment)
Expand Down
13 changes: 12 additions & 1 deletion spec/controllers/hub/tax_returns_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
let(:client) { create :client, intake: build(:intake, preferred_name: "Lucille"), vita_partner: client_assigned_group }
let!(:tax_return) { create :tax_return, client: client, year: 2018, assigned_user: currently_assigned_coalition_lead }

let(:fake_current_tax_year) { 2021 }
let(:fake_time) { DateTime.parse("2022-04-14") }
before do
allow(Rails.application.config).to receive(:gyr_current_tax_year).and_return(fake_current_tax_year)
end
around do |example|
Timecop.freeze(fake_time) do
example.run
end
end

describe "#new" do
let(:params) do
{
Expand Down Expand Up @@ -50,7 +61,7 @@
expect(assigns(:client)).to eq client
expect(assigns(:tax_return)).to be_an_instance_of TaxReturn
expect(assigns(:form).tax_return_years).to eq [2018]
expect(assigns(:form).remaining_years).to eq MultiTenantService.new(:gyr).filing_years - [2018]
expect(assigns(:form).remaining_years).to eq(MultiTenantService.gyr.filing_years(fake_time) - [2018])
end
end
end
Expand Down
8 changes: 5 additions & 3 deletions spec/controllers/portal/still_needs_helps_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@
end

context "when the client has triggered still needs help" do
let!(:tax_return_in_progress) { create(:tax_return, :intake_in_progress, year: 2018, client: client) }
let!(:tax_return_not_filing) { create(:tax_return, :file_not_filing, year: 2019, client: client) }
let!(:tax_return_in_progress) { create(:tax_return, :intake_in_progress, year: 2019, client: client) }
let!(:tax_return_not_filing) { create(:tax_return, :file_not_filing, year: 2020, client: client) }
let(:client) { create :client, triggered_still_needs_help_at: Time.now, intake: build(:intake) }
let(:fake_time) { DateTime.new(2021, 1, 1) }
let(:fake_time) { DateTime.new(2022, 4, 1) }

before { sign_in client }

context "client indicates they still need help" do
it "saves answer, tax return statuses, first_unanswered_incoming_interaction_at, and clears triggered_still_needs_help_at" do
allow(Rails.application.config).to receive(:gyr_current_tax_year).and_return(2021)
Timecop.freeze(fake_time) { put :update, params: { still_needs_help: "yes" } }

# updates client still needs help fields
Expand Down
8 changes: 0 additions & 8 deletions spec/controllers/questions/backtaxes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@

render_views

describe "#load_possible_filing_years" do
it "sets possible_filing_years to all filing years" do
get :edit

expect(assigns(:possible_filing_years)).to eq (MultiTenantService.new(:gyr).filing_years)
end
end

describe "#edit" do
it "renders the edit page" do
get :edit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
end
let(:ip_address) { "127.0.0.1" }
let(:user_agent) { "IceFerret" }
let(:current_time) { DateTime.new(2021, 2, 23) }
let(:current_time) { DateTime.new(2022, 2, 23) }

before do
allow(DateTime).to receive(:now).and_return current_time
Expand Down
Loading

0 comments on commit bd78afa

Please sign in to comment.