Class: Activity
Defined Under Namespace
Classes: Adjustment, Labor, Material, Proposal
Instance Attribute Summary collapse
Instance Method Summary
collapse
append_features
append_features
Constructor Details
#initialize(*args) ⇒ Activity
Returns a new instance of Activity.
20
21
22
|
# File 'app/models/activity.rb', line 20
def initialize(*args)
super(*args)
end
|
Instance Attribute Details
#dont_validate_type_associations ⇒ Object
Returns the value of attribute dont_validate_type_associations.
28
29
30
|
# File 'app/models/activity.rb', line 28
def dont_validate_type_associations
@dont_validate_type_associations
end
|
Instance Method Details
#authorized_for?(options) ⇒ Boolean
79
80
81
82
83
84
85
86
|
# File 'app/models/activity.rb', line 79
def authorized_for?(options)
case options[:action].to_s
when /^(update|destroy)$/
(is_published?) ? false : true
else
true
end
end
|
#ensure_not_published ⇒ Object
63
64
65
66
67
68
|
# File 'app/models/activity.rb', line 63
def ensure_not_published
if is_published?
errors.add_to_base "Can't destroy an activity once its invoice is published"
return false
end
end
|
#is_paid? ⇒ Boolean
55
56
57
|
# File 'app/models/activity.rb', line 55
def is_paid?
(invoice.nil?) ? false : invoice.is_paid?
end
|
#is_published? ⇒ Boolean
59
60
61
|
# File 'app/models/activity.rb', line 59
def is_published?
(invoice.nil?) ? false : invoice.is_published
end
|
#label ⇒ Object
24
25
26
|
# File 'app/models/activity.rb', line 24
def label
(self.activity_type.nil? or self.activity_type.length == 0) ? "Activity" : self.activity_type.capitalize
end
|
#move_to_invoice(dest) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'app/models/activity.rb', line 88
def move_to_invoice(dest)
dest_invoice = (dest.class == Integer) ? Invoice.find(dest) : dest
raise StandardError, "Can't move an already-published activity." if is_published?
raise StandardError, "Can't move an activity to an already published invoice." if dest_invoice.is_published?
self.invoice_id = dest_invoice.id
self.client_id = dest_invoice.client_id
@dont_validate_type_associations = true
save!
@dont_validate_type_associations = false
end
|
#sub_activity ⇒ Object
75
76
77
|
# File 'app/models/activity.rb', line 75
def sub_activity
send activity_type unless activity_type.nil?
end
|
#validate ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/models/activity.rb', line 29
def validate
activity_type_sym = (activity_type.nil? or activity_type.empty?) ? nil : activity_type.to_sym
unless dont_validate_type_associations or !self.class.reflections.has_key?(activity_type_sym)
type_association = instance_variable_get("@#{activity_type}")
if type_association.nil?
errors.add activity_type_sym, 'missing'
else
type_association.valid?
type_association.errors.each { |attr,msg| errors.add attr, msg }
end
end
end
|
#validate_on_update ⇒ Object
70
71
72
|
# File 'app/models/activity.rb', line 70
def validate_on_update
errors.add_to_base "Activity can't be adjusted once its invoice is published" if is_published? and changed_attributes.length > 0
end
|