|
|
|
@ -8,7 +8,6 @@ class CaseLogValidator < ActiveModel::Validator
|
|
|
|
|
include Validations::TenancyValidations |
|
|
|
|
include Validations::DateValidations |
|
|
|
|
include Validations::LocalAuthorityValidations |
|
|
|
|
|
|
|
|
|
def validate(record) |
|
|
|
|
validation_methods = public_methods.select { |method| method.starts_with?("validate_") } |
|
|
|
|
validation_methods.each { |meth| public_send(meth, record) } |
|
|
|
@ -57,7 +56,7 @@ class CaseLog < ApplicationRecord
|
|
|
|
|
scope :filter_by_id, ->(id) { where(id:) } |
|
|
|
|
scope :filter_by_tenant_code, ->(tenant_code) { where("tenancycode ILIKE ?", "%#{tenant_code}%") } |
|
|
|
|
scope :filter_by_propcode, ->(propcode) { where("propcode ILIKE ?", "%#{propcode}%") } |
|
|
|
|
scope :filter_by_postcode, ->(postcode_full) { where("postcode_full ILIKE ?", "%#{postcode_full.gsub(/\s+/, '')}%") } |
|
|
|
|
scope :filter_by_postcode, ->(postcode_full) { where("REPLACE(postcode_full, ' ', '') ILIKE ?", "%#{postcode_full.delete(' ')}%") } |
|
|
|
|
scope :search_by, lambda { |param| |
|
|
|
|
filter_by_id(param) |
|
|
|
|
.or(filter_by_tenant_code(param)) |
|
|
|
@ -118,6 +117,22 @@ class CaseLog < ApplicationRecord
|
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def postcode_full=(postcode) |
|
|
|
|
if postcode |
|
|
|
|
super UKPostcode.parse(postcode).to_s |
|
|
|
|
else |
|
|
|
|
super nil |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def ppostcode_full=(postcode) |
|
|
|
|
if postcode |
|
|
|
|
super UKPostcode.parse(postcode).to_s |
|
|
|
|
else |
|
|
|
|
super nil |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def completed? |
|
|
|
|
status == "completed" |
|
|
|
|
end |
|
|
|
|