Browse Source

Fixes #4924 - No possibility to export merged tickets in reports.

Mantas Masalskis 9 months ago
parent
commit
ca854d308e

+ 7 - 0
app/models/report.rb

@@ -70,6 +70,13 @@ class Report
         adapter:      Report::TicketMoved,
         params:       { type: 'out' }
       },
+      {
+        name:         'merged',
+        display:      __('Merged'),
+        selected:     false,
+        dataDownload: true,
+        adapter:      Report::TicketMerged,
+      },
     ]
     config[:metric][:count][:backend] = backend
 

+ 4 - 0
i18n/zammad.pot

@@ -8388,6 +8388,10 @@ msgstr ""
 msgid "Merge to Ticket#"
 msgstr ""
 
+#: app/models/report.rb
+msgid "Merged"
+msgstr ""
+
 #: app/assets/javascripts/app/controllers/_channel/sms.coffee
 #: app/assets/javascripts/app/views/maintenance.jst.eco
 #: public/assets/form/form.js

+ 1 - 1
lib/report/article_by_type_sender.rb

@@ -22,7 +22,7 @@ returns
 =end
 
   def self.aggs(params_origin)
-    params = params_origin.dup
+    params = params_origin.deep_dup
 
     result = []
     case params[:interval]

+ 17 - 1
lib/report/base.rb

@@ -11,7 +11,6 @@ class Report::Base
   # :end
   # :selector
   def self.history_count(params)
-
     history_object = History::Object.lookup(name: params[:object])
 
     query, bind_params, tables = Ticket.selector2sql(params[:selector])
@@ -357,4 +356,21 @@ class Report::Base
     true
   end
 
+  INTERVAL_LENGTH = {
+    month:  12,
+    week:   7,
+    # day:  31, Day is counted bellow by given month/year
+    hour:   24,
+    minute: 60,
+  }.with_indifferent_access
+
+  def self.interval_length(params)
+    interval = params[:interval]
+
+    if interval == 'day'
+      return Time.days_in_month params[:range_start].month, params[:range_start].year
+    end
+
+    INTERVAL_LENGTH[interval]
+  end
 end

+ 1 - 1
lib/report/ticket_backlog.rb

@@ -19,7 +19,7 @@ returns
 =end
 
   def self.aggs(params_origin)
-    params = params_origin.dup
+    params = params_origin.deep_dup
 
     local_params = params.clone
     local_params[:params] = {}

+ 1 - 1
lib/report/ticket_first_solution.rb

@@ -18,7 +18,7 @@ returns
 =end
 
   def self.aggs(params_origin)
-    params = params_origin.dup
+    params = params_origin.deep_dup
 
     result = []
     case params[:interval]

+ 1 - 1
lib/report/ticket_generic_time.rb

@@ -20,7 +20,7 @@ returns
 =end
 
   def self.aggs(params_origin)
-    params = params_origin.dup
+    params = params_origin.deep_dup
     interval_es = params[:interval]
     if params[:interval] == 'week'
       interval_es = 'day'

+ 82 - 0
lib/report/ticket_merged.rb

@@ -0,0 +1,82 @@
+# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
+
+class Report::TicketMerged < Report::Base
+
+  # Returns amount of merged tickets in a given time range
+  # sliced by given time interval.
+  #
+  # @example
+  #
+  # result = Report::TicketMerged.aggs(
+  #   range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
+  #   range_end:   Time.zone.parse('2015-12-31T23:59:59Z'),
+  #   interval:    'month', # month, week, day, hour, minute, second
+  #   selector:    selector, # ticket selector to get only a collection of tickets
+  #   timezone:    'Europe/Berlin',
+  # )
+  # #=> [4,5,1,5,0,51,5,56,7,4]
+  #
+  # @return [Array<Integer>]
+  def self.aggs(params_origin)
+    params = params_origin.deep_dup
+
+    Array.new(interval_length(params)) do |_counter|
+      case params[:interval]
+      when 'month'
+        params[:range_end] = params[:range_start].next_month
+      when 'week', 'day'
+        params[:range_end] = params[:range_start].next_day
+      when 'hour'
+        params[:range_end] = params[:range_start] + 1.hour
+      when 'minute'
+        params[:range_end] = params[:range_start] + 1.minute
+      end
+
+      count = history_count(query_params(params))
+
+      params[:range_start] = params[:range_end]
+
+      count
+    end
+  end
+
+  # Returns merged tickets in a given time range matching the selector
+  #
+  # @example
+  #
+  # result = Report::TicketMerged.items(
+  #   range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
+  #   range_end:   Time.zone.parse('2015-12-31T23:59:59Z'),
+  #   selector:    selector, # ticket selector to get only a collection of tickets
+  # )
+  #
+  # #=> {
+  #   count: 123,
+  #   ticket_ids: [4,5,1,5,0,51,5,56,7,4],
+  #   assets: assets,
+  # }
+  #
+  # @return [Hash]
+  def self.items(params)
+    result = history(query_params(params))
+
+    if params[:sheet].blank?
+      result[:assets] = ApplicationModel::CanAssets
+        .reduce(Ticket.where(id: result[:ticket_ids]), {})
+    end
+
+    result
+  end
+
+  def self.query_params(params)
+    {
+      object:    'Ticket',
+      type:      'updated',
+      attribute: 'state',
+      start:     params[:range_start],
+      end:       params[:range_end],
+      selector:  params[:selector],
+      id_to:     Ticket::State.lookup(name: 'merged').id,
+    }
+  end
+end

+ 1 - 1
lib/report/ticket_moved.rb

@@ -20,7 +20,7 @@ returns
 =end
 
   def self.aggs(params_origin)
-    params = params_origin.dup
+    params = params_origin.deep_dup
 
     selector = params[:selector]['ticket.group_id']
 

+ 1 - 1
lib/report/ticket_reopened.rb

@@ -19,7 +19,7 @@ returns
 =end
 
   def self.aggs(params_origin)
-    params = params_origin.dup
+    params = params_origin.deep_dup
     ticket_state_ids = ticket_ids
 
     result = []

Some files were not shown because too many files changed in this diff