Commit d1fc3d47 by Nguyen Vo Huy Hoang

bugfix: group by issue root_id

parent 983ef81a
Pipeline #1631 canceled with stages
in 0 seconds
...@@ -4,13 +4,19 @@ class WorkflowReportIssue < Issue ...@@ -4,13 +4,19 @@ class WorkflowReportIssue < Issue
belongs_to :workflow_report_version, class_name: 'Version', foreign_key: 'fixed_version_id' belongs_to :workflow_report_version, class_name: 'Version', foreign_key: 'fixed_version_id'
has_many :workflow_report_custom_values, class_name: 'WorkflowReportCustomValue', foreign_key: 'customized_id' has_many :workflow_report_custom_values, class_name: 'WorkflowReportCustomValue', foreign_key: 'customized_id'
scope :raw_tasks_records, -> (year, month, project_ids) { scope :raw_tasks_records, -> (root_ids, project_ids) {
includes(:time_entries, project: :enabled_modules)
.where(root_id: root_ids)
.where.not(projects: { status: CLOSED_STATUS_PROJECT }, issues: { tracker_id: BUG_TRACKER_ID, author_id: 1 })
.order(Arel.sql("FIELD(projects.id, #{project_ids.join(',')})"), :root_id)
}
scope :raw_tasks_root, -> (year, month, project_ids) {
includes(:time_entries, project: :enabled_modules) includes(:time_entries, project: :enabled_modules)
.where.not(projects: { status: CLOSED_STATUS_PROJECT }, issues: { tracker_id: BUG_TRACKER_ID }) .where.not(projects: { status: CLOSED_STATUS_PROJECT }, issues: { tracker_id: BUG_TRACKER_ID })
.where(projects: { id: project_ids }, enabled_modules: { name: 'time_tracking' }) .where(projects: { id: project_ids }, enabled_modules: { name: 'time_tracking' })
.where(['((time_entries.spent_on IS NOT NULL AND time_entries.tyear = ? AND time_entries.tmonth = ?) OR (issues.closed_on BETWEEN ? AND ?))', .where(['((time_entries.spent_on IS NOT NULL AND time_entries.tyear = ? AND time_entries.tmonth = ?) OR (issues.closed_on BETWEEN ? AND ?))',
year, month, DateTime.new(year, month).beginning_of_day, DateTime.new(year, month, -1).end_of_day]) year, month, DateTime.new(year, month).beginning_of_day, DateTime.new(year, month, -1).end_of_day])
.order(Arel.sql("FIELD(projects.id, #{project_ids.join(',')})"), :root_id)
} }
scope :raw_task_in_date, -> (date_from, date_to, project_ids) { scope :raw_task_in_date, -> (date_from, date_to, project_ids) {
......
...@@ -21,7 +21,8 @@ module WorkflowReport ...@@ -21,7 +21,8 @@ module WorkflowReport
error_links = [] error_links = []
work_queue = Queue.new work_queue = Queue.new
result = TABLE_HEADER.length.times.map { [] } result = TABLE_HEADER.length.times.map { [] }
raw_tasks = WorkflowReportIssue.raw_tasks_records(year, month, project_ids) root_ids = WorkflowReportIssue.raw_tasks_root(year, month, project_ids).uniq.pluck(:root_id)
raw_tasks = WorkflowReportIssue.raw_tasks_records(root_ids, project_ids)
return { workflow_report: [], error_links: [] } if raw_tasks.empty? return { workflow_report: [], error_links: [] } if raw_tasks.empty?
raw_tasks.group_by(&:root_id).each do |root_id, issues| raw_tasks.group_by(&:root_id).each do |root_id, issues|
...@@ -30,10 +31,14 @@ module WorkflowReport ...@@ -30,10 +31,14 @@ module WorkflowReport
root_issue = arr_issue.find(root_id) root_issue = arr_issue.find(root_id)
journals = WorkflowReportJournal.find_journal_by_issue_ids(issue_ids).to_a journals = WorkflowReportJournal.find_journal_by_issue_ids(issue_ids).to_a
target_version = root_issue.workflow_report_version&.name
subject = issues.first.project.name.gsub(/[^[:print:]]/, '')
next if (target_version.present? && target_version.include?("Backlog(Internal)")) || subject.include?("Internal")
result[0] << root_id result[0] << root_id
result[1] << issues.first.project.name.gsub(/[^[:print:]]/, '') result[1] << subject
result[2] << root_issue&.subject.gsub(/[^[:print:]]/, '') result[2] << root_issue&.subject.gsub(/[^[:print:]]/, '')
result[3] << root_issue.workflow_report_version&.name result[3] << target_version
issue_created_on = arr_issue.min_by { |i| i[:created_on] if i[:created_on].present? } issue_created_on = arr_issue.min_by { |i| i[:created_on] if i[:created_on].present? }
result[4].push(issue_created_on.present? ? issue_created_on.created_on&.strftime('%Y-%m-%d %H:%M:%S') : '') result[4].push(issue_created_on.present? ? issue_created_on.created_on&.strftime('%Y-%m-%d %H:%M:%S') : '')
closed_on_issues = arr_issue.map(&:closed_on).compact closed_on_issues = arr_issue.map(&:closed_on).compact
...@@ -195,7 +200,8 @@ module WorkflowReport ...@@ -195,7 +200,8 @@ module WorkflowReport
issue_custom = filtered_values issue_custom = filtered_values
end end
max_value_in_record = issue_custom.map { |custom| custom.value.to_i }.max max_value_in_record = issue_custom.map { |custom| custom.value }.max
return nil if max_value_in_record.nil? || max_value_in_record.empty?
[max_value, max_value_in_record.to_i].max [max_value, max_value_in_record.to_i].max
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment