Browse Source

Make organisation fields optional since they won't immediately have one when created by support users

pull/653/head
baarkerlounger 3 years ago
parent
commit
98abe09db7
  1. 5
      app/controllers/case_logs_controller.rb
  2. 5
      app/models/case_log.rb
  3. 2
      app/models/validations/financial_validations.rb
  4. 2
      app/models/validations/household_validations.rb

5
app/controllers/case_logs_controller.rb

@ -105,7 +105,9 @@ private
end end
def case_log_params def case_log_params
if current_user if current_user && current_user.role == "support"
{ "created_by_id": current_user.id }.merge(api_case_log_params)
elsif current_user
org_params.merge(api_case_log_params) org_params.merge(api_case_log_params)
else else
api_case_log_params api_case_log_params
@ -115,7 +117,6 @@ private
def org_params def org_params
{ {
"owning_organisation_id" => current_user.organisation.id, "owning_organisation_id" => current_user.organisation.id,
"managing_organisation_id" => current_user.organisation.id,
"created_by_id" => current_user.id, "created_by_id" => current_user.id,
} }
end end

5
app/models/case_log.rb

@ -31,8 +31,8 @@ class CaseLog < ApplicationRecord
before_validation :set_derived_fields! before_validation :set_derived_fields!
before_save :update_status! before_save :update_status!
belongs_to :owning_organisation, class_name: "Organisation" belongs_to :owning_organisation, class_name: "Organisation", optional: true
belongs_to :managing_organisation, class_name: "Organisation" belongs_to :managing_organisation, class_name: "Organisation", optional: true
belongs_to :created_by, class_name: "User" belongs_to :created_by, class_name: "User"
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) }
@ -528,6 +528,7 @@ private
if rsnvac.present? if rsnvac.present?
self.newprop = has_first_let_vacancy_reason? ? 1 : 2 self.newprop = has_first_let_vacancy_reason? ? 1 : 2
end end
self.managing_organisation_id = owning_organisation_id
self.incref = 1 if net_income_refused? self.incref = 1 if net_income_refused?
self.renttype = RENT_TYPE_MAPPING[rent_type] self.renttype = RENT_TYPE_MAPPING[rent_type]
self.lettype = get_lettype self.lettype = get_lettype

2
app/models/validations/financial_validations.rb

@ -130,6 +130,8 @@ private
NEEDSTYPE_VALUES = { 2 => :supported_housing, 1 => :general_needs }.freeze NEEDSTYPE_VALUES = { 2 => :supported_housing, 1 => :general_needs }.freeze
def validate_charges(record) def validate_charges(record)
return unless record.owning_organisation
provider_type = record.owning_organisation.provider_type_before_type_cast provider_type = record.owning_organisation.provider_type_before_type_cast
%i[scharge pscharge supcharg].each do |charge| %i[scharge pscharge supcharg].each do |charge|
maximum = CHARGE_MAXIMUMS.dig(charge, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[record.needstype]) maximum = CHARGE_MAXIMUMS.dig(charge, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[record.needstype])

2
app/models/validations/household_validations.rb

@ -110,6 +110,8 @@ module Validations::HouseholdValidations
end end
def validate_referral(record) def validate_referral(record)
return unless record.owning_organisation
if record.is_internal_transfer? && record.owning_organisation.provider_type == "PRP" && record.is_prevten_la_general_needs? if record.is_internal_transfer? && record.owning_organisation.provider_type == "PRP" && record.is_prevten_la_general_needs?
record.errors.add :prevten, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.household.prevten.la_general_needs.internal_transfer") record.errors.add :prevten, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.household.prevten.la_general_needs.internal_transfer")
record.errors.add :referral, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.household.referral.la_general_needs.internal_transfer") record.errors.add :referral, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.household.referral.la_general_needs.internal_transfer")

Loading…
Cancel
Save