Class: Legrain::Epicea::AccountsExchanger

Inherits:
ActiveExchanger::Base show all
Defined in:
app/exchangers/legrain/epicea/accounts_exchanger.rb

Instance Attribute Summary

Attributes inherited from ActiveExchanger::Base

#file, #supervisor

Instance Method Summary collapse

Methods inherited from ActiveExchanger::Base

build, check, check_by_default, exchanger_name, export, exporters, find, human_name, import, import!, importers, importers_selection, inherited, #initialize, register_exchanger

Constructor Details

This class inherits a constructor from ActiveExchanger::Base

Instance Method Details

#importObject


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/exchangers/legrain/epicea/accounts_exchanger.rb', line 2

def import
  rows = CSV.read(file, headers: true, encoding: 'cp1252', col_sep: ';', quote_char: "'")
  w.count = rows.count

  # asociate usage to its account number
   = {}
  Nomen::Account.all.each do |usage|
    [Nomen::Account[usage].fr_pcga] = usage
  end

  rows.each do |row|
     = row[0].to_s
    label = row[1].to_s.tr('"', "'")
    usage = []
    if usage.present?
       = Account.find_or_import_from_nomenclature(usage)
    else
       = .chop
      while .present?
        usage = []
        break if usage.present?
        .chop!
      end
       = Account.create(number: , name: label, usages: usage)
      .save
    end
    w.check_point
  end
end