1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-30 19:52:20 +01:00

(bug) event cannot update nb of free places

This commit is contained in:
Du Peng 2023-07-12 12:26:49 +02:00
parent 25d8b25808
commit e8228ce48f

View File

@ -87,11 +87,9 @@ class Event < ApplicationRecord
if nb_total_places.nil? if nb_total_places.nil?
self.nb_free_places = nil self.nb_free_places = nil
else else
reserved_places = reservations.joins(:slots_reservations) reserved = reservations.joins(:slots_reservations).where('slots_reservations.canceled_at': nil)
.where('slots_reservations.canceled_at': nil) reserved = reserved.where('slots_reservations.is_valid': true) if pre_registration?
.where('slots_reservations.is_valid': true) reserved_places = reserved.map(&:total_booked_seats).inject(0) { |sum, t| sum + t }
.map(&:total_booked_seats)
.inject(0) { |sum, t| sum + t }
self.nb_free_places = (nb_total_places - reserved_places) self.nb_free_places = (nb_total_places - reserved_places)
end end
end end