##// END OF EJS Templates
added 999 as a maximum for time entry hours...
Jean-Philippe Lang -
r366:76d4ac17a2aa
parent child
Show More
@@ -1,33 +1,33
1 1 class TimeEntry < ActiveRecord::Base
2 2 # could have used polymorphic association
3 3 # project association here allows easy loading of time entries at project level with one database trip
4 4 belongs_to :project
5 5 belongs_to :issue
6 6 belongs_to :user
7 7 belongs_to :activity, :class_name => 'Enumeration', :foreign_key => :activity_id
8 8
9 9 attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek
10 10
11 11 validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
12 12 validates_numericality_of :hours, :allow_nil => true
13 13 validates_length_of :comment, :maximum => 255
14 14
15 15 def before_validation
16 16 self.project = issue.project if issue && project.nil?
17 17 end
18 18
19 19 def validate
20 errors.add :hours, :activerecord_error_invalid if hours && hours < 0
20 errors.add :hours, :activerecord_error_invalid if hours && (hours < 0 || hours >= 1000)
21 21 errors.add :project_id, :activerecord_error_invalid if project.nil?
22 22 errors.add :issue_id, :activerecord_error_invalid if (issue_id && !issue) || (issue && project!=issue.project)
23 23 end
24 24
25 25 # tyear, tmonth, tweek assigned where setting spent_on attributes
26 26 # these attributes make time aggregations easier
27 27 def spent_on=(date)
28 28 super
29 29 self.tyear = spent_on ? spent_on.year : nil
30 30 self.tmonth = spent_on ? spent_on.month : nil
31 31 self.tweek = spent_on ? spent_on.cweek : nil
32 32 end
33 33 end
General Comments 0
You need to be logged in to leave comments. Login now