mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Sync OC subscriptions if transitioning from closed to open
This commit is contained in:
@@ -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?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user