mirror of
https://github.com/internetee/registry.git
synced 2025-05-28 12:31:21 +02:00
Import account balance #2267
This commit is contained in:
parent
392ecba4b2
commit
e6387a2847
3 changed files with 20 additions and 0 deletions
5
app/models/legacy/invoice.rb
Normal file
5
app/models/legacy/invoice.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
module Legacy
|
||||
class Invoice < Db
|
||||
self.table_name = :invoice
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue