Skip to content

Commit

Permalink
Find the reason for decline and cancelation more effectively
Browse files Browse the repository at this point in the history
  • Loading branch information
eanders committed Sep 22, 2024
1 parent cd9e70e commit 3f35988
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
29 changes: 25 additions & 4 deletions app/models/client_opportunity_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -457,16 +457,37 @@ def current_decision
end

def unsuccessful_decision
initialized_decisions.where.not(decline_reason_id: nil)&.first ||
initialized_decisions.where.not(administrative_cancel_reason_id: nil)&.first
return canceled_decision if canceled?

declined_decision
end

def unsuccessful_reason
return unsuccessful_decision.administrative_cancel_reason if canceled?

unsuccessful_decision.decline_reason
end

# Find the latest decision in the route that was declined with a reason
# If that doesn't exist, pull the latest initialized decision that was declined
def declined_decision
@declined_decision ||= initialized_decisions.where.not(decline_reason_id: nil)&.first
@declined_decision ||= initialized_decisions.where(status: :declined)&.last
decision_order = match_route.class.match_steps_for_reporting.keys
@declined_decision ||= initialized_decisions.order_as_specified(type: decision_order).where.not(decline_reason_id: nil)&.last
@declined_decision ||= initialized_decisions.order_as_specified(type: decision_order).where(status: :declined)&.last
@declined_decision
end

# Find the latest decision in the route that was canceled with a reason
# If that doesn't exist, pull the latest initialized decision that was canceled
def canceled_decision
return nil unless canceled?

decision_order = match_route.class.match_steps_for_reporting.keys
@canceled_decision ||= initialized_decisions.order_as_specified(type: decision_order).where.not(administrative_cancel_reason_id: nil)&.last
@canceled_decision ||= initialized_decisions.order_as_specified(type: decision_order).where(status: :canceled)&.last
@canceled_decision
end

def clear_current_decision_cache!
@current_decision = nil
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/warehouse/referral_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def accepted
end

def rejected
reason = client_opportunity_match.current_decision&.decline_reason
reason = client_opportunity_match.unsuccessful_reason
if reason&.referral_result.present?
update(referral_result: reason.referral_result, referral_result_date: reason.referral_result_date)
else
Expand Down Expand Up @@ -62,7 +62,7 @@ def self.sync_match_referrals!
)
end
else
reason = match.current_decision&.decline_reason
reason = match.unsuccessful_reason
if reason.present? && reason.referral_result.present?
if event.referral_result != reason.referral_result
event.update(
Expand Down

0 comments on commit 3f35988

Please sign in to comment.