Class: Project

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
GuidReferenced
Defined in:
app/models/project.rb

Instance Method Summary collapse

Instance Method Details

#allows_access?(user) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'app/models/project.rb', line 64

def allows_access?(user)
  accepts_roles_by?(user) || user.admin?
end

#files_and_commentsObject



68
69
70
# File 'app/models/project.rb', line 68

def files_and_comments
  [comments, file_attachments].flatten.sort_by {|x| x.created_at}
end

#hoursObject



40
41
42
# File 'app/models/project.rb', line 40

def hours
  WorkUnit.for_project(self).sum(:effective_hours)
end

#hours_this_monthObject



44
45
46
# File 'app/models/project.rb', line 44

def hours_this_month
  WorkUnit.for_project(self).scheduled_between(Time.zone.now.beginning_of_month, Time.zone.now.end_of_month).sum(:effective_hours)
end

#hours_this_weekObject



48
49
50
# File 'app/models/project.rb', line 48

def hours_this_week
  WorkUnit.for_project(self).scheduled_between(Time.zone.now.beginning_of_week, Time.zone.now.end_of_week).sum(:effective_hours)
end

#to_sObject



56
57
58
59
60
61
62
# File 'app/models/project.rb', line 56

def to_s
  if new_record?
    I18n.t(:new_project)
  else
    name
  end
end

#uninvoiced_hoursObject



36
37
38
# File 'app/models/project.rb', line 36

def uninvoiced_hours
  WorkUnit.for_project(self).not_invoiced.sum(:effective_hours)
end

#work_unitsObject



52
53
54
# File 'app/models/project.rb', line 52

def work_units
  WorkUnit.for_project(self)
end