1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/models/cart_item/free_extension.rb

43 lines
943 B
Ruby
Raw Normal View History

2021-10-12 14:07:35 +02:00
# frozen_string_literal: true
# A subscription extended for free, added to the shopping cart
class CartItem::FreeExtension < CartItem::BaseItem
2022-12-28 17:51:27 +01:00
belongs_to :customer_profile, class_name: 'InvoicingProfile'
belongs_to :subscription
2021-10-12 14:07:35 +02:00
2022-12-28 17:51:27 +01:00
def customer
statistic_profile.user
2021-10-12 14:07:35 +02:00
end
def start_at
2022-12-28 17:51:27 +01:00
raise InvalidSubscriptionError if subscription.nil?
if new_expiration_date.nil? || new_expiration_date <= subscription.expired_at
raise InvalidSubscriptionError, I18n.t('cart_items.must_be_after_expiration')
end
2021-10-12 14:07:35 +02:00
2022-12-28 17:51:27 +01:00
subscription.expired_at
2021-10-12 14:07:35 +02:00
end
def price
elements = { OfferDay: 0 }
{ elements: elements, amount: 0 }
end
def name
2023-02-24 17:26:55 +01:00
I18n.t('cart_items.free_extension', **{ DATE: I18n.l(new_expiration_date) })
2021-10-12 14:07:35 +02:00
end
def to_object
::OfferDay.new(
2022-12-28 17:51:27 +01:00
subscription_id: subscription.id,
2021-10-12 14:07:35 +02:00
start_at: start_at,
2022-12-28 17:51:27 +01:00
end_at: new_expiration_date
2021-10-12 14:07:35 +02:00
)
end
def type
'subscription'
end
2021-10-12 14:07:35 +02:00
end