Class: WorkUnit
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- WorkUnit
show all
- Extended by:
- Finders
- Includes:
- GuidReferenced
- Defined in:
- app/models/work_unit.rb,
app/models/work_unit/finders.rb
Defined Under Namespace
Modules: Finders
Instance Method Summary
collapse
Methods included from Finders
cto, except_client, for_client, for_project, for_ticket, for_user, for_users, hours_types, normal, not_invoiced, on_estimated_ticket, overtime, pto, scheduled_between, sort_by_scheduled_at, unpaid
Instance Method Details
#allows_access?(user) ⇒ Boolean
70
71
72
|
# File 'app/models/work_unit.rb', line 70
def allows_access?(user)
project.accepts_roles_by?(user) || user.has_role?(:admin)
end
|
#client ⇒ Object
38
39
40
|
# File 'app/models/work_unit.rb', line 38
def client
(ticket && ticket.client) ? ticket.project.client : nil
end
|
#email_list ⇒ Object
34
35
36
|
# File 'app/models/work_unit.rb', line 34
def email_list
Contact.for_client(self.client).receives_email.map(&:email_address)
end
|
#external? ⇒ Boolean
26
27
28
|
# File 'app/models/work_unit.rb', line 26
def external?
!internal?
end
|
#internal? ⇒ Boolean
22
23
24
|
# File 'app/models/work_unit.rb', line 22
def internal?
SiteSettings.first.try(:client) == client
end
|
#invoiced? ⇒ Boolean
54
55
56
|
# File 'app/models/work_unit.rb', line 54
def invoiced?
!not_invoiced?
end
|
#not_invoiced? ⇒ Boolean
58
59
60
|
# File 'app/models/work_unit.rb', line 58
def not_invoiced?
invoiced.blank?
end
|
#overtime? ⇒ Boolean
96
97
98
|
# File 'app/models/work_unit.rb', line 96
def overtime?
hours_type == "Overtime"
end
|
#overtime_multiplier ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
|
# File 'app/models/work_unit.rb', line 74
def overtime_multiplier
if ticket && project && project.overtime_multiplier
project.overtime_multiplier
elsif client && client.overtime_multiplier
client.overtime_multiplier
elsif SiteSettings.first && SiteSettings.first.overtime_multiplier
SiteSettings.first.overtime_multiplier
else
BigDecimal.new("1.5")
end
end
|
#paid? ⇒ Boolean
50
51
52
|
# File 'app/models/work_unit.rb', line 50
def paid?
!unpaid?
end
|
#project ⇒ Object
42
43
44
|
# File 'app/models/work_unit.rb', line 42
def project
ticket.project
end
|
#send_email! ⇒ Object
30
31
32
|
# File 'app/models/work_unit.rb', line 30
def send_email!
WorkUnitNotifierWorker.perform_async(id, email_list) if email_list.any?
end
|
#set_effective_hours! ⇒ Object
86
87
88
89
90
91
92
93
94
|
# File 'app/models/work_unit.rb', line 86
def set_effective_hours!
if hours
if hours_type == "Overtime"
self.effective_hours = hours * overtime_multiplier
else
self.effective_hours = hours
end
end
end
|
#to_s ⇒ Object
62
63
64
65
66
67
68
|
# File 'app/models/work_unit.rb', line 62
def to_s
if new_record?
I18n.t(:new_work_unit)
else
description[0..80]
end
end
|
#unpaid? ⇒ Boolean
46
47
48
|
# File 'app/models/work_unit.rb', line 46
def unpaid?
paid.blank?
end
|
#validate_client_status ⇒ Object
16
17
18
19
20
|
# File 'app/models/work_unit.rb', line 16
def validate_client_status
if client && client.status == "Inactive"
self.errors.add(:base, "Cannot create work units on inactive clients.")
end
end
|