Permalink
Browse files

Creating payments rollback function

  • Loading branch information...
1 parent 3ab7729 commit fcca4f354337ff06afa871c8ad7f2cb1219f6e2a @rmatei committed May 17, 2011
Showing with 10 additions and 4 deletions.
  1. +1 −4 app/models/billing_period.rb
  2. +9 −0 lib/tasks/payments.rake
@@ -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"
View
@@ -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 }

0 comments on commit fcca4f3

Please sign in to comment.