From 448bd12e9fdabe486c27b5690b8f18885b22f097 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 9 Jul 2015 09:54:40 +0800 Subject: [PATCH] Adding billing tasks to whenever schedule --- .../accounts_and_billing_settings/edit.html.haml | 4 ++-- config/schedule.rb | 9 +++++++++ lib/tasks/billing.rake | 13 +++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 lib/tasks/billing.rake diff --git a/app/views/admin/accounts_and_billing_settings/edit.html.haml b/app/views/admin/accounts_and_billing_settings/edit.html.haml index 3fbcf0ae22..040415cbb7 100644 --- a/app/views/admin/accounts_and_billing_settings/edit.html.haml +++ b/app/views/admin/accounts_and_billing_settings/edit.html.haml @@ -25,13 +25,13 @@ %fieldset.no-border-bottom %legend Update Invoices = f.check_box :auto_update_invoices - = f.label :auto_update_invoices, "Auto-update invoices nightly at 2am" + = f.label :auto_update_invoices, "Auto-update invoices nightly at 1:00am" .six.columns.omega %fieldset.no-border-bottom %legend Finalise Invoices = f.check_box :auto_finalize_invoices - = f.label :auto_finalize_invoices, "Auto-finalise invoices monthly on the 2nd" + = f.label :auto_finalize_invoices, "Auto-finalise invoices monthly on the 2nd at 1:30am" .row .twelve.columns.alpha.omega.form-buttons{"data-hook" => "buttons"} diff --git a/config/schedule.rb b/config/schedule.rb index 0c98f72dc6..d5417cec81 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -18,3 +18,12 @@ end every 4.hours do rake 'db2fog:backup' end + +every 1.day, at: '1:00am' do + rake 'openfoodnetwork:billing:update_user_invoices' +end + +# On the 2nd of every month at 1:30am +every '30 1 2 * *' do + rake 'openfoodnetwork:billing:finalize_user_invoices' +end diff --git a/lib/tasks/billing.rake b/lib/tasks/billing.rake new file mode 100644 index 0000000000..13930f1f58 --- /dev/null +++ b/lib/tasks/billing.rake @@ -0,0 +1,13 @@ +namespace :openfoodnetwork do + namespace :billing do + desc 'Update enterprise user invoices' + task update_user_invoices: :environment do + Delayed::Job.enqueue(UpdateUserInvoices.new) if Spree::Config[:auto_update_invoices] + end + + desc 'Finalize enterprise user invoices' + task finalize_user_invoices: :environment do + Delayed::Job.enqueue(FinalizeUserInvoices.new) if Spree::Config[:auto_finalize_invoices] + end + end +end