From 2bb22fb7f47464db4fc6565a40a6a6b43981d9d3 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 2 Nov 2020 19:42:13 +0000 Subject: [PATCH] Add task to reset Orders inside a specific Order Cycle by repeating the placement job --- lib/tasks/subscriptions/subscriptions.rake | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lib/tasks/subscriptions/subscriptions.rake diff --git a/lib/tasks/subscriptions/subscriptions.rake b/lib/tasks/subscriptions/subscriptions.rake new file mode 100644 index 0000000000..6a9fcb06a8 --- /dev/null +++ b/lib/tasks/subscriptions/subscriptions.rake @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +namespace :ofn do + namespace :subs do + desc "Repeat placement job for a specific Order Cycle" + task repeat_placement_job: :environment do + puts "WARNING: this task will generate new, and potentially duplicate, orders for customers" + + puts "Please input Order Cycle ID to reset" + input = STDIN.gets.chomp + exit if input.blank? || !Integer(input) + order_cycle_id = Integer(input) + + # Open Order Cycle by moving open_at to the past + OrderCycle.find_by(id: order_cycle_id).update(orders_open_at: Time.zone.now - 1000) + + # Reset Proxy Orders of the Order Cycle + # by detatching them from existing orders and resetting placed and confirmed dates + ProxyOrder.find_by(order_cycle_id: order_cycle_id).update(order_id: nil, + confirmed_at: nil, + placed_at: nil) + + # Run placement job to create orders + SubscriptionPlacementJob.new.perform + end + end +end