diff --git a/app/models/availability.rb b/app/models/availability.rb index ff7e63d96..06b077a38 100644 --- a/app/models/availability.rb +++ b/app/models/availability.rb @@ -89,7 +89,7 @@ class Availability < ApplicationRecord def available_space_places return unless available_type == 'space' - duration = slot_duration || Setting.get('slot_duration') + duration = slot_duration || Setting.get('slot_duration').to_i ((end_at - start_at) / duration.minutes).to_i * nb_total_places end @@ -162,7 +162,7 @@ class Availability < ApplicationRecord def length_must_be_slot_multiple return unless available_type == 'machines' || available_type == 'space' - duration = slot_duration || Setting.get('slot_duration') + duration = slot_duration || Setting.get('slot_duration').to_i return unless end_at < (start_at + duration.minutes) errors.add(:end_at, I18n.t('availabilities.length_must_be_slot_multiple', MIN: duration)) diff --git a/app/services/availabilities/availabilities_service.rb b/app/services/availabilities/availabilities_service.rb index 167755aec..5d4662c91 100644 --- a/app/services/availabilities/availabilities_service.rb +++ b/app/services/availabilities/availabilities_service.rb @@ -17,7 +17,7 @@ class Availabilities::AvailabilitiesService slots = [] availabilities.each do |a| - slot_duration = a.slot_duration || Setting.get('slot_duration') + slot_duration = a.slot_duration || Setting.get('slot_duration').to_i ((a.end_at - a.start_at) / slot_duration.minutes).to_i.times do |i| next unless (a.start_at + (i * slot_duration).minutes) > DateTime.current || user.admin? @@ -44,7 +44,7 @@ class Availabilities::AvailabilitiesService slots = [] availabilities.each do |a| - slot_duration = a.slot_duration || Setting.get('slot_duration') + slot_duration = a.slot_duration || Setting.get('slot_duration').to_i ((a.end_at - a.start_at) / slot_duration.minutes).to_i.times do |i| next unless (a.start_at + (i * slot_duration).minutes) > DateTime.current || user.admin? diff --git a/app/services/availabilities/public_availabilities_service.rb b/app/services/availabilities/public_availabilities_service.rb index 7e0fce152..efee253c7 100644 --- a/app/services/availabilities/public_availabilities_service.rb +++ b/app/services/availabilities/public_availabilities_service.rb @@ -15,7 +15,7 @@ class Availabilities::PublicAvailabilitiesService .where(lock: false) slots = [] availabilities.each do |a| - slot_duration = a.slot_duration || Setting.get('slot_duration') + slot_duration = a.slot_duration || Setting.get('slot_duration').to_i a.machines.each do |machine| next unless machine_ids&.include?(machine.id.to_s) @@ -46,7 +46,7 @@ class Availabilities::PublicAvailabilitiesService slots = [] availabilities.each do |a| - slot_duration = a.slot_duration || Setting.get('slot_duration') + slot_duration = a.slot_duration || Setting.get('slot_duration').to_i space = a.spaces.first ((a.end_at - a.start_at) / slot_duration.minutes).to_i.times do |i| next unless (a.start_at + (i * slot_duration).minutes) > DateTime.current diff --git a/app/views/exports/availabilities_index.xlsx.axlsx b/app/views/exports/availabilities_index.xlsx.axlsx index af56b60d9..c08414983 100644 --- a/app/views/exports/availabilities_index.xlsx.axlsx +++ b/app/views/exports/availabilities_index.xlsx.axlsx @@ -16,7 +16,7 @@ wb.add_worksheet(name: t('export_availabilities.machines')) do |sheet| # data rows @availabilities.where(available_type: 'machines').order(:start_at).each do |a| - slot_duration = a.slot_duration || Setting.get('slot_duration') + slot_duration = a.slot_duration || Setting.get('slot_duration').to_i a.machines.each do |m| ((a.end_at - a.start_at) / slot_duration.minutes).to_i.times do |i| start_at = a.start_at + (i * slot_duration).minutes @@ -84,7 +84,7 @@ if Setting.get('spaces_module') # data rows @availabilities.where(available_type: 'space').order(:start_at).each do |a| - slot_duration = a.slot_duration || Setting.get('slot_duration') + slot_duration = a.slot_duration || Setting.get('slot_duration').to_i ((a.end_at - a.start_at) / slot_duration.minutes).to_i.times do |i| start_at = a.start_at + (i * slot_duration).minutes end_at = a.start_at + (i * slot_duration).minutes + slot_duration.minutes diff --git a/test/fixtures/history_values.yml b/test/fixtures/history_values.yml index aaa2bfd72..b4bf61b85 100644 --- a/test/fixtures/history_values.yml +++ b/test/fixtures/history_values.yml @@ -598,7 +598,7 @@ history_value_62: id: 62 setting_id: 62 invoicing_profile_id: 1 - value: 'false' + value: 'true' created_at: 2020-06-01 11:12:21.255550000 Z updated_at: 2020-06-01 11:12:21.255550000 Z footprint: