Skip to content

Commit

Permalink
Creating payments rollback function
Browse files Browse the repository at this point in the history
  • Loading branch information
rmatei committed May 17, 2011
1 parent 3ab7729 commit fcca4f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 1 addition & 4 deletions app/models/billing_period.rb
Expand Up @@ -83,10 +83,7 @@ def print_rent_payback
def claim_expenses_for_period def claim_expenses_for_period
Expense.update_all(["billing_period_id = ?", id], ["created_at >= ? AND created_at <= ?", start_time, end_time]) 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]) 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 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 "#{expenses.count} expenses for current billing period"
puts "#{tallied_consumptions.count} tallied_consumptions for current billing period" puts "#{tallied_consumptions.count} tallied_consumptions for current billing period"
Expand Down
9 changes: 9 additions & 0 deletions lib/tasks/payments.rake
Expand Up @@ -4,6 +4,15 @@ namespace :payments do
BillingPeriod.compute_new_period BillingPeriod.compute_new_period
end 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" desc "Send emails for each unpaid payment"
task :request => :environment do task :request => :environment do
Payment.unpaid.each { |p| p.request } Payment.unpaid.each { |p| p.request }
Expand Down

0 comments on commit fcca4f3

Please sign in to comment.