mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
remove references to PaymentSchedule.scheduled
This commit is contained in:
parent
5f5ec8dbb6
commit
6cd74ac33e
@ -18,7 +18,7 @@ class Reservation < ApplicationRecord
|
||||
accepts_nested_attributes_for :tickets, allow_destroy: false
|
||||
|
||||
has_many :invoice_items, as: :object, dependent: :destroy
|
||||
has_one :payment_schedule, as: :scheduled, dependent: :destroy
|
||||
has_one :payment_schedule_object, as: :object, dependent: :destroy
|
||||
|
||||
validates_presence_of :reservable_id, :reservable_type
|
||||
validate :machine_not_already_reserved, if: -> { reservable.is_a?(Machine) }
|
||||
|
@ -7,7 +7,7 @@ class Subscription < ApplicationRecord
|
||||
belongs_to :plan
|
||||
belongs_to :statistic_profile
|
||||
|
||||
has_one :payment_schedule, as: :scheduled, dependent: :destroy
|
||||
has_one :payment_schedule_object, as: :object, dependent: :destroy
|
||||
has_one :payment_gateway_object, as: :item
|
||||
has_many :invoice_items, as: :object, dependent: :destroy
|
||||
has_many :offer_days, dependent: :destroy
|
||||
|
@ -12,7 +12,7 @@ class PaymentScheduleService
|
||||
other_items = total - plan.amount
|
||||
# base monthly price of the plan
|
||||
price = plan.amount
|
||||
ps = PaymentSchedule.new(scheduled: plan, total: price + other_items, coupon: coupon)
|
||||
ps = PaymentSchedule.new(total: price + other_items, coupon: coupon)
|
||||
deadlines = plan.duration / 1.month
|
||||
per_month = (price / deadlines).truncate
|
||||
adjustment = if per_month * deadlines + other_items.truncate != ps.total
|
||||
@ -58,7 +58,12 @@ class PaymentScheduleService
|
||||
ps = schedule[:payment_schedule]
|
||||
items = schedule[:items]
|
||||
|
||||
ps.scheduled = reservation || subscription
|
||||
if reservation
|
||||
ps.payment_schedule_objects.push(PaymentScheduleObject.new(object: reservation, main: true))
|
||||
ps.payment_schedule_objects.push(PaymentScheduleObject.new(object: subscription, main: false)) if subscription
|
||||
else
|
||||
ps.payment_schedule_objects.push(PaymentScheduleObject.new(object: subscription, main: true))
|
||||
end
|
||||
ps.payment_method = payment_method
|
||||
if !payment_id.nil? && !payment_type.nil?
|
||||
pgo = PaymentGatewayObject.new(
|
||||
|
@ -12,12 +12,12 @@ class Stripe::Service < Payment::Service
|
||||
stripe_key = Setting.get('stripe_secret_key')
|
||||
first_item = payment_schedule.ordered_items.first
|
||||
|
||||
case payment_schedule.scheduled_type
|
||||
case payment_schedule.main_object.object_type
|
||||
when Reservation.name
|
||||
subscription = payment_schedule.scheduled.subscription
|
||||
reservable_stp_id = payment_schedule.scheduled.reservable&.payment_gateway_object&.gateway_object_id
|
||||
subscription = payment_schedule.payment_schedule_objects.find(&:subscription)
|
||||
reservable_stp_id = payment_schedule.main_object.object.reservable&.payment_gateway_object&.gateway_object_id
|
||||
when Subscription.name
|
||||
subscription = payment_schedule.scheduled
|
||||
subscription = payment_schedule.main_object
|
||||
reservable_stp_id = nil
|
||||
else
|
||||
raise InvalidSubscriptionError
|
||||
|
@ -574,7 +574,7 @@ class Reservations::CreateAsAdminTest < ActionDispatch::IntegrationTest
|
||||
# reservation assertions
|
||||
assert_equal reservation_res[:id], reservation.id
|
||||
assert reservation.payment_schedule
|
||||
assert_equal payment_schedule.scheduled, reservation
|
||||
assert_equal payment_schedule.main_object.object, reservation
|
||||
|
||||
# payment schedule assertions
|
||||
assert_not_nil payment_schedule.reference
|
||||
|
@ -775,7 +775,7 @@ class Reservations::CreateTest < ActionDispatch::IntegrationTest
|
||||
|
||||
# reservation assertions
|
||||
assert reservation.payment_schedule
|
||||
assert_equal payment_schedule.scheduled, reservation
|
||||
assert_equal payment_schedule.main_object.object, reservation
|
||||
|
||||
# Check the answer
|
||||
reservation = json_response(response.body)
|
||||
@ -881,7 +881,7 @@ class Reservations::CreateTest < ActionDispatch::IntegrationTest
|
||||
|
||||
# reservation assertions
|
||||
assert reservation.payment_schedule
|
||||
assert_equal payment_schedule.scheduled, reservation
|
||||
assert_equal payment_schedule.main_object.object, reservation
|
||||
|
||||
# payment schedule assertions
|
||||
assert_not_nil payment_schedule.reference
|
||||
|
Loading…
x
Reference in New Issue
Block a user