diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2022-06-20 17:41:24 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2022-06-20 17:41:24 +0000 |
commit | 5dba10c4903cc93a035e764576b56ab690ed6463 (patch) | |
tree | 8a33eebc6e090de20fa51d13e5ef786e0f12d0ce /app | |
parent | 00c1e3528f09a1b83ef7bdf0f3d231de4dff9450 (diff) | |
download | redmine-5dba10c4903cc93a035e764576b56ab690ed6463.tar.gz redmine-5dba10c4903cc93a035e764576b56ab690ed6463.zip |
Merged r21668 and r21669 to 4.2-stable (#33914).
git-svn-id: https://svn.redmine.org/redmine/branches/4.2-stable@21671 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/models/time_entry.rb | 2 | ||||
-rw-r--r-- | app/models/time_entry_activity.rb | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index e72c05117..6867dc95c 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -107,7 +107,7 @@ class TimeEntry < ActiveRecord::Base def initialize(attributes=nil, *args) super if new_record? && self.activity.nil? - if default_activity = TimeEntryActivity.default + if default_activity = TimeEntryActivity.default(self.project) self.activity_id = default_activity.id end self.hours = nil if hours == 0 diff --git a/app/models/time_entry_activity.rb b/app/models/time_entry_activity.rb index f4562a8e1..d988129c9 100644 --- a/app/models/time_entry_activity.rb +++ b/app/models/time_entry_activity.rb @@ -22,6 +22,16 @@ class TimeEntryActivity < Enumeration OptionName = :enumeration_activities + def self.default(project=nil) + default_activity = super() + + if default_activity.nil? || project.nil? || project.activities.blank? || project.activities.include?(default_activity) + return default_activity + end + + project.activities.detect { |activity| activity.parent_id == default_activity.id } + end + def option_name OptionName end |