Import account balance #2267

This commit is contained in:
Martin Lensment 2015-06-17 13:37:41 +03:00
parent 392ecba4b2
commit e6387a2847
3 changed files with 20 additions and 0 deletions

View file

@ -0,0 +1,5 @@
module Legacy
class Invoice < Db
self.table_name = :invoice
end
end

View file

@ -1,5 +1,11 @@
module Legacy
class Registrar < Db
self.table_name = :registrar
has_many :invoices, foreign_key: :registrarid
def account_balance
invoices.sum(:credit)
end
end
end

View file

@ -106,6 +106,15 @@ namespace :import do
next if x.cash_account
x.accounts.create(account_type: Account::CASH, currency: 'EUR')
x.save(validate: false)
lr = Legacy::Registrar.find(x.legacy_id)
x.cash_account.account_activities << AccountActivity.new({
sum: lr.account_balance,
currency: 'EUR',
description: 'Transfer from legacy system'
})
x.cash_account.save
end
puts "-----> Imported #{count} new registrars in #{(Time.zone.now.to_f - start).round(2)} seconds"