mirror of
https://github.com/internetee/registry.git
synced 2025-05-30 09:30:03 +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
|
module Legacy
|
||||||
class Registrar < Db
|
class Registrar < Db
|
||||||
self.table_name = :registrar
|
self.table_name = :registrar
|
||||||
|
|
||||||
|
has_many :invoices, foreign_key: :registrarid
|
||||||
|
|
||||||
|
def account_balance
|
||||||
|
invoices.sum(:credit)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -106,6 +106,15 @@ namespace :import do
|
||||||
next if x.cash_account
|
next if x.cash_account
|
||||||
x.accounts.create(account_type: Account::CASH, currency: 'EUR')
|
x.accounts.create(account_type: Account::CASH, currency: 'EUR')
|
||||||
x.save(validate: false)
|
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
|
end
|
||||||
|
|
||||||
puts "-----> Imported #{count} new registrars in #{(Time.zone.now.to_f - start).round(2)} seconds"
|
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