Skip to content

Commit

Permalink
Updated buxfer update code to reflect the name changes I made yesterday
Browse files Browse the repository at this point in the history
  • Loading branch information
konklone committed Mar 25, 2010
1 parent f63ffcd commit b260491
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions updater/buxfer.yml.example
Expand Up @@ -17,6 +17,6 @@
# Remember to put the negative sign on a debt
:manual:
- :local_id:
:balance:
:amount:
- :local_id:
:balance:
:amount:
26 changes: 13 additions & 13 deletions updater/updater.rb
Expand Up @@ -24,21 +24,21 @@ def update_accounts!
map = maps.find {|m| m[:remote_id] == remote['id']}
if map
account = user.accounts.find map[:local_id]
balance = (remote['balance'] * 100).to_i # convert to pennies
balance *= -1 if account.debts?
amount = (remote['balance'] * 100).to_i # convert to pennies
amount *= -1 if account.debts?

worth += balance
update_account! account, balance
worth += amount
update_account! account, amount
end
end

# the manual accounts that Buxfer doesn't support
manual.each do |map|
account = user.accounts.find map[:local_id]
balance = map[:balance]
amount = map[:amount]

worth += balance
update_account! account, map[:balance]
worth += amount
update_account! account, amount
end

# the net worth of it all
Expand All @@ -47,11 +47,11 @@ def update_accounts!
end

# idempotent - will overwrite balance if one exists for today
def update_account!(account, balance)
day = account.days.find_or_initialize_by_date_of Time.now.to_date
day.user_id = user.id
day.balance = balance
day.save!
puts "Updated #{account.name} with balance of #{balance}, for #{day.date_of}."
def update_account!(account, amount)
balance = account.balances.find_or_initialize_by_date_of Time.now.to_date
balance.user_id = user.id
balance.amount = amount
balance.save!
puts "Updated #{account.name} with balance of #{amount}, for #{balance.date_of}."
end
end

0 comments on commit b260491

Please sign in to comment.