Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix grouped_durations query #1862

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/services/reports/time_entries/report_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def group_by_total_duration

filter_service = TimeEntries::Filters.new(params)
where_conditions = filter_service.process
where_conditions.delete(:client_id) if where_conditions.key?(:client_id)

joins_clause, group_field = case group_by
when :client
Expand All @@ -86,9 +85,14 @@ def group_by_total_duration
raise ArgumentError, "Unsupported group_by: #{group_by}"
end

if where_conditions.key?(:client_id)
where_conditions["clients.id"] = where_conditions[:client_id]
where_conditions.delete(:client_id)
joins_clause = { user: [], project: :client }
end

grouped_durations = TimesheetEntry.kept.joins(joins_clause)
.where(where_conditions)
.reorder("")
.group(group_field)
.sum(:duration)

Expand Down
Loading