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