mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-28 09:24:24 +01:00
(quality) typed CartItem::Reservation
This commit is contained in:
parent
2316cc5b1e
commit
c3d6206dba
@ -13,18 +13,22 @@ class CartItem::Reservation < CartItem::BaseItem
|
||||
nil
|
||||
end
|
||||
|
||||
# @return [Plan,NilClass]
|
||||
def plan
|
||||
nil
|
||||
end
|
||||
|
||||
# @return [User]
|
||||
def operator
|
||||
operator_profile.user
|
||||
end
|
||||
|
||||
# @return [User]
|
||||
def customer
|
||||
customer_profile.user
|
||||
end
|
||||
|
||||
# @return [Hash{Symbol=>Integer,Hash{Symbol=>Array<Hash{Symbol=>Integer,Float,Boolean,Time}>}}]
|
||||
def price
|
||||
is_privileged = operator.privileged? && operator.id != customer.id
|
||||
prepaid = { minutes: PrepaidPackService.minutes_available(customer, reservable) }
|
||||
@ -48,10 +52,13 @@ class CartItem::Reservation < CartItem::BaseItem
|
||||
{ elements: elements, amount: amount }
|
||||
end
|
||||
|
||||
# @return [String,NilClass]
|
||||
def name
|
||||
reservable&.name
|
||||
end
|
||||
|
||||
# @param all_items [Array<CartItem::BaseItem>]
|
||||
# @return [Boolean]
|
||||
def valid?(all_items = [])
|
||||
pending_subscription = all_items.find { |i| i.is_a?(CartItem::Subscription) }
|
||||
|
||||
@ -91,6 +98,7 @@ class CartItem::Reservation < CartItem::BaseItem
|
||||
true
|
||||
end
|
||||
|
||||
# @return [Reservation]
|
||||
def to_object
|
||||
::Reservation.new(
|
||||
reservable_id: reservable_id,
|
||||
@ -107,7 +115,7 @@ class CartItem::Reservation < CartItem::BaseItem
|
||||
end
|
||||
|
||||
# Group the slots by date, if the extended_prices_in_same_day option is set to true
|
||||
# @return Hash{Symbol => Array<CartItem::ReservationSlot>}
|
||||
# @return [Hash{Symbol => Array<CartItem::ReservationSlot>}]
|
||||
def grouped_slots
|
||||
return { all: cart_item_reservation_slots } unless Setting.get('extended_prices_in_same_day')
|
||||
|
||||
@ -125,7 +133,7 @@ class CartItem::Reservation < CartItem::BaseItem
|
||||
# @option options [Boolean] :has_credits true if the user still has credits for the given slot, false if not provided
|
||||
# @option options [Boolean] :is_division false if the slot covers a full availability, true if it is a subdivision (default)
|
||||
# @option options [Number] :prepaid_minutes number of remaining prepaid minutes for the customer
|
||||
# @return [Float]
|
||||
# @return [Float,Integer]
|
||||
def get_slot_price_from_prices(prices, slot_reservation, is_privileged, options = {})
|
||||
options = GET_SLOT_PRICE_DEFAULT_OPTS.merge(options)
|
||||
|
||||
@ -152,7 +160,7 @@ class CartItem::Reservation < CartItem::BaseItem
|
||||
# @option options [Boolean] :has_credits true if the user still has credits for the given slot, false if not provided
|
||||
# @option options [Boolean] :is_division false if the slot covers a full availability, true if it is a subdivision (default)
|
||||
# @option options [Number] :prepaid_minutes number of remaining prepaid minutes for the customer
|
||||
# @return [Float] price of the slot
|
||||
# @return [Float,Integer] price of the slot
|
||||
def get_slot_price(hourly_rate, slot_reservation, is_privileged, options = {})
|
||||
options = GET_SLOT_PRICE_DEFAULT_OPTS.merge(options)
|
||||
|
||||
@ -245,10 +253,10 @@ class CartItem::Reservation < CartItem::BaseItem
|
||||
cart_item_reservation_slots.map { |sr| { id: sr.slots_reservation_id, slot_id: sr.slot_id, offered: sr.offered } }
|
||||
end
|
||||
|
||||
##
|
||||
# Check if the given availability requires a valid subscription. If so, check if the current customer
|
||||
# has the required susbcription, otherwise, check if the operator is privileged
|
||||
##
|
||||
# @param availability [Availability]
|
||||
# @param pending_subscription [CartItem::Subscription, NilClass]
|
||||
def required_subscription?(availability, pending_subscription)
|
||||
(customer.subscribed_plan && availability.plan_ids.include?(customer.subscribed_plan.id)) ||
|
||||
(pending_subscription && availability.plan_ids.include?(pending_subscription.plan.id)) ||
|
||||
|
@ -73,7 +73,7 @@ class PrepaidPackService
|
||||
|
||||
# Total number of prepaid minutes available
|
||||
# @param user [User]
|
||||
# @param priceable [Machine,Space]
|
||||
# @param priceable [Machine,Space,NilClass]
|
||||
def minutes_available(user, priceable)
|
||||
return 0 if Setting.get('pack_only_for_subscription') && !user.subscribed_plan
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user