diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-03-23 12:22:31 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-03-23 12:22:31 +0000 |
commit | 8d54d9700746636849bd104f4d18db479492505e (patch) | |
tree | a8d9c209a929b2c6a63dbbf2cbc7f717d264ad6f /app/models/time_entry.rb | |
parent | 7cf2d889d8866226378db250a2c7ec2fc77ef9fc (diff) | |
download | redmine-8d54d9700746636849bd104f4d18db479492505e.tar.gz redmine-8d54d9700746636849bd104f4d18db479492505e.zip |
Simple time tracking functionality added. Time can be logged at issue or project level.
There's no aggregation reports for now, it's just possible to see all time entries for a project or an issue.
A new "activities" enumeration is added.
Permission for a role to log time must be set (new "Time tracking" section in role permissions screen).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@368 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/time_entry.rb')
-rw-r--r-- | app/models/time_entry.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb new file mode 100644 index 000000000..4f2c561f5 --- /dev/null +++ b/app/models/time_entry.rb @@ -0,0 +1,33 @@ +class TimeEntry < ActiveRecord::Base + # could have used polymorphic association + # project association here allows easy loading of time entries at project level with one database trip + belongs_to :project + belongs_to :issue + belongs_to :user + belongs_to :activity, :class_name => 'Enumeration', :foreign_key => :activity_id + + attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek + + validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on + validates_numericality_of :hours, :allow_nil => true + validates_length_of :comment, :maximum => 255 + + def before_validation + self.project = issue.project if issue && project.nil? + end + + def validate + errors.add :hours, :activerecord_error_invalid if hours && hours < 0 + errors.add :project_id, :activerecord_error_invalid if project.nil? + errors.add :issue_id, :activerecord_error_invalid if (issue_id && !issue) || (issue && project!=issue.project) + end + + # tyear, tmonth, tweek assigned where setting spent_on attributes + # these attributes make time aggregations easier + def spent_on=(date) + super + self.tyear = spent_on ? spent_on.year : nil + self.tmonth = spent_on ? spent_on.month : nil + self.tweek = spent_on ? spent_on.cweek : nil + end +end |