diff --git a/app/models/billing_period.rb b/app/models/billing_period.rb index e95d112..0d0bc1d 100644 --- a/app/models/billing_period.rb +++ b/app/models/billing_period.rb @@ -83,10 +83,7 @@ def print_rent_payback def claim_expenses_for_period Expense.update_all(["billing_period_id = ?", id], ["created_at >= ? AND created_at <= ?", start_time, end_time]) TalliedConsumption.update_all(["billing_period_id = ?", id], ["created_at >= ? AND created_at <= ?", start_time, end_time]) - - # temp hack - TalliedConsumption.update_all(["billing_period_id = ?", BillingPeriod.first.id], ["created_at <= ?", Time.parse('April 19, 2011 20:00')]) - + raise "Need to have entered alcohol consumption for the month!" unless tallied_consumptions.count >= User.count * TalliedItem.count puts "#{expenses.count} expenses for current billing period" puts "#{tallied_consumptions.count} tallied_consumptions for current billing period" diff --git a/lib/tasks/payments.rake b/lib/tasks/payments.rake index 37781b5..d8156ec 100644 --- a/lib/tasks/payments.rake +++ b/lib/tasks/payments.rake @@ -4,6 +4,15 @@ namespace :payments do BillingPeriod.compute_new_period end + desc "Undo the last rake payments:compute" + task :rollback => :environment do + bp = BillingPeriod.last + bp.expenses.each {|e| e.update_attribute :billing_period_id, nil} + bp.tallied_consumptions.each {|e| e.update_attribute :billing_period_id, nil} + bp.payments.each {|e| e.destroy} + bp.destroy + end + desc "Send emails for each unpaid payment" task :request => :environment do Payment.unpaid.each { |p| p.request }