Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

fix total spent hours query for version

Klaus Zandersd1a32437481b
diff --git a/app/models/version.rb b/app/models/version.rb
index 8b545c02259..50438668fb6 100644
--- a/app/models/version.rb
+++ b/app/models/version.rb
@@ -94,8 +94,8 @@ class Version < ApplicationRecord
def spent_hours
@spent_hours ||= TimeEntry
.not_ongoing
- .includes(:work_package)
- .where(work_packages: { version_id: id })
+ .joins("INNER JOIN work_packages ON entity_type = 'WorkPackage' AND work_packages.id = entity_id")
+ .where(work_packages: { version_id: id }, entity_type: "WorkPackage")
.sum(:hours)
.to_f
end