1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-12 23:09:03 +01:00
fab-manager/app/models/cart_item/space_reservation.rb
Nicolas Florentin 043ff6d47e wip
2023-07-20 16:55:22 +02:00

44 lines
1.1 KiB
Ruby

# frozen_string_literal: true
# A space reservation added to the shopping cart
class CartItem::SpaceReservation < CartItem::Reservation
has_many :cart_item_reservation_slots, class_name: 'CartItem::ReservationSlot', dependent: :destroy, inverse_of: :cart_item,
foreign_type: 'cart_item_type', as: :cart_item
accepts_nested_attributes_for :cart_item_reservation_slots
belongs_to :operator_profile, class_name: 'InvoicingProfile'
belongs_to :customer_profile, class_name: 'InvoicingProfile'
belongs_to :reservable, polymorphic: true
belongs_to :plan
belongs_to :reservation_context
def type
'space'
end
def valid?(all_items)
if reservable.disabled
errors.add(:reservable, I18n.t('cart_item_validation.space'))
return false
end
super
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_plan_being_bought: new_subscription)
end
def reservation_deadline_minutes
Setting.get('space_reservation_deadline').to_i
end
end