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

[OP#65622] Do not calculate an end_time when no hours are set

Klaus Zanders28c7a1745ff1
diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rb
index ee502d13d4c..688a3fc35e4 100644
--- a/modules/costs/app/models/time_entry.rb
+++ b/modules/costs/app/models/time_entry.rb
@@ -160,10 +160,11 @@ class TimeEntry < ApplicationRecord
time_zone_object.local(spent_on.year, spent_on.month, spent_on.day, start_time / 60, start_time % 60)
end
- def end_timestamp
+ def end_timestamp # rubocop:disable Metrics/AbcSize
return nil if start_time.blank?
return nil if time_zone.blank?
return nil if spent_on.blank?
+ return nil if hours.blank? && !ongoing?
if ongoing?
start_timestamp + ongoing_hours.hours
diff --git a/modules/costs/spec/models/time_entry_spec.rb b/modules/costs/spec/models/time_entry_spec.rb
index b03088352b8..595a6c880ff 100644
--- a/modules/costs/spec/models/time_entry_spec.rb
+++ b/modules/costs/spec/models/time_entry_spec.rb
@@ -522,6 +522,11 @@ RSpec.describe TimeEntry do
expect(time_entry.end_timestamp).to be_nil
end
+ it "returns nil if hours are nil" do
+ time_entry.hours = nil
+ expect(time_entry.end_timestamp).to be_nil
+ end
+
it "generates a proper timestamp from the stored information" do
time_entry.start_time = 8 * 60
time_entry.hours = 2.5