Skip to content

Commit

Permalink
Fyst 1429 update md two income subtraction to use new df json format …
Browse files Browse the repository at this point in the history
…for 1099 gs (#5235)

* Added DfJsonForm1099Gs accessor
* Update MD two income subtraction calculation & test
* Remove accessor for form_1099_gs_total
* In order to properly calculate the primary and spouse's federal agi (and the two-income subtraction), we need to reduce 'amount' by 'amountPaidBackForBenefitsInTaxYear'
  • Loading branch information
mpidcock authored Dec 20, 2024
1 parent bf54fb0 commit 5c77360
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
4 changes: 3 additions & 1 deletion app/lib/efile/md/two_income_subtraction_worksheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def calculate_fed_income(primary_or_spouse)
.select { |form1099r| form1099r.recipient_ssn == filer_ssn }
.sum { |form1099r| form1099r.taxable_amount&.round }

unemployment_income = find_filer_json_for(primary_or_spouse)&.form_1099_gs_total&.round || 0
unemployment_income = @direct_file_json_data.form_1099gs
.select { |form_1099g| form_1099g.recipient_tin.delete("-") == filer_ssn }
.sum { |form_1099g| (form_1099g.amount - form_1099g.amount_paid_back_for_benefits_in_tax_year).round }

wage_income +
interest_income +
Expand Down
17 changes: 16 additions & 1 deletion app/models/direct_file_json_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class DfJsonPerson < DfJsonWrapper

class DfJsonFiler < DfJsonPerson
json_accessor is_primary_filer: { type: :boolean, key: "isPrimaryFiler" }
json_accessor form_1099_gs_total: { type: :money_amount, key: "form1099GsTotal" }
json_accessor educator_expenses: { type: :money_amount, key: "educatorExpenses" }
json_accessor hsa_total_deductible_amount: { type: :money_amount, key: "hsaTotalDeductibleAmount" }
end
Expand Down Expand Up @@ -58,6 +57,18 @@ class DfJsonInterestReport < DfJsonWrapper
json_accessor tax_exempt_and_tax_credit_bond_cusip_number: { type: :string, key: "taxExemptAndTaxCreditBondCusipNo" }
end

class DfJsonForm1099Gs < DfJsonWrapper
json_accessor amount: { type: :money_amount, key: "amount" }
json_accessor amount_paid_back_for_benefits_in_tax_year: { type: :money_amount, key: "amountPaidBackForBenefitsInTaxYear" }
json_accessor federal_tax_withheld: { type: :money_amount, key: "federalTaxWithheld" }
json_accessor has_1099: { type: :boolean, key: "has1099" }
json_accessor state_id_number: { type: :string, key: "stateIdNumber" }
json_accessor state_tax_withheld: { type: :money_amount, key: "stateTaxWithheld" }
json_accessor payer: { type: :string, key: "payer" }
json_accessor payer_tin: { type: :string, key: "payerTin" }
json_accessor recipient_tin: { type: :string, key: "recipientTin" }
end

attr_reader :data
delegate :to_json, to: :data

Expand Down Expand Up @@ -89,6 +100,10 @@ def interest_reports
data["interestReports"]&.map { |interest_report| DfJsonInterestReport.new(interest_report) } || []
end

def form_1099gs
data["form1099Gs"]&.map { |form_1099g| DfJsonForm1099Gs.new(form_1099g) } || []
end

def filers
data["filers"]&.map { |filer| DfJsonFiler.new(filer) } || []
end
Expand Down
42 changes: 36 additions & 6 deletions spec/lib/efile/md/two_income_subtraction_worksheet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,60 @@
end

context "primary and spouse have only unemployment income" do
before do
primary_ssn = intake.primary.ssn
spouse_ssn = intake.spouse.ssn
intake.raw_direct_file_intake_data["form1099Gs"] = [{}, {}]
intake.direct_file_json_data.form_1099gs[0].recipient_tin = primary_ssn
intake.direct_file_json_data.form_1099gs[1].recipient_tin = spouse_ssn
end

it "calculates the fed income amount for primary and spouse" do
intake.direct_file_json_data.primary_filer&.form_1099_gs_total = "100.00"
intake.direct_file_json_data.spouse_filer&.form_1099_gs_total = "200.00"
intake.direct_file_json_data.form_1099gs[0].amount = "100.00"
intake.direct_file_json_data.form_1099gs[0].amount_paid_back_for_benefits_in_tax_year = "0.00"
intake.direct_file_json_data.form_1099gs[1].amount = "200.00"
intake.direct_file_json_data.form_1099gs[1].amount_paid_back_for_benefits_in_tax_year = "0.00"
expect(instance.calculate_fed_income(:primary)).to eq(100)
expect(instance.calculate_fed_income(:spouse)).to eq(200)
end

it "reduces unemployment income by the amount paid back" do
intake.direct_file_json_data.form_1099gs[0].amount = "100.00"
intake.direct_file_json_data.form_1099gs[0].amount_paid_back_for_benefits_in_tax_year = "50.00"
intake.direct_file_json_data.form_1099gs[1].amount = "200.00"
intake.direct_file_json_data.form_1099gs[1].amount_paid_back_for_benefits_in_tax_year = "50.00"
expect(instance.calculate_fed_income(:primary)).to eq(50)
expect(instance.calculate_fed_income(:spouse)).to eq(150)
end

it "handles nil values for 1099g income" do
intake.direct_file_json_data.form_1099gs[0].amount = nil
intake.direct_file_json_data.form_1099gs[1].amount = nil
expect(instance.calculate_fed_income(:primary)).to eq(0)
expect(instance.calculate_fed_income(:spouse)).to eq(0)
end
end

context "primary and spouse have all four kinds of income" do
context "primary and spouse each have all the income forms used to calculate the federal income amount" do
let(:intake) { create(:state_file_md_intake, :df_data_many_w2s) }
let(:primary_ssn) { intake.primary.ssn }
let(:spouse_ssn) { intake.spouse.ssn }
let!(:primary_state_file1099_r) { create(:state_file1099_r, intake: intake, recipient_ssn: primary_ssn, taxable_amount: 10) }
let!(:spouse_state_file1099_r) { create(:state_file1099_r, intake: intake, recipient_ssn: spouse_ssn, taxable_amount: 20) }

before do
# only populating minimum data required for this test
# only populating the minimum interestReport data required for this test
intake.raw_direct_file_intake_data["interestReports"] = [{}, {}]
intake.direct_file_json_data.interest_reports[0].recipient_tin = primary_ssn
intake.direct_file_json_data.interest_reports[1].recipient_tin = spouse_ssn
intake.direct_file_json_data.interest_reports[0].amount_1099 = "1.00"
intake.direct_file_json_data.interest_reports[1].amount_no_1099 = "2.00"
intake.direct_file_json_data.primary_filer&.form_1099_gs_total = "100.00"
intake.direct_file_json_data.spouse_filer&.form_1099_gs_total = "200.00"
# only populating the minimum form1099G data required for this test
intake.raw_direct_file_intake_data["form1099Gs"] = [{}, {}]
intake.direct_file_json_data.form_1099gs[0].recipient_tin = primary_ssn
intake.direct_file_json_data.form_1099gs[1].recipient_tin = spouse_ssn
intake.direct_file_json_data.form_1099gs[0].amount = "100.00"
intake.direct_file_json_data.form_1099gs[1].amount = "200.00"
end

it "calculates the fed income amount for primary and spouse" do
Expand Down

0 comments on commit 5c77360

Please sign in to comment.