diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2022-06-20 15:26:47 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2022-06-20 15:26:47 +0000 |
commit | bfcb1b0054ce6ab397025622c4e7309bc8e1dbcb (patch) | |
tree | f0fd76f0112da704a3999cf43643204164d4126d /app | |
parent | e0f0f2c210e0c05a28beb20ede23143fc302f0a6 (diff) | |
download | redmine-bfcb1b0054ce6ab397025622c4e7309bc8e1dbcb.tar.gz redmine-bfcb1b0054ce6ab397025622c4e7309bc8e1dbcb.zip |
Fix time entry activity is not set as default when the default activity exists as project specific activity (#33914).
Patch by Mizuki ISHIKAWA.
git-svn-id: https://svn.redmine.org/redmine/trunk@21668 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 | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index 34e4aab7b..7776db0d8 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 973ec923f..a0be39469 100644 --- a/app/models/time_entry_activity.rb +++ b/app/models/time_entry_activity.rb @@ -22,6 +22,15 @@ class TimeEntryActivity < Enumeration OptionName = :enumeration_activities + def self.default(project=nil) + default_activity = super() + if project.nil? || project.activities.blank? || project.activities.include?(default_activity) + return default_activity + end + + project.activities.find_by(parent_id: default_activity.id) + end + def option_name OptionName end |