From c35f9ddc2d7a94828534c5777c65d1281d4dc768 Mon Sep 17 00:00:00 2001
From: Katsuya Hidaka <hidakatsuya@gmail.com>
Date: Thu, 27 Feb 2025 22:34:32 +0900
Subject: Fix thousands separator for integer/float custom field totals

---
 app/helpers/queries_helper.rb             |  2 ++
 test/functional/issues_controller_test.rb | 30 ++++++++++++++++++++---
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb
index 708a8acfb..8e109c693 100644
--- a/app/helpers/queries_helper.rb
+++ b/app/helpers/queries_helper.rb
@@ -192,6 +192,8 @@ module QueriesHelper
     value =
       if [:hours, :spent_hours, :total_spent_hours, :estimated_hours, :total_estimated_hours, :estimated_remaining_hours].include? column.name
         format_hours(value)
+      elsif column.is_a?(QueryCustomFieldColumn)
+        format_object(value, thousands_delimiter: column.custom_field.thousands_delimiter?)
       else
         format_object(value)
       end
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index 1eff9b5d1..44483a8f0 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -2003,12 +2003,34 @@ class IssuesControllerTest < Redmine::ControllerTest
 
   def test_index_with_int_custom_field_total
     field = IssueCustomField.generate!(:field_format => 'int', :is_for_all => true)
-    CustomValue.create!(:customized => Issue.find(1), :custom_field => field, :value => '2')
-    CustomValue.create!(:customized => Issue.find(2), :custom_field => field, :value => '7')
-    get(:index, :params => {:t => ["cf_#{field.id}"]})
+    CustomValue.create!(:customized => Issue.find(1), :custom_field => field, :value => '9800')
+    CustomValue.create!(:customized => Issue.find(2), :custom_field => field, :value => '10')
+
+    field_with_delimiter = IssueCustomField.generate!(:field_format => 'int', :thousands_delimiter => '1', :is_for_all => true)
+    CustomValue.create!(:customized => Issue.find(1), :custom_field => field_with_delimiter, :value => '9800')
+    CustomValue.create!(:customized => Issue.find(2), :custom_field => field_with_delimiter, :value => '10')
+
+    get(:index, :params => {:t => ["cf_#{field.id}", "cf_#{field_with_delimiter.id}"]})
+    assert_response :success
+    assert_select '.query-totals'
+    assert_select ".total-for-cf-#{field.id} span.value", :text => '9810'
+    assert_select ".total-for-cf-#{field_with_delimiter.id} span.value", :text => '9,810'
+  end
+
+  def test_index_with_float_custom_field_total
+    field = IssueCustomField.generate!(field_format: 'float', is_for_all: true)
+    CustomValue.create!(customized: Issue.find(1), custom_field: field, value: '1000000.01')
+    CustomValue.create!(customized: Issue.find(2), custom_field: field, value: '99.01')
+
+    field_with_delimiter = IssueCustomField.generate!(field_format: 'float', thousands_delimiter: '1', is_for_all: true)
+    CustomValue.create!(customized: Issue.find(1), custom_field: field_with_delimiter, value: '1000000.01')
+    CustomValue.create!(customized: Issue.find(2), custom_field: field_with_delimiter, value: '99.01')
+
+    get(:index, params: {t: ["cf_#{field.id}", "cf_#{field_with_delimiter.id}"]})
     assert_response :success
     assert_select '.query-totals'
-    assert_select ".total-for-cf-#{field.id} span.value", :text => '9'
+    assert_select ".total-for-cf-#{field.id} span.value", text: '1000099.02'
+    assert_select ".total-for-cf-#{field_with_delimiter.id} span.value", text: '1,000,099.02'
   end
 
   def test_index_with_spent_time_total_should_sum_visible_spent_time_only
-- 
2.45.2

