mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-29 10:24:20 +01:00
c7a59c8cb7
We need to achieve only one process for all booking, not one for subscription, one for reservations, etc. Moreover we must store one object per invoice_item/payment_schedule_object and stop using Invoice.invoiced or PaymentSchedule.scheduled
33 lines
1.0 KiB
Ruby
33 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# A space reservation added to the shopping cart
|
|
class CartItem::SpaceReservation < CartItem::Reservation
|
|
# @param plan {Plan} a subscription bought at the same time of the reservation OR an already running subscription
|
|
# @param new_subscription {Boolean} true is new subscription is being bought at the same time of the reservation
|
|
def initialize(customer, operator, space, slots, plan: nil, new_subscription: false)
|
|
raise TypeError unless space.is_a? Space
|
|
|
|
super(customer, operator, space, slots)
|
|
@plan = plan
|
|
@new_subscription = new_subscription
|
|
end
|
|
|
|
def to_object
|
|
::Reservation.new(
|
|
reservable_id: @reservable.id,
|
|
reservable_type: Space.name,
|
|
slots_attributes: slots_params,
|
|
statistic_profile_id: StatisticProfile.find_by(user: @customer).id
|
|
)
|
|
end
|
|
|
|
protected
|
|
|
|
def credits
|
|
return 0 if @plan.nil?
|
|
|
|
space_credit = @plan.space_credits.find { |credit| credit.creditable_id == @reservable.id }
|
|
credits_hours(space_credit, @new_subscription)
|
|
end
|
|
end
|