|
|
|
@ -1,5 +1,7 @@ |
|
|
|
module DerivedVariables::SalesLogVariables |
|
|
|
module DerivedVariables::SalesLogVariables |
|
|
|
def set_derived_fields! |
|
|
|
def set_derived_fields! |
|
|
|
|
|
|
|
reset_invalidated_derived_values! |
|
|
|
|
|
|
|
|
|
|
|
self.ethnic = 17 if ethnic_refused? |
|
|
|
self.ethnic = 17 if ethnic_refused? |
|
|
|
self.mscharge = nil if no_monthly_leasehold_charges? |
|
|
|
self.mscharge = nil if no_monthly_leasehold_charges? |
|
|
|
if exdate.present? |
|
|
|
if exdate.present? |
|
|
|
@ -13,9 +15,6 @@ module DerivedVariables::SalesLogVariables |
|
|
|
self.hoyear = hodate.year |
|
|
|
self.hoyear = hodate.year |
|
|
|
end |
|
|
|
end |
|
|
|
self.deposit = value if outright_sale? && mortgage_not_used? |
|
|
|
self.deposit = value if outright_sale? && mortgage_not_used? |
|
|
|
if mortgage_not_used? |
|
|
|
|
|
|
|
self.mortgage = 0 |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
self.pcode1, self.pcode2 = postcode_full.split(" ") if postcode_full.present? |
|
|
|
self.pcode1, self.pcode2 = postcode_full.split(" ") if postcode_full.present? |
|
|
|
self.totchild = total_child |
|
|
|
self.totchild = total_child |
|
|
|
self.totadult = total_adult + total_elder |
|
|
|
self.totadult = total_adult + total_elder |
|
|
|
@ -31,20 +30,73 @@ module DerivedVariables::SalesLogVariables |
|
|
|
self.uprn_known = 0 |
|
|
|
self.uprn_known = 0 |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if buyers_will_not_live_in? |
|
|
|
set_encoded_derived_values! |
|
|
|
self.buy1livein = 2 |
|
|
|
end |
|
|
|
if joint_purchase? |
|
|
|
|
|
|
|
self.buy2livein = 2 |
|
|
|
private |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEPENDENCIES = [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
conditions: { |
|
|
|
|
|
|
|
buylivein: 2, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
derived_values: { |
|
|
|
|
|
|
|
buy1livein: 2, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
conditions: { |
|
|
|
|
|
|
|
buylivein: 2, |
|
|
|
|
|
|
|
jointpur: 1, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
derived_values: { |
|
|
|
|
|
|
|
buy1livein: 2, |
|
|
|
|
|
|
|
buy2livein: 2, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
conditions: { |
|
|
|
|
|
|
|
buylivein: 1, |
|
|
|
|
|
|
|
jointpur: 2, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
derived_values: { |
|
|
|
|
|
|
|
buy1livein: 1, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
conditions: { |
|
|
|
|
|
|
|
mortgageused: 2, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
derived_values: { |
|
|
|
|
|
|
|
mortgage: 0, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
].freeze |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def reset_invalidated_derived_values! |
|
|
|
|
|
|
|
DEPENDENCIES.each do |dependency| |
|
|
|
|
|
|
|
any_conditions_changed = dependency[:conditions].any? { |attribute, _value| send("#{attribute}_changed?") } |
|
|
|
|
|
|
|
next unless any_conditions_changed |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
previously_in_derived_state = dependency[:conditions].all? { |attribute, value| send("#{attribute}_was") == value } |
|
|
|
|
|
|
|
next unless previously_in_derived_state |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dependency[:derived_values].each do |derived_attribute, _derived_value| |
|
|
|
|
|
|
|
Rails.logger.debug("Cleared derived #{derived_attribute} value") |
|
|
|
|
|
|
|
send("#{derived_attribute}=", nil) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if buyers_will_live_in? && not_joint_purchase? |
|
|
|
def set_encoded_derived_values! |
|
|
|
self.buy1livein = 1 |
|
|
|
DEPENDENCIES.each do |dependency| |
|
|
|
|
|
|
|
derivation_applies = dependency[:conditions].all? { |attribute, value| send(attribute) == value } |
|
|
|
|
|
|
|
if derivation_applies |
|
|
|
|
|
|
|
dependency[:derived_values].each { |attribute, value| send("#{attribute}=", value) } |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
private |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def number_of_household_members |
|
|
|
def number_of_household_members |
|
|
|
return unless hholdcount.present? && jointpur.present? |
|
|
|
return unless hholdcount.present? && jointpur.present? |
|
|
|
|
|
|
|
|
|
|
|
|