Sync OC subscriptions if transitioning from closed to open

This commit is contained in:
Matt-Yorkley
2022-02-16 13:03:27 +00:00
parent 4260422ea7
commit 4592827261

View File

@@ -29,6 +29,7 @@ class OrderCycle < ApplicationRecord
attr_accessor :incoming_exchanges, :outgoing_exchanges
before_update :reset_processed_at, if: :will_save_change_to_orders_close_at?
after_save :sync_subscriptions, if: :opening?
validates :name, :coordinator_id, presence: true
validate :orders_close_at_after_orders_open_at?
@@ -274,6 +275,14 @@ class OrderCycle < ApplicationRecord
private
def opening?
open? && orders_close_at_changed? && was_closed?
end
def was_closed?
orders_close_at_was && Time.zone.now > orders_close_at_was
end
def sync_subscriptions
return unless open? && schedule_ids.any?