Class: HrLite::Approval

Inherits:
ApplicationRecord show all
Defined in:
app/models/hr_lite/approval.rb

Overview

One person's outstanding decision on one record. The row is the unit the inbox lists and the escalation job reads.

Constant Summary collapse

STATUSES =
%w[pending approved rejected returned skipped cancelled].freeze

Instance Method Summary collapse

Instance Method Details

#answerable_by?(user) ⇒ Boolean

Whether user may answer this — the approver themselves, or somebody they have delegated to while they are away.

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'app/models/hr_lite/approval.rb', line 22

def answerable_by?(user)
  return false if user.nil? || !pending?

  approver_id == user.id ||
    ApprovalDelegation.stand_ins_for(approver_id).include?(user.id)
end

#decide!(status:, actor:, note: nil) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
34
# File 'app/models/hr_lite/approval.rb', line 29

def decide!(status:, actor:, note: nil)
  raise ArgumentError, "unknown decision #{status}" unless STATUSES.include?(status.to_s)

  update!(status: status.to_s, note: note.presence, decided_at: Time.current,
          decided_by_id: actor&.id)
end

#labelObject



44
# File 'app/models/hr_lite/approval.rb', line 44

def label = "#{subject_type.demodulize.underscore.humanize} ##{subject_id}"

#overdue?(now = Time.current) ⇒ Boolean

True once this row's SLA has run out. Computed rather than stored so editing a step's SLA takes effect on the rows already waiting.

Returns:

  • (Boolean)


38
39
40
41
42
# File 'app/models/hr_lite/approval.rb', line 38

def overdue?(now = Time.current)
  return false unless pending? && step.sla_hours

  created_at + step.sla_hours.hours <= now
end