Class: TravelSponsorship
- Inherits:
-
ReimbursableRequest
- Object
- ActiveRecord::Base
- ApplicationRecord
- Request
- ReimbursableRequest
- TravelSponsorship
- Defined in:
- app/models/travel_sponsorship.rb
Overview
Request from a user to get help from the TSP for a given event
State Machines
This class contains 1 state machine(s).state
Instance Attribute Summary
Attributes inherited from Request
#contact_phone_number, #created_at, #description, #state, #state_updated_at, #type, #updated_at, #visa_letter
Class Method Summary collapse
-
.in_conflict_with ⇒ ActiveRecord::Relation<TravelSponsorship>
A relation of TravelSponsorships that are in conflict with.
-
.notify_missing_reimbursement(after_end_threshold, before_deadline_threshold) ⇒ Object
Sends notifications about requests lacking a reimbursement.
Instance Method Summary collapse
- #allow_cancel?(role_name) ⇒ Boolean
-
#can_have_reimbursement? ⇒ Boolean
Checks whether the request is ready for reimbursement.
-
#visa_letter_allowed? ⇒ Boolean
Check wheter the visa_letter attribute can be used.
Methods inherited from ReimbursableRequest
#can_cancel?, #expenses, #expenses_sum, expenses_sum, #lacks_reimbursement?, #no_expenses?, #reimbursement
Methods inherited from Request
Methods included from HasState
#active?, #assigned_roles, #can_be_destroyed?, #can_cancel?, #cancel, #editable?, #human_state_description, #human_state_guide, #in_final_state?, #in_initial_state?, #label, #notify_state, #title, #with_transitions?
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes
Class Method Details
.in_conflict_with ⇒ ActiveRecord::Relation<TravelSponsorship>
A relation of TravelSponsorships that are in conflict with. Active Record Scope
10 11 12 13 14 |
# File 'app/models/travel_sponsorship.rb', line 10 scope :in_conflict_with, lambda { |req| others = active.where(user_id: req.user_id, event_id: req.event_id) others = others.where(['id <> ?', req.id]) if req.id others } |
.notify_missing_reimbursement(after_end_threshold, before_deadline_threshold) ⇒ Object
Sends notifications about requests lacking a reimbursement.
Looks for events that finished some days ago or that are about to reach the reimbursement deadline and sends a reminder for every request associated to those events and lacking a reimbursement object.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/models/travel_sponsorship.rb', line 102 def self.notify_missing_reimbursement(after_end_threshold, before_deadline_threshold) now = Time.zone.now # Skip events finished more than 6 months ago to keep the size under control candidate_events = Event.where( ['(end_date > ? and end_date < ?) or '\ '(reimbursement_creation_deadline > ? and reimbursement_creation_deadline < ?)', now - 6.months, now - after_end_threshold, now, now + before_deadline_threshold] ) candidate_events.includes(:requests).each do |e| e.requests.each do |r| ReimbursableRequestMailer.notify_to([r.user], :missing_reimbursement, r) if r.lacks_reimbursement? end end end |
Instance Method Details
#allow_cancel?(role_name) ⇒ Boolean
73 74 75 76 |
# File 'app/models/travel_sponsorship.rb', line 73 def allow_cancel?(role_name) r = role_name.to_sym %i[requester supervisor].include?(r) || (r == :tsp && !accepted?) end |
#can_have_reimbursement? ⇒ Boolean
Checks whether the request is ready for reimbursement
81 82 83 |
# File 'app/models/travel_sponsorship.rb', line 81 def can_have_reimbursement? accepted? && (!reimbursement.nil? || event.accepting_reimbursements?) end |
#visa_letter_allowed? ⇒ Boolean
Check wheter the visa_letter attribute can be used
88 89 90 |
# File 'app/models/travel_sponsorship.rb', line 88 def visa_letter_allowed? event.try(:visa_letters) == true end |