Browse Source

feat: infer mscharge if mscharge_known == No

pull/1134/head
natdeanlewissoftwire 3 years ago
parent
commit
a1b975b1a7
  1. 11
      app/models/form/sales/questions/leasehold_charges.rb
  2. 5
      app/models/form/sales/questions/leasehold_charges_known.rb
  3. 7
      app/models/sales_log.rb

11
app/models/form/sales/questions/leasehold_charges.rb

@ -2,17 +2,12 @@ class Form::Sales::Questions::LeaseholdCharges < ::Form::Question
def initialize(id, hsh, page)
super
@id = "mscharge"
@check_answer_label = "Monthly rent"
@check_answer_label = "Monthly leasehold charges"
@header = "Enter the total monthly charge"
@type = "numeric"
@page = page
@width = 2
@min = 0
@width = 5
@prefix = "£"
@inferred_check_answers_value = {
"condition" => {
"mscharge_known" => 0,
},
"value" => 0,
}
end
end

5
app/models/form/sales/questions/leasehold_charges_known.rb

@ -2,7 +2,7 @@ class Form::Sales::Questions::LeaseholdChargesKnown < ::Form::Question
def initialize(id, hsh, page)
super
@id = "mscharge_known"
@check_answer_label = "Monthly rent"
@check_answer_label = "Monthly leasehold charges known?"
@header = "Does the property have any monthly leasehold charges?"
@hint_text = "For example, service and management charges"
@type = "radio"
@ -13,9 +13,6 @@ class Form::Sales::Questions::LeaseholdChargesKnown < ::Form::Question
}
@hidden_in_check_answers = {
"depends_on" => [
{
"mscharge_known" => 0,
},
{
"mscharge_known" => 1,
},

7
app/models/sales_log.rb

@ -20,6 +20,7 @@ class SalesLog < Log
validates_with SalesLogValidator
before_validation :set_derived_fields!
before_validation :reset_invalidated_dependent_fields!
before_validation :process_mscharge_known_changes!, if: :mscharge_known_changed?
scope :filter_by_year, ->(year) { where(saledate: Time.zone.local(year.to_i, 4, 1)...Time.zone.local(year.to_i + 1, 4, 1)) }
scope :search_by, ->(param) { filter_by_id(param) }
@ -115,4 +116,10 @@ class SalesLog < Log
def right_to_buy?
[9, 14, 27].include?(type)
end
def process_mscharge_known_changes!
return if mscharge_known.blank?
self["mscharge"] = 0 if mscharge_known.zero?
end
end

Loading…
Cancel
Save