mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-30 19:52:20 +01:00
(bug) auto cancel trainings
- Wrong trainings sessions was cancelled (in the past instead of in the futur) - Notifications about auto refunds was incorrect
This commit is contained in:
parent
ef92e607f4
commit
23ba44bc57
@ -12,7 +12,10 @@ class Trainings::AutoCancelService
|
||||
|
||||
training.availabilities
|
||||
.includes(slots: :slots_reservations)
|
||||
.where('availabilities.start_at >= ?', DateTime.current - training.auto_cancel_deadline.hours)
|
||||
.where(availabilities: { lock: false })
|
||||
.where('availabilities.start_at >= ? AND availabilities.start_at <= ?',
|
||||
DateTime.current,
|
||||
DateTime.current + training.auto_cancel_deadline.hours)
|
||||
.find_each do |availability|
|
||||
next if availability.reservations.count >= training.auto_cancel_threshold
|
||||
|
||||
@ -72,8 +75,11 @@ class Trainings::AutoCancelService
|
||||
# @param reservation [Reservation]
|
||||
def refund_after_cancel(reservation)
|
||||
invoice_item = reservation.invoice_items.joins(:invoice).where(invoices: { type: nil }).first
|
||||
amount = (invoice_item&.amount_after_coupon || 0) / 100.00
|
||||
return if amount.zero?
|
||||
|
||||
service = WalletService.new(user: reservation.user, wallet: reservation.user.wallet)
|
||||
transaction = service.credit(invoice_item.amount_after_coupon / 100.00)
|
||||
transaction = service.credit(amount)
|
||||
service.create_avoir(transaction, DateTime.current, I18n.t('trainings.refund_for_auto_cancel')) if transaction
|
||||
end
|
||||
end
|
||||
|
@ -4,4 +4,4 @@ json.title notification.notification_type
|
||||
json.description "#{t('.auto_cancelled_training', {
|
||||
TRAINING: notification.attached_object.trainings.first.name,
|
||||
DATE: I18n.l(notification.attached_object.start_at.to_date)
|
||||
})} #{notification.meta_data['auto_refund'] == 'true' ? t('.auto_refund') : t('.manual_refund')}"
|
||||
})} #{notification.meta_data['auto_refund'] ? t('.auto_refund') : t('.manual_refund')}"
|
||||
|
@ -3,5 +3,5 @@
|
||||
json.title notification.notification_type
|
||||
json.description "#{t('.auto_cancelled_training', {
|
||||
TRAINING: notification.attached_object.reservation.reservable.name,
|
||||
DATE: I18n.l(notification.attached_object.start_at.to_date)
|
||||
})} #{notification.meta_data['auto_refund'] == 'true' ? t('.auto_refund') : ''}"
|
||||
DATE: I18n.l(notification.attached_object.slot.start_at.to_date)
|
||||
})} #{notification.meta_data['auto_refund'] ? t('.auto_refund') : ''}"
|
||||
|
@ -9,5 +9,5 @@
|
||||
}) %>
|
||||
</p>
|
||||
<p>
|
||||
<%= @notification.get_meta_data(:auto_refund) == 'true' ? t('.body.auto_refund') : t('.body.manual_refund') %>
|
||||
<%= @notification.get_meta_data(:auto_refund) ? t('.body.auto_refund') : t('.body.manual_refund') %>
|
||||
</p>
|
||||
|
@ -9,5 +9,5 @@
|
||||
}) %>
|
||||
</p>
|
||||
<p>
|
||||
<%= @notification.get_meta_data(:auto_refund) == 'true' ? t('.body.auto_refund') : '' %>
|
||||
<%= @notification.get_meta_data(:auto_refund) ? t('.body.auto_refund') : '' %>
|
||||
</p>
|
||||
|
Loading…
x
Reference in New Issue
Block a user