Class: SponsoredProjectAllocation

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/sponsored_project_allocation.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.emails_staff_requesting_confirmation_for_allocationsObject


28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/sponsored_project_allocation.rb', line 28

def self.emails_staff_requesting_confirmation_for_allocations
  efforts = SponsoredProjectEffort.for_all_users_for_a_given_month(1.month.ago.month, 1.month.ago.year)
  efforts.each do |effort|
    user = effort.sponsored_project_allocation.user
    unless effort.confirmed || user.emailed_recently(:sponsored_project_effort)
      SponsoredProjectEffortMailer.monthly_staff_email(user, effort.month, effort.year).deliver
      user.sponsored_project_effort_last_emailed = Time.now
      user.save
    end
  end

end

.monthly_copy_to_sponsored_project_effortObject


21
22
23
24
25
26
# File 'app/models/sponsored_project_allocation.rb', line 21

def self.monthly_copy_to_sponsored_project_effort
  allocations = SponsoredProjectAllocation.current
  allocations.each do |allocation|
    SponsoredProjectEffort.new_from_sponsored_project_allocation(allocation)
  end
end

Instance Method Details

#unique_user_to_project_allocation?Boolean

Returns:

  • (Boolean)

9
10
11
12
13
14
# File 'app/models/sponsored_project_allocation.rb', line 9

def unique_user_to_project_allocation?
  duplicate = SponsoredProjectAllocation.find_by_user_id_and_sponsored_project_id(self.user_id, self.sponsored_project_id)
  unless duplicate.nil? || duplicate.id == self.id
    errors.add(:base, "Can't create duplicate allocation for the same person to project.")
  end
end