Project

General

Profile

Actions

Patch #3803

open

Show custom user fields in csv export of time entry reports

Added by Roderik van der Veer about 15 years ago. Updated about 15 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Time tracking
Target version:
-
Start date:
2009-09-01
Due date:
% Done:

0%

Estimated time:

Description

Ok, fist of all, this was my first morning of ruby hacking, so code quality = 0. But it does what i need for now, and i wanted to share it.

The idea is as follows, i use these csv's to get my data in categories and per user into excel and do analysis on them. The problem is that not all users work at the same rate, and that is kinda vital to my analysis. I also don't want to copy paste in excel until i have a "rate" column for every user in every category in every product. The Rate plugin did,'t integrate with the normal time tracking export so i changed some core code by myself.

So i created a custom field on user (Rate) and i added some "if" statements in report_ ... _to_csv in the timeloghelper.rb. If "Member" is in the criteria, i add the custom fields of user just behind the Member column. This way i would have a colum "Member" and a column "Rate" (or any other custom user field i make.

To make it work i changed these to methods like so:

Index: timelog_helper.rb
===================================================================
--- timelog_helper.rb   (revision 2847)
+++ timelog_helper.rb   (working copy)
@@ -68,6 +68,8 @@
     ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
     decimal_separator = l(:general_csv_decimal_separator)
     custom_fields = TimeEntryCustomField.find(:all)
+    #custom_user_fields = UserCustomField.find(:all)
+    #raise custom_user_fields.inspect
     export = StringIO.new
     CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
       # csv header fields
@@ -115,6 +117,11 @@
     CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
       # Column headers
       headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) }
+      #logger.info{headers.inspect}
+      if headers.include?("Member")
+          custom_user_fields = UserCustomField.find(:all)
+         headers += custom_user_fields.collect(&:name)
+      end
       headers += periods
       headers << l(:label_total)
       csv << headers.collect {|c| to_utf8(c) }
@@ -141,6 +148,14 @@
       next if hours_for_value.empty?
       row = [''] * level
       row << to_utf8(format_criteria_value(criterias[level], value))
+      #logger.info criterias.inspect
+      if (criterias[level] == "member")
+             k = @available_criterias[criterias[level]][:klass]
+             user = k.find_by_id(value.to_i)
+             custom_user_fields = UserCustomField.find(:all)
+             #logger.info user.inspect
+             row += custom_user_fields.collect {|f| show_value(user.custom_value_for(f)) }
+      end
       row += [''] * (criterias.length - level - 1)
       total = 0
       periods.each do |period|
Actions

Also available in: Atom PDF