mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-12 06:54:19 +01:00
(bug) unable to fix availabilities for events
This commit is contained in:
parent
f33bd2ef23
commit
c0b465748a
@ -1,6 +1,7 @@
|
|||||||
# Changelog Fab-manager
|
# Changelog Fab-manager
|
||||||
|
|
||||||
- Fix a bug: unable to configure RAILS_LOCALE to fr-CA
|
- Fix a bug: unable to configure RAILS_LOCALE to fr-CA
|
||||||
|
- Fix a bug: unable to fix availabilities for events
|
||||||
|
|
||||||
## v5.7.0 2023 February 17
|
## v5.7.0 2023 February 17
|
||||||
|
|
||||||
|
@ -12,15 +12,17 @@ namespace :fablab do
|
|||||||
other_slots = Slot.where(availability_id: slot.availability_id)
|
other_slots = Slot.where(availability_id: slot.availability_id)
|
||||||
reservations = SlotsReservation.where(slot_id: other_slots.map(&:id))
|
reservations = SlotsReservation.where(slot_id: other_slots.map(&:id))
|
||||||
|
|
||||||
|
type = available_type(reservations)
|
||||||
a = Availability.new(
|
a = Availability.new(
|
||||||
id: slot.availability_id,
|
id: slot.availability_id,
|
||||||
start_at: other_slots.group('id').select('min(start_at) as min').first[:min],
|
start_at: other_slots.group('id').select('min(start_at) as min').first[:min],
|
||||||
end_at: other_slots.group('id').select('max(end_at) as max').first[:max],
|
end_at: other_slots.group('id').select('max(end_at) as max').first[:max],
|
||||||
available_type: available_type(reservations),
|
available_type: type,
|
||||||
machine_ids: machines_ids(reservations, slot.availability_id),
|
machine_ids: machines_ids(reservations, slot.availability_id),
|
||||||
space_ids: space_ids(reservations, slot.availability_id),
|
space_ids: space_ids(reservations, slot.availability_id),
|
||||||
training_ids: training_ids(reservations, slot.availability_id)
|
training_ids: training_ids(reservations, slot.availability_id)
|
||||||
)
|
)
|
||||||
|
create_mock_event(reservations, slot.availability_id) if type == 'event' && a.event.nil?
|
||||||
raise StandardError, "unable to save availability for slot #{slot.id}: #{a.errors.full_messages}" unless a.save(validate: false)
|
raise StandardError, "unable to save availability for slot #{slot.id}: #{a.errors.full_messages}" unless a.save(validate: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -85,4 +87,32 @@ namespace :fablab do
|
|||||||
|
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @param reservations [ActiveRecord::Relation<SlotsReservation>]
|
||||||
|
# @param availability_id [Number]
|
||||||
|
def create_mock_event(reservations, availability_id)
|
||||||
|
model = find_similar_event(reservations)
|
||||||
|
invoice_item = reservations.first&.reservation&.invoice_items&.find_by(main: true)
|
||||||
|
Event.create!(
|
||||||
|
title: model&.title || invoice_item&.description,
|
||||||
|
description: model&.description || invoice_item&.description,
|
||||||
|
category: model&.category || Category.first,
|
||||||
|
availability_id: availability_id
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
# @param reservations [ActiveRecord::Relation<SlotsReservation>]
|
||||||
|
# @return [Event,NilClass]
|
||||||
|
def find_similar_event(reservations)
|
||||||
|
reservations.each do |reservation|
|
||||||
|
reservation.reservation.invoice_items.each do |invoice_item|
|
||||||
|
words = invoice_item.description.split
|
||||||
|
(0..words.count).each do |w|
|
||||||
|
try_title = words[0..words.count - w].join(' ')
|
||||||
|
event = Event.find_by("title LIKE '#{try_title}%'")
|
||||||
|
return event unless event.nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user