diff --git a/app/models/legacy/invoice.rb b/app/models/legacy/invoice.rb new file mode 100644 index 000000000..15441d89e --- /dev/null +++ b/app/models/legacy/invoice.rb @@ -0,0 +1,5 @@ +module Legacy + class Invoice < Db + self.table_name = :invoice + end +end diff --git a/app/models/legacy/registrar.rb b/app/models/legacy/registrar.rb index 0dc124085..80a09a945 100644 --- a/app/models/legacy/registrar.rb +++ b/app/models/legacy/registrar.rb @@ -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 diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index c966438b4..8436080be 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -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"