From 62881bd04418da4e41e0c2a580025e56c0dcef2c Mon Sep 17 00:00:00 2001 From: Grigory Date: Thu, 2 May 2024 18:54:48 +0700 Subject: [PATCH] Fix totals --- app/helpers/custom_table/application_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/custom_table/application_helper.rb b/app/helpers/custom_table/application_helper.rb index 60d485b..2cb5f9d 100644 --- a/app/helpers/custom_table/application_helper.rb +++ b/app/helpers/custom_table/application_helper.rb @@ -133,9 +133,9 @@ def custom_table_totals collection, fields, totals = {}, fields_totals = {} # We can try to sum value from database if fields[field][:total_scope].nil? - out[field] = collection.except(:limit, :offset, :order, :group).sum(field) - else - out[field] = collection.except(:limit, :offset, :order, :group).send(fields[field][:total_scope]) + out[field] = collection.except(:limit, :offset, :order, :group).distinct(false).sum(field) + else + out[field] = collection.except(:limit, :offset, :order, :group).distinct(false).send(fields[field][:total_scope]) end else # Taking simple summed value because all data is shown