Class: HrLite::Asset
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- HrLite::Asset
- Includes:
- Audited
- Defined in:
- app/models/hr_lite/asset.rb
Overview
A laptop, a phone, a SIM. An asset nobody tracks is a cost nobody notices, and the moment it matters is somebody's last day.
Constant Summary collapse
- STATUSES =
%w[available assigned returned lost damaged retired].freeze
- CATEGORIES =
%w[laptop phone sim id_card accessory vehicle other].freeze
Constants included from Audited
HrLite::Audited::REDACTED, HrLite::Audited::SKIPPED_ATTRIBUTES
Class Method Summary collapse
-
.outstanding_for(user) ⇒ Object
Everything still out with somebody who has left — the report that should exist before an exit, not after.
Instance Method Summary collapse
- #assign_to!(user, actor: nil, on: Date.current) ⇒ Object
- #holder ⇒ Object
- #live_assignment ⇒ Object
-
#return!(actor: nil, on: Date.current, condition: nil, status: "available") ⇒ Object
conditionrecords what came back — "screen cracked" is the difference between an asset returned and an asset written off.
Class Method Details
.outstanding_for(user) ⇒ Object
Everything still out with somebody who has left — the report that should exist before an exit, not after.
51 52 53 54 55 |
# File 'app/models/hr_lite/asset.rb', line 51 def self.outstanding_for(user) joins(:asset_assignments) .where(hr_lite_asset_assignments: { user_id: user.id, returned_on: nil }) .distinct end |
Instance Method Details
#assign_to!(user, actor: nil, on: Date.current) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'app/models/hr_lite/asset.rb', line 26 def assign_to!(user, actor: nil, on: Date.current) raise ActiveRecord::RecordInvalid.new(self), "already assigned" if live_assignment transaction do asset_assignments.create!(user_id: user.id, assigned_on: on, assigned_by_id: actor&.id) update!(status: "assigned") end true end |
#holder ⇒ Object
24 |
# File 'app/models/hr_lite/asset.rb', line 24 def holder = live_assignment&.user |
#live_assignment ⇒ Object
22 |
# File 'app/models/hr_lite/asset.rb', line 22 def live_assignment = asset_assignments.find_by(returned_on: nil) |
#return!(actor: nil, on: Date.current, condition: nil, status: "available") ⇒ Object
condition records what came back — "screen cracked" is the difference
between an asset returned and an asset written off.
38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/hr_lite/asset.rb', line 38 def return!(actor: nil, on: Date.current, condition: nil, status: "available") assignment = live_assignment raise ActiveRecord::RecordInvalid.new(self), "not assigned" if assignment.nil? transaction do assignment.update!(returned_on: on, condition_note: condition.presence) update!(status: status) end true end |