Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
5.0 KiB

module Validations::Sales::SoftValidations
CLDC-853 Added validations for sales income2 (#1101) * CLDC-853 Added hard validations for sales income2 * CLDC-853 Added soft validation for sales income2 * CLDC-853 Fix tests broken by new code * CLDC-853 Add new tests for new page and refactor slightly * CLDC-853 Fix linting errors * CLDC-853 Rename migration and update schema version * CLDC-853 Fix broken sales income2 test * CLDC-853 Rename migration * CLDC-853 Move income 2 to cya card 2 and commonise combined income validation * CLDC-853 Actually use the validate_combined_income method * combine duplicate methods after rebase, ensure hard validations are triggered on all relevant fields * move validation on child income to financial validations to stop it being triggered on lettings logs, minor amendments to tests broken by changes * revamp financial validations tests against income to reflect updates * amend child income validation to reflect specifications and write tests to cover this validation * correct linting errors and play a little code golf * change copy for some validations, add sales log method and amend interruption screen helper to support this * extract duplicate code to private method * update buyer 1 and 2 income value check to be consistent * remove ecstat from income checks, the only ecstat we care about is child which is dealt with elsewhere * rename constant struct with same anme as existing variable * amend tests to reflect the chagnes in validations and copy * enable currency formatting of numbers for inserting into informative_text or title_text * update evil test in form handler spec * rebase and fix conflicts and tests * change a variable name and correct minor rebase errors * update interruption screen helper tests * correct linting errors, minor test failure and typo * add tests for new sales log method for formatting currency * fix merge conflicts --------- Co-authored-by: Arthur Campbell <arfa.camble@gmail.com>
2 years ago
ALLOWED_INCOME_RANGES_SALES = {
1 => OpenStruct.new(soft_min: 5000),
2 => OpenStruct.new(soft_min: 1500),
3 => OpenStruct.new(soft_min: 1000),
5 => OpenStruct.new(soft_min: 2000),
0 => OpenStruct.new(soft_min: 2000),
}.freeze
def income1_under_soft_min?
CLDC-853 Added validations for sales income2 (#1101) * CLDC-853 Added hard validations for sales income2 * CLDC-853 Added soft validation for sales income2 * CLDC-853 Fix tests broken by new code * CLDC-853 Add new tests for new page and refactor slightly * CLDC-853 Fix linting errors * CLDC-853 Rename migration and update schema version * CLDC-853 Fix broken sales income2 test * CLDC-853 Rename migration * CLDC-853 Move income 2 to cya card 2 and commonise combined income validation * CLDC-853 Actually use the validate_combined_income method * combine duplicate methods after rebase, ensure hard validations are triggered on all relevant fields * move validation on child income to financial validations to stop it being triggered on lettings logs, minor amendments to tests broken by changes * revamp financial validations tests against income to reflect updates * amend child income validation to reflect specifications and write tests to cover this validation * correct linting errors and play a little code golf * change copy for some validations, add sales log method and amend interruption screen helper to support this * extract duplicate code to private method * update buyer 1 and 2 income value check to be consistent * remove ecstat from income checks, the only ecstat we care about is child which is dealt with elsewhere * rename constant struct with same anme as existing variable * amend tests to reflect the chagnes in validations and copy * enable currency formatting of numbers for inserting into informative_text or title_text * update evil test in form handler spec * rebase and fix conflicts and tests * change a variable name and correct minor rebase errors * update interruption screen helper tests * correct linting errors, minor test failure and typo * add tests for new sales log method for formatting currency * fix merge conflicts --------- Co-authored-by: Arthur Campbell <arfa.camble@gmail.com>
2 years ago
return false unless ecstat1 && income1 && ALLOWED_INCOME_RANGES_SALES[ecstat1]
CLDC-853 Added validations for sales income2 (#1101) * CLDC-853 Added hard validations for sales income2 * CLDC-853 Added soft validation for sales income2 * CLDC-853 Fix tests broken by new code * CLDC-853 Add new tests for new page and refactor slightly * CLDC-853 Fix linting errors * CLDC-853 Rename migration and update schema version * CLDC-853 Fix broken sales income2 test * CLDC-853 Rename migration * CLDC-853 Move income 2 to cya card 2 and commonise combined income validation * CLDC-853 Actually use the validate_combined_income method * combine duplicate methods after rebase, ensure hard validations are triggered on all relevant fields * move validation on child income to financial validations to stop it being triggered on lettings logs, minor amendments to tests broken by changes * revamp financial validations tests against income to reflect updates * amend child income validation to reflect specifications and write tests to cover this validation * correct linting errors and play a little code golf * change copy for some validations, add sales log method and amend interruption screen helper to support this * extract duplicate code to private method * update buyer 1 and 2 income value check to be consistent * remove ecstat from income checks, the only ecstat we care about is child which is dealt with elsewhere * rename constant struct with same anme as existing variable * amend tests to reflect the chagnes in validations and copy * enable currency formatting of numbers for inserting into informative_text or title_text * update evil test in form handler spec * rebase and fix conflicts and tests * change a variable name and correct minor rebase errors * update interruption screen helper tests * correct linting errors, minor test failure and typo * add tests for new sales log method for formatting currency * fix merge conflicts --------- Co-authored-by: Arthur Campbell <arfa.camble@gmail.com>
2 years ago
income1 < ALLOWED_INCOME_RANGES_SALES[ecstat1][:soft_min]
end
def income2_under_soft_min?
return false unless ecstat2 && income2 && ALLOWED_INCOME_RANGES_SALES[ecstat2]
income2 < ALLOWED_INCOME_RANGES_SALES[ecstat2][:soft_min]
end
def income1_over_soft_max?
return unless income1 && la && discounted_ownership_sale?
income_over_soft_max?(income1)
end
def income2_over_soft_max?
return unless income2 && la && discounted_ownership_sale?
income_over_soft_max?(income2)
end
def combined_income_over_soft_max?
return unless income1 && income2 && la && discounted_ownership_sale?
income_over_soft_max?(income1 + income2)
end
def staircase_bought_above_fifty?
stairbought && stairbought > 50
end
def mortgage_over_soft_max?
return false unless mortgage && inc1mort && (inc2mort || not_joint_purchase?)
return false if income1_used_for_mortgage? && income1.blank? || income2_used_for_mortgage? && income2.blank?
income_used_for_mortgage = (income1_used_for_mortgage? ? income1 : 0) + (income2_used_for_mortgage? ? income2 : 0)
mortgage > income_used_for_mortgage * 5
end
Cldc 1440 household situation section (#1132) * feat: add question page and subsection (#1120) * feat: add question page and subsection * refactor: linting * feat: remove schema rows from other branch * feat: slight refactor, fix tag behaviour and add section tests * test: update and add tests * feat: update status behaviour * feat: update subsection status tag * refactor: linting * [CLDC-857] Add household wheelchair check (#1122) * [CLDC-857] Add household wheelchair check * Hide only if answered * Cldc 1497 ever served armed forces (#1124) * feat: add question and page * test: update tests * refactor: linting and slight test updates * test: fix tests * Cldc 1498 still serving armed forces (#1123) * feat: new question and tests * test: update subsection spec * test: update tests * feat: (future) conflict resolving * feat: more conflict resolution * feat: update db field * test: update id * test: updates * Cldc 1488 last accomodation (#1125) * Add postcode fields * Add previous postcode page and questions * Add last accommodation page to household situation subsection * add previous la known to the db * infer correct location fields * styling * Reorder disability questions (#1127) * [CLDC-1487] Add buyer1 previous tenure question (#1133) * use collection_start_year instead of the startdate (#1128) * [CLDC-1487] Add buyer 1 previous tenure Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> * feat: fix routing (#1141) * Add last accommodation la question (#1142) * move hint text (#1146) Co-authored-by: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Co-authored-by: Jack S <113976590+bibblobcode@users.noreply.github.com>
2 years ago
def wheelchair_when_not_disabled?
return unless disabled && wheel
Cldc 1440 household situation section (#1132) * feat: add question page and subsection (#1120) * feat: add question page and subsection * refactor: linting * feat: remove schema rows from other branch * feat: slight refactor, fix tag behaviour and add section tests * test: update and add tests * feat: update status behaviour * feat: update subsection status tag * refactor: linting * [CLDC-857] Add household wheelchair check (#1122) * [CLDC-857] Add household wheelchair check * Hide only if answered * Cldc 1497 ever served armed forces (#1124) * feat: add question and page * test: update tests * refactor: linting and slight test updates * test: fix tests * Cldc 1498 still serving armed forces (#1123) * feat: new question and tests * test: update subsection spec * test: update tests * feat: (future) conflict resolving * feat: more conflict resolution * feat: update db field * test: update id * test: updates * Cldc 1488 last accomodation (#1125) * Add postcode fields * Add previous postcode page and questions * Add last accommodation page to household situation subsection * add previous la known to the db * infer correct location fields * styling * Reorder disability questions (#1127) * [CLDC-1487] Add buyer1 previous tenure question (#1133) * use collection_start_year instead of the startdate (#1128) * [CLDC-1487] Add buyer 1 previous tenure Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> * feat: fix routing (#1141) * Add last accommodation la question (#1142) * move hint text (#1146) Co-authored-by: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Co-authored-by: Jack S <113976590+bibblobcode@users.noreply.github.com>
2 years ago
wheel == 1 && disabled == 2
Cldc 1440 household situation section (#1132) * feat: add question page and subsection (#1120) * feat: add question page and subsection * refactor: linting * feat: remove schema rows from other branch * feat: slight refactor, fix tag behaviour and add section tests * test: update and add tests * feat: update status behaviour * feat: update subsection status tag * refactor: linting * [CLDC-857] Add household wheelchair check (#1122) * [CLDC-857] Add household wheelchair check * Hide only if answered * Cldc 1497 ever served armed forces (#1124) * feat: add question and page * test: update tests * refactor: linting and slight test updates * test: fix tests * Cldc 1498 still serving armed forces (#1123) * feat: new question and tests * test: update subsection spec * test: update tests * feat: (future) conflict resolving * feat: more conflict resolution * feat: update db field * test: update id * test: updates * Cldc 1488 last accomodation (#1125) * Add postcode fields * Add previous postcode page and questions * Add last accommodation page to household situation subsection * add previous la known to the db * infer correct location fields * styling * Reorder disability questions (#1127) * [CLDC-1487] Add buyer1 previous tenure question (#1133) * use collection_start_year instead of the startdate (#1128) * [CLDC-1487] Add buyer 1 previous tenure Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> * feat: fix routing (#1141) * Add last accommodation la question (#1142) * move hint text (#1146) Co-authored-by: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Co-authored-by: Jack S <113976590+bibblobcode@users.noreply.github.com>
2 years ago
end
def savings_over_soft_max?
savings && savings > 100_000
end
def deposit_over_soft_max?
return unless savings && deposit
deposit > savings * 4 / 3
end
def extra_borrowing_expected_but_not_reported?
return unless extrabor && mortgage && deposit && value && discount
extrabor != 1 && mortgage + deposit > value - value * discount / 100
end
def purchase_price_out_of_soft_range?
return unless value && beds && la && sale_range
!value.between?(sale_range.soft_min, sale_range.soft_max)
end
def staircase_owned_out_of_soft_range?
return unless type && stairowned
type == 24 && stairowned.between?(76, 100)
end
def shared_ownership_deposit_invalid?
return unless mortgage || mortgageused == 2 || mortgageused == 3
return unless cashdis || !is_type_discount?
return unless deposit && value && equity
cash_discount = cashdis || 0
mortgage_value = mortgage || 0
mortgage_value + deposit + cash_discount != value * equity / 100
end
def mortgage_plus_deposit_less_than_discounted_value?
return unless mortgage && deposit && value && discount
discounted_value = value * (100 - discount) / 100
mortgage + deposit < discounted_value
end
def hodate_3_years_or_more_saledate?
return unless hodate && saledate
saledate - hodate >= 3.years
end
CLDC-2248 Improve soft validations (#1584) * Update interruption screen page * Update routing and add flash * Only display routed to affected questions * Add affected_question_ids to pregnancy check * lint * Add skip link and lint * Move affected_question_ids to page, because we reuse questions so they might have different affected_question_ids * typo * Fix button wording * Update action href links * Change how we route back to interruption screen * Update affected_question_ids for lettings * Update sales soft validations * Update title texts * Update styling * Update is_referrer_interruption_screen? check and naming * Add interuption screen helper specs * Add request test for fixing soft validation * Add tests for geting soft validation page * Extract interruption screen banner * Update action_href to be reusable * Extract questions out of check answers summary list * Reuse check_answers_summary_list for interruption screen * refactor string parse * Rename attribute * fix test * Add tests for sales paths * typo * Update validation message: void date, major repairs date * Update validation message: rent_value_check, 2022 * Update validation message: buyer live in * Update validation message: staircase * Update validation message: purchase price * Update validation message: income * Update validation message: savings * Update validation message: extra borrowing * Update validation message: extra borrowing * Update validation message: wheelchair * Update validation message: monthly charge * Update validation message: mortgage * Update validation message: old persons shared ownership * Update validation message: discount * Update validation: min retirement * Wording in tests and time test * Update missing question * Refactor is referrer methods * Update validation message: net income * Update validation message: deposit and savings * Update validation message: mortgage, discount and deposit * Fix test validation messages * Fix the retirement check showing on the card 8, fix tests * test * return the user back to the check_your_answers after fixing a validation from check_your_anwers * pr comments
2 years ago
def purchase_price_higher_or_lower_text
value < sale_range.soft_min ? "lower" : "higher"
end
def purchase_price_soft_min_or_soft_max
value < sale_range.soft_min ? sale_range.soft_min : sale_range.soft_max
end
def grant_outside_common_range?
return unless grant
!grant.between?(9_000, 16_000)
end
def monthly_charges_over_soft_max?
return unless type && mscharge && proptype
soft_max = old_persons_shared_ownership? ? 550 : 300
mscharge > soft_max
end
(2..6).each do |person_num|
define_method("person_#{person_num}_student_not_child?") do
relat = send("relat#{person_num}")
ecstat = send("ecstat#{person_num}")
age = send("age#{person_num}")
return unless age && ecstat && relat
age.between?(16, 19) && ecstat == 7 && relat != "C"
end
end
def discounted_ownership_value_invalid?
return unless saledate && collection_start_year <= 2023
return unless value && deposit && ownershipsch
return unless mortgage || mortgageused == 2 || mortgageused == 3
return unless discount || grant || type == 29
mortgage_deposit_and_grant_total != value_with_discount && discounted_ownership_sale?
end
def buyer1_livein_wrong_for_ownership_type?
return unless ownershipsch && buy1livein
(discounted_ownership_sale? || shared_ownership_scheme?) && buy1livein == 2
end
def buyer2_livein_wrong_for_ownership_type?
return unless ownershipsch && buy2livein
return unless joint_purchase?
(discounted_ownership_sale? || shared_ownership_scheme?) && buy2livein == 2
end
def percentage_discount_invalid?
return unless discount && proptype
case proptype
when 1, 2
discount > 50
when 3, 4, 9
discount > 35
end
end
private
def sale_range
LaSaleRange.find_by(
start_year: collection_start_year,
la:,
bedrooms: beds_for_la_sale_range,
)
end
def income_over_soft_max?(income)
(london_property? && income > 90_000) || (property_not_in_london? && income > 80_000)
end
end