diff --git a/app/views/hooks/_view_issues_show_details_bottom.html.erb b/app/views/hooks/_view_issues_show_details_bottom.html.erb
index 1fea28595e..ee1539f0bb 100644
--- a/app/views/hooks/_view_issues_show_details_bottom.html.erb
+++ b/app/views/hooks/_view_issues_show_details_bottom.html.erb
@@ -4,7 +4,7 @@
<%# disables core's spent-time as it is not displayed if the user has just the view_own_time_entries permission %>
.spent-time { display: none }
- <% attributes_array = cost_issues_attributes %>
+ <% attributes_array = cost_issues_attributes(controller.work_package) %>
<% (0..(attributes_array.size - 1)).step(2) do |i| %>
diff --git a/lib/open_project/costs/patches/issues_helper_patch.rb b/lib/open_project/costs/patches/issues_helper_patch.rb
index a8c36ec83e..2ba4e664be 100644
--- a/lib/open_project/costs/patches/issues_helper_patch.rb
+++ b/lib/open_project/costs/patches/issues_helper_patch.rb
@@ -42,13 +42,13 @@ module OpenProject::Costs::Patches::IssuesHelperPatch
str_array.join(", ").html_safe
end
- def cost_issues_attributes
+ def cost_issues_attributes(work_package)
attributes = []
- object_value = if @work_package.cost_object.nil?
+ object_value = if work_package.cost_object.nil?
"-"
else
- link_to_cost_object(@work_package.cost_object)
+ link_to_cost_object(work_package.cost_object)
end
attributes << [CostObject.model_name.human, object_value]
@@ -56,8 +56,11 @@ module OpenProject::Costs::Patches::IssuesHelperPatch
if User.current.allowed_to?(:view_time_entries, @project) ||
User.current.allowed_to?(:view_own_time_entries, @project)
- value = @work_package.spent_hours > 0 ?
- link_to(l_hours(@work_package.spent_hours), issue_time_entries_path(@work_package)) : "-"
+ #TODO: put inside controller or model
+ summed_hours = @time_entries.sum(&:hours)
+
+ value = summed_hours > 0 ?
+ link_to(l_hours(summed_hours), issue_time_entries_path(work_package)) : "-"
attributes << [Issue.human_attribute_name(:spent_hours), value]
end
|