Class: HrLite::ChecklistItem
Overview
One step for one person. Kept even when its template is later deleted —
what a company DID on somebody's first day is history, and history should
not change because a template was tidied up.
Constant Summary
Constants included
from Audited
Audited::REDACTED, Audited::SKIPPED_ATTRIBUTES
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.open_for!(user, kind:, anchor_date:) ⇒ Object
Builds somebody's list from the active templates. Idempotent: running
it twice does not double the list, so a re-run after adding a template
adds only what is new.
34
35
36
37
38
39
40
41
|
# File 'app/models/hr_lite/checklist_item.rb', line 34
def self.open_for!(user, kind:, anchor_date:)
ChecklistTemplate.for_kind(kind).filter_map do |template|
next if exists?(user_id: user.id, kind: kind.to_s, title: template.title)
create!(user_id: user.id, template: template, kind: kind.to_s, title: template.title,
due_on: anchor_date + template.due_offset_days)
end
end
|
Instance Method Details
#complete!(actor:, note: nil) ⇒ Object
23
24
25
|
# File 'app/models/hr_lite/checklist_item.rb', line 23
def complete!(actor:, note: nil)
update!(completed_at: Time.current, completed_by_id: actor&.id, note: note.presence)
end
|
#done? ⇒ Boolean
19
|
# File 'app/models/hr_lite/checklist_item.rb', line 19
def done? = completed_at.present?
|
#overdue?(on = Date.current) ⇒ Boolean
21
|
# File 'app/models/hr_lite/checklist_item.rb', line 21
def overdue?(on = Date.current) = !done? && due_on.present? && due_on < on
|
#reopen!(actor:) ⇒ Object
27
28
29
|
# File 'app/models/hr_lite/checklist_item.rb', line 27
def reopen!(actor:)
update!(completed_at: nil, completed_by_id: nil)
end
|