Skip to content

Commit

Permalink
RST-4671 income (#1355)
Browse files Browse the repository at this point in the history
* Loading addditional income based on benefits

* Keeping exising value if exists
  • Loading branch information
zaparka authored Oct 27, 2022
1 parent 4e4843e commit c07b09d
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
5 changes: 5 additions & 0 deletions app/controllers/evidence/hmrc_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def create
def show
authorize evidence
check_hmrc_data
prepulated_additional_income
render :show
end

Expand Down Expand Up @@ -95,5 +96,9 @@ def load_default_date_range
def additional_income_updated?
hmrc_service.update_additional_income(hmrc_params)
end

def prepulated_additional_income
@form.load_additional_income_from_benefits
end
end
end
20 changes: 20 additions & 0 deletions app/models/forms/evidence/hmrc_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ def to_date
@to_date.strftime("%Y-%m-%d")
end

def load_additional_income_from_benefits
if child_benefits_per_month.positive?
self.additional_income = true
self.additional_income_amount = additional_income_value
end
end

def additional_income_value
return additional_income_amount if additional_income_amount.to_i.positive?
child_benefits_per_month
end

def child_benefits_per_month
children = @object.evidence_check.application.children
return 0 if children.zero?
children = 7 if children > 7

Settings.child_benefits_per_month[children]
end

private

def persist!
Expand Down
8 changes: 8 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ income:
max_threshold_base: 5170
per_child_increment: 265
married_supplement: 175
child_benefits_per_month:
1: 87
2: 145
3: 202
4: 260
5: 318
6: 375
7: 375
reference:
date: <%= ENV['FIRST_SOP_REFERENCE_DATE'] || '2017-01-01' %>
fee_approval_threshold: 10000.01
Expand Down
49 changes: 46 additions & 3 deletions spec/models/forms/evidence/hmrc_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

RSpec.describe Forms::Evidence::HmrcCheck do
subject(:form) { described_class.new(HmrcCheck.new(evidence_check: evidence)) }
let(:application) { create :application, created_at: '15.3.2021' }
let(:evidence) { create :evidence_check, application: application }

let(:application) { build :application, created_at: '15.3.2021', children: children }
let(:evidence) { build :evidence_check, application: application }
let(:children) { 0 }
let(:params) {
{
"from_date_day" => from_date_day,
Expand Down Expand Up @@ -184,6 +184,49 @@
end
end

context 'load_additional_income_from_benefits' do
subject(:form) { described_class.new(HmrcCheck.new(evidence_check: evidence)) }
context '1 child' do
let(:children) { 1 }

it 'additional_income' do
form.load_additional_income_from_benefits
expect(form.additional_income_amount).to eq 87
expect(form.additional_income).to be true
end
end

context '2 child' do
let(:children) { 2 }

it 'additional_income' do
form.load_additional_income_from_benefits
expect(form.additional_income_amount).to eq 145
expect(form.additional_income).to be true
end
end

context '8 child' do
let(:children) { 8 }

it 'additional_income' do
form.load_additional_income_from_benefits
expect(form.additional_income_amount).to eq 375
expect(form.additional_income).to be true
end
end

context 'don not ovrride existing value' do
let(:children) { 2 }

it 'additional_income' do
form.additional_income_amount = 10
form.load_additional_income_from_benefits
expect(form.additional_income_amount).to eq 10
end
end
end

context 'store' do
subject(:form) { described_class.new(hmrc_check) }
let(:hmrc_check) { HmrcCheck.create(evidence_check: evidence) }
Expand Down

0 comments on commit c07b09d

Please sign in to comment.