Defect #8368

Bad decimal separator in time entry CSV

Added by Francisco José Martínez over 10 years ago. Updated almost 10 years ago.

Status:ClosedStart date:2011-05-13
Priority:NormalDue date:
Assignee:Toshi MARUYAMA% Done:

100%

Category:Time tracking
Target version:1.3.0
Resolution:Fixed Affected version:

Description

In file app/helpers/timelog_helper.rb
I've patched two methods do not correctly display the decimal format, because they aren't reading general_csv_decimal_separator. Here are the new methods I've patched:

def report_to_csv_with_td_csv(criterias, periods, hours)
  decimal_separator = l(:general_csv_decimal_separator)

  export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
    # Column headers
    headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) }
    headers += periods
    headers << l(:label_total)
    csv << headers.collect {|c| to_utf8(c) }
    # Content
    report_criteria_to_csv(csv, criterias, periods, hours)
    # Total row
    row = [ l(:label_total) ] + [''] * (criterias.size - 1)
    total = 0
    periods.each do |period|
      sum = sum_hours(select_hours(hours, @columns, period.to_s)) 
      total += sum
      row << (sum > 0 ? ("%.2f" % sum).gsub('.',decimal_separator) : '')
    end
    row << ("%.2f" %total).gsub('.',decimal_separator)
    csv << row
  end
  export      
end

def report_criteria_to_csv_with_td_csv(csv, criterias, periods, hours, level=0)
  decimal_separator = l(:general_csv_decimal_separator)

  hours.collect {|h| h[criterias[level]].to_s}.uniq.each do |value|
    hours_for_value = select_hours(hours, criterias[level], value)
    next if hours_for_value.empty?
    row = [''] * level
    row << to_utf8(format_criteria_value(criterias[level], value))
    row += [''] * (criterias.length - level - 1)
    total = 0
    periods.each do |period|
      sum = sum_hours(select_hours(hours_for_value, @columns, period.to_s))
      total += sum
      row << (sum > 0 ? ("%.2f" % sum).gsub('.',decimal_separator) : '')
    end
    row << ("%.2f" %total).gsub('.',decimal_separator)
    csv << row

    if criterias.length > level + 1
      report_criteria_to_csv(csv, criterias, periods, hours_for_value, level + 1)
    end
  end      
end

timelog_helper.patch Magnifier (1.62 KB) Francisco José Martínez, 2011-05-17 09:17


Related issues

Related to Redmine - Defect #7096: CSV Issues Export + Ruby 1.9 + Thin + non-ascii character... Closed 2010-12-11
Duplicated by Redmine - Defect #9907: CSV Seperator is not used when exporting Time Report as CSV Closed

Associated revisions

Revision 7943
Added by Toshi MARUYAMA almost 10 years ago

add tests to export issues csv in Traditional Chinese and French for csv separator (#8368)

Revision 7944
Added by Toshi MARUYAMA almost 10 years ago

add tests to export time log csv in Traditional Chinese and French for csv separator (#8368)

Revision 7949
Added by Toshi MARUYAMA almost 10 years ago

add csv separator check to the test to export time entry csv in Traditional Chinese (#8368)

Revision 7950
Added by Toshi MARUYAMA almost 10 years ago

fix csv decimal separator of time entry csv (#8368)

Contributed by Francisco José Martínez.

Revision 7951
Added by Toshi MARUYAMA almost 10 years ago

add tests to export time entry csv in French for csv separator (#8368)

History

#1 Updated by Etienne Massip over 10 years ago

  • Category set to Time tracking

#2 Updated by Etienne Massip over 10 years ago

  • Target version set to Candidate for next minor release

Seems you found inspiration in IssueHelper#issues_to_csv, looks fine to me.

Could you post a .patch/.diff file instead of the whole changed methods, please ?

#3 Updated by Etienne Massip over 10 years ago

  • Target version changed from Candidate for next minor release to Candidate for next major release

#4 Updated by Francisco José Martínez over 10 years ago

Sorry, this is my first patch.
Affirmative, the inspiration came from IssueHelper#issues_to_csv

#5 Updated by Toshi MARUYAMA over 10 years ago

  • Assignee set to Toshi MARUYAMA
  • Target version changed from Candidate for next major release to 1.3.0

#6 Updated by Toshi MARUYAMA almost 10 years ago

  • Tracker changed from Patch to Defect
  • Target version changed from 1.3.0 to 1.2.3

#7 Updated by Toshi MARUYAMA almost 10 years ago

  • Subject changed from Fixing bad format in CSV exports to Bad decimal separator in time entry CSV

#8 Updated by Toshi MARUYAMA almost 10 years ago

  • Status changed from New to Confirmed

#9 Updated by Toshi MARUYAMA almost 10 years ago

  • Target version changed from 1.2.3 to 1.3.0

#10 Updated by Toshi MARUYAMA almost 10 years ago

  • % Done changed from 0 to 100

#11 Updated by Toshi MARUYAMA almost 10 years ago

  • Status changed from Confirmed to Closed
  • Resolution set to Fixed

Committed in r7951.

Also available in: Atom PDF