プロジェクト

全般

プロフィール

Vote #79531

未完了

Adding a 'Custom Field' to 'Activities (time tracking)' prevents time entry on project change

Admin Redmine さんが約2年前に追加. 約2年前に更新.

ステータス:
New
優先度:
通常
担当者:
-
カテゴリ:
Time tracking_13
対象バージョン:
-
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
13
version_id:
0
issue_org_id:
29622
author_id:
356606
assigned_to_id:
0
comments:
2
status_id:
1
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
139
ステータス-->[New]

説明

Two projects have identical values for time tracking activity and custom field:

attachment:field_work_settings.png
attachment:consulting_settings.png

But if you try to move an issue from one project to the other and create a time entry with that time tracking activity, the following errors occur:

attachment:time_entry_error.png

The validation for the time entry should not fail, since both projects have the same activity with the same custom field value.

Our workflow dictates to create a time entry on every issue update, regardless of the content of the update. So moving the issue to another project, then creating a time entry is out of the question.

Seperate values for identical activities can be seen in the database, so inclusion validation always seems to fail:

 19 | QA                      |        3 | f          | TimeEntryActivity | t      |          3 |        14 | 
 18 | QA                      |        3 | f          | TimeEntryActivity | t      |          2 |        14 | 
 14 | QA                      |        3 | f          | TimeEntryActivity | t      |            |           | 


journals

Ercan Demirel wrote:
> But if you try to move an issue from one project to the other and create a time entry with that time tracking activity, the following errors occur:
>
> attachment:time_entry_error.png
>
> The validation for the time entry should not fail, since both projects have the same activity with the same custom field value.

There are two kinds of activities.
* Administration > Enumerations > Activities (time tracking): These activities are *system activities* . The original of the activities updated in each project.
* [project] > Settings > Time tracking: These activities are duplications of system activities. If you edit the value of the custom fields or switch between Active/Inactive, the checkmark of the system activity column disappears and it is re-registered as a project-specific activity.
!{width:600px;border:1px solid grey;}project-time-tracking-settings.png!

---

> Seperate values for identical activities can be seen in the database, so inclusion validation always seems to fail:
> <pre>
19 | QA | 3 | f | TimeEntryActivity | t | 3 | 14 |
18 | QA | 3 | f | TimeEntryActivity | t | 2 | 14 |
14 | QA | 3 | f | TimeEntryActivity | t | | |
</pre>

Perhaps I think the QA of Field Work and the QA of Consulting have different activity ids (18 or 19). When changing the issue's project, the time entry's activity must be replaced with a valid activity in the destination project.

--------------------------------------------------------------------------------
I created the following patch.

<pre><code class="diff">
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 5c1911eb8d..4faa063762 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -1679,8 +1679,28 @@ class Issue < ActiveRecord::Base
end

def after_project_change
- # Update project_id on related time entries
- TimeEntry.where({:issue_id => id}).update_all(["project_id = ?", project_id])
+ # Update project_id and activity_id on related time entries
+ activities = project.activities
+ time_entries.each do |time_entry|
+ curr_activity = time_entry.activity
+ curr_activity_id = (curr_activity.parent_id || curr_activity.id)
+ new_activity =
+ activities.detect do |activity|
+ activity.id == curr_activity_id || activity.parent_id == curr_activity_id
+ end
+
+ time_entry.project = project
+ time_entry.activity = new_activity unless curr_activity == new_activity
+ unless time_entry.save
+ errors.add(
+ :base,
+ l(:error_move_of_time_entries_not_possible,
+ :id => "##{time_entry.id}",
+ :errors => time_entry.errors.full_messages.join(", "))
+ )
+ raise ActiveRecord::Rollback
+ end
+ end

# Delete issue relations
unless Setting.cross_project_issue_relations?
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 2eb4af0e13..8693538ac1 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -229,6 +229,7 @@ en:
error_no_tracker_allowed_for_new_issue_in_project: "The project doesn't have any trackers for which you can create an issue"
error_no_projects_with_tracker_allowed_for_new_issue: "There are no projects with trackers for which you can create an issue"
error_move_of_child_not_possible: "Subtask %{child} could not be moved to the new project: %{errors}"
+ error_move_of_time_entries_not_possible: "Spent time %{id} could not be moved to the new project: %{errors}"
error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: "Spent time cannot be reassigned to an issue that is about to be deleted"
warning_fields_cleared_on_bulk_edit: "Changes will result in the automatic deletion of values from one or more fields on the selected objects"
error_exceeds_maximum_hours_per_day: "Cannot log more than %{max_hours} hours on the same day (%{logged_hours} hours have already been logged)"
</code></pre>
--------------------------------------------------------------------------------

Admin Redmine さんが約2年前に更新

  • カテゴリTime tracking_13 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0