Class: Company

Inherits:
ActiveRecord::Base show all
Defined in:
app/models/company.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from ActiveRecord::Base

#has_dependencies?, #merge, relates_to_user_in, #user_model

Class Method Details

+ (Object) conditions_proc(string)



170
171
172
173
174
175
176
# File 'app/models/company.rb', line 170

def self.conditions_proc(string)
  if Rails.version.match(/^3\./)
    eval('proc{"'+string.gsub('"', '\\"')+'"}')
  else
    string
  end
end

+ (Object) models



240
241
242
# File 'app/models/company.rb', line 240

def self.models
  Object.subclasses_of(ActiveRecord::Base).collect{|x| x.name}
end

Instance Method Details

- (Object) account(number, name = nil)



256
257
258
259
260
# File 'app/models/company.rb', line 256

def (number, name=nil)
  number = number.to_s
  a = self.accounts.find_by_number(number)
  return a||self.accounts.create!(:number=>number, :name=>name||number.to_s)
end

- (Object) admin_role



274
275
276
# File 'app/models/company.rb', line 274

def admin_role
  self.roles.find(:first)#, :conditions=>"actions LIKE '%all%'")
end

- (Object) available_entities(options = {})



278
279
280
281
# File 'app/models/company.rb', line 278

def available_entities(options={})
  #    options[:conditions]={:deleted=>false}
  self.entities.find(:all, options)
end


283
284
285
286
287
288
289
290
# File 'app/models/company.rb', line 283

def available_link_natures(options={})
  array = self.entity_link_natures.find_all_by_symmetric(false).collect{|x| [x.name_1_to_2, x.id]}
  array += self.entity_link_natures.find_all_by_symmetric(false).collect{|x| [x.name_2_to_1, x.id.to_s+"-R"]}
  array += self.entity_link_natures.find_all_by_symmetric(true).collect{|x| [x.name_1_to_2, x.id]}
  array.sort!{|a,b| a[0]<=>b[0] }
  #raise Exception.new array.inspect
  array
end

- (Object) available_taxes(options = {})



293
294
295
296
# File 'app/models/company.rb', line 293

def available_taxes(options={})
  #    options[:conditions]={:deleted=>false}
  self.taxes.find(:all, options)
end

- (Object) available_users(options = {})



299
300
301
# File 'app/models/company.rb', line 299

def available_users(options={})
  self.users.find(:all, :order=>:last_name, :conditions=>{:locked=>false})
end

- (Object) backup(options = {})



415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'app/models/company.rb', line 415

def backup(options={})
  creator, with_files = options[:creator], options[:with_prints]
  version = (ActiveRecord::Migrator.current_version rescue 0)
  temporary_dir = Rails.root.join("tmp", "backups")
  FileUtils.mkdir_p(temporary_dir)
  file = temporary_dir.join("backup-#{self.code.lower}-#{Time.now.strftime('%Y%m%d-%H%M%S')}.zip")
  doc = LibXML::XML::Document.new
  doc.root = backup = LibXML::XML::Node.new('backup')
  {'version'=>version, 'creation-date'=>Date.today, 'creator'=>creator}.each{|k,v| backup[k]=v.to_s}
  backup << root = LibXML::XML::Node.new('company')
  self.attributes.each{|k,v| root[k] = v.to_s}
  n = 0
  start = Time.now.to_i
  models = Ekylibre.models.delete_if{|x| x==:company}
  for model in models
    rows = model.to_s.classify.constantize.find(:all, :conditions=>{:company_id=>self.id}, :order=>:id)
    rows_count = rows.size
    n += rows_count
    root << table = LibXML::XML::Node.new('rows')
    {'model'=>model.to_s, 'records-count'=>rows_count.to_s}.each{|k,v| table[k]=v}
    rows_count.times do |i|
      table << row = LibXML::XML::Node.new('row')
      rows[i].attributes.each{|k,v| row[k] = v.to_s}
    end
  end
  # backup.add_attributes('records-count'=>n.to_s, 'generation-duration'=>(Time.now.to_i-start).to_s)
  stream = doc.to_s

  Zip::ZipFile.open(file, Zip::ZipFile::CREATE) do |zile|
    zile.get_output_stream("backup.xml") { |f| f.puts(stream) }
    files_dir = self.private_directory
    if with_files and File.exist?(files_dir)
      Dir.chdir(files_dir) do
        for document in Dir.glob(File.join("**", "*"))
          zile.add("Files/#{document}", File.join(files_dir, document))
        end
      end
    end
  end
  return file
end

- (Object) company_id



248
249
250
# File 'app/models/company.rb', line 248

def company_id
  self.id
end

- (Object) default_contact



390
391
392
# File 'app/models/company.rb', line 390

def default_contact
  self.entity.default_contact
end

- (Object) default_currency

Return the default currency



325
326
327
# File 'app/models/company.rb', line 325

def default_currency
  self.currency # || 'EUR'
end

- (Object) deposits_to_lock



382
383
384
385
386
387
388
# File 'app/models/company.rb', line 382

def deposits_to_lock
  deposits = []
  for deposit in self.deposits
    deposits << deposit if ( deposit.locked == false and deposit.created_on <= Date.today-(15) )
  end
  deposits
end

- (Object) imported_entity_category(row)



342
343
344
345
346
347
348
349
350
# File 'app/models/company.rb', line 342

def imported_entity_category(row)
  if row.blank?
    nature = self.entity_categories.first
  else
    nature = EntityCategory.find(:first, :conditions=>['company_id = ? AND LOWER(name) LIKE ? ',self.id, row.lower])
    nature = EntityCategory.create!(:name=>row, :by_default=>false, :company_id=>self.id) if nature.nil?
  end
  nature.id
end

- (Object) imported_entity_nature(row)



329
330
331
332
333
334
335
336
337
338
339
340
# File 'app/models/company.rb', line 329

def imported_entity_nature(row)
  if row.blank?
    nature = self.entity_natures.find_by_abbreviation("-")
  else
    nature = EntityNature.find(:first, :conditions=>['company_id = ? AND LOWER(name) LIKE ? ',self.id, row.lower])
    #raise Exception.new nature.empty?.inspect
    #raise Exception.new nature.inspect if row == "SCEA"
    nature = EntityNature.find(:first, :conditions=>['company_id = ? AND LOWER(abbreviation) LIKE ?', self.id, row.lower]) if nature.nil?
    nature = EntityNature.create!(:name=>row, :abbreviation=>row[0..1], :in_name=>false, :physical=>true, :company_id=>self.id) if nature.nil?
  end
  nature.id
end

- (Object) journal(name)

Returns the default journal from preferences Creates the journal if not exists

Raises:

  • (ArgumentError)


396
397
398
399
400
401
402
403
404
405
406
# File 'app/models/company.rb', line 396

def journal(name)
  name = name.to_s
  pref_name  = "#{name}_journal"
  raise ArgumentError.new("Unvalid journal name: #{name.inspect}") unless self.class.preferences_reference.has_key? pref_name
  unless journal = self.preferred(pref_name)
    journal = self.journals.find_by_nature(name)
    journal = self.journals.create!(:name=>tc("default.journals.#{name}"), :nature=>name, :currency=>self.default_currency) unless journal
    self.prefer!(pref_name, journal)
  end
  return journal
end

- (Object) journal_entry_lines_calculate(column, started_on, stopped_on, operation = :sum)

def journal_entry_lines_between(started_on, stopped_on)

self.journal_entry_lines.find(:all, :joins=>"JOIN #{JournalEntry.table_name} AS journal_entries ON (journal_entries.id=entry_id)", :conditions=>["printed_on BETWEEN ? AND ? ", started_on, stopped_on], :order=>"printed_on, journal_entries.id, journal_entry_lines.id")

end



970
971
972
973
# File 'app/models/company.rb', line 970

def journal_entry_lines_calculate(column, started_on, stopped_on, operation=:sum)
  column = (column == :balance ? "#{JournalEntryLine.table_name}.original_debit - #{JournalEntryLine.table_name}.original_credit" : "#{JournalEntryLine.table_name}.original_#{column}")
  self.journal_entry_lines.calculate(operation, column, :joins=>"JOIN #{JournalEntry.table_name} AS journal_entries ON (journal_entries.id=entry_id)", :conditions=>["printed_on BETWEEN ? AND ? ", started_on, stopped_on])
end

- (Object) load_demo_data(language_code = nil)



889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
# File 'app/models/company.rb', line 889

def load_demo_data(language_code=nil)
  self.entity_natures.create!(:name=>"Société A Responsabilité Limitée", :title=>"SARL", :in_name=>true)
  last_name = ["MARTIN", "DUPONT", "DURAND", "LABAT", "VILLENEUVE", "SICARD", "FRERET", "FOUCAULT", "DUPEYRON", "BORGÈS", "DUBOIS", "LEROY", "MOREL", "GUERIN", "MORIN", "ROUSSEAU", "LEMAIRE", "DUVAL", "BRUN", "FERNANDEZ", "BRETON", "LEBLANC", "DA SILVA", "CORDIER", "BRIAND", "CAMUS", "VOISIN", "LELIEVRE", "GONZALEZ"]
  first_name = ["Benoît", "Stéphane", "Marine", "Roger", "Céline", "Bertrand", "Camille", "Dominique", "Julie", "Kévin", "Maxime", "Vincent", "Claire", "Marie-France", "Jean-Marie", "Anne-Marie", "Dominique", "Hakim", "Alain", "Daniel", "Sylvie", "Fabrice", "Nathalie", "Véronique", "Jeanine", "Edouard", "Colette", "Sébastien", "Rémi", "Joseph", "Baptiste", "Manuel", "Sofia", "Indira", "Martine", "Guy"]
  streets = ["Cours Xavier Arnozan", "Cours du général de Gaulle", "Route pavée", "Avenue Thiers", "Rue Gambetta", "5th Avenue", "rue Louis La Brocante", "Rue Léon Blum", "Avenue des Champs Élysées", "Cours de la marne"]
  cities = ["33000 Bordeaux", "33170 Gradignan", "40600 Biscarosse", "33400 Talence", "75001 Paris", "13000 Marseille", "33600 Pessac", "47000 Agen", "33710 Pugnac", "33700 Mérignac", "40000 Mont de Marsan"]
  entity_natures = self.entity_natures.collect{|x| x.id.to_s}
  indifferent_attributes = {:category_id=>self.entity_categories.first.id, :language=>self.entity.language}
  products = ["Salades", "Bouteille en verre 75 cl", "Bouchon liège", "Capsule CRD", "Capsule", "Étiquette", "Vin Quillet-Bont 2005", "Caisse Bois 6 btles", "Bouteille Quillet-Bont 2005 75 cl", "Caisse 6 b. Quillet-Bont 2005", "Pommes de terre", "Séjour 1 nuit", "Séjour 1 semaine 1/2 pension", "Fongicide", "Insecticide"]
  product_category_id = self.product_categories.first.id
  category_id = self.entity_categories.first.id

  for x in 0..60
    entity = self.entities.new(indifferent_attributes)
    entity.nature_id = entity_natures[rand(entity_natures.size).to_i]
    entity.last_name = last_name[rand(last_name.size)]
    entity.last_name = entity.nature.title.to_s+" "+entity.last_name if entity.nature.in_name
    entity.first_name = first_name[rand(first_name.size)] if entity.nature.physical
    entity.client = (rand() > 0.5 or rand() > 0.8)
    entity.supplier = (rand() > 0.75 or x == 0)
    entity.transporter = rand() > 0.9
    entity.save!
    contact = entity.contacts.create!(:company_id=>self.id, :line_4=>rand(100).to_s+" "+streets[rand(streets.size)], :line_6=>cities[rand(cities.size)], :by_default=>true)
  end
  self.entity_link_natures.create!(:name=>"Gérant - Société", :name_1_to_2=>"gère la société", :name_2_to_1=>"est une société qui a pour associé", :propagate_contacts=>true, :symmetric=>false)
  self.subscription_natures.create!(:name=>"Abonnement annuel", :nature=>"period", :reduction_rate=>0.1)
  self.event_natures.create!(:name=>"Conversation téléphonique", :duration=>10, :usage=>"manual")

  # charge_account  = self.accounts.find_by_number("60")
   = self.accounts.find_by_number("7")
  units = self.units.find(:all, :conditions=>"base IS NULL OR base in ('', 'kg', 'm3')")
  taxes = self.taxes
  for product_name in products
    product = self.products.create!(:nature=>"product", :name=>product_name, :for_sales=>true, :for_productions=>true, :category_id=>product_category_id, :unit=>units[rand(units.size)], :deliverable=>true, :stockable=>true, :weight=>rand(3), :sales_account_id=>.id)
    product.reload
    product.prices.create!(:amount=>rand(100), :company_id=>self.id, :use_range=>false, :tax_id=>taxes[rand(taxes.size)].id, :category_id=>category_id, :entity_id=>product.name.include?("icide") ? self.entities.find(:first, :conditions=>{:supplier=>true}).id : self.entity_id)
  end

  product = self.products.find_by_name("Caisse 6 b. Quillet-Bont 2005")
  self.product_components.create!(:active=>true, :product_id=>product.id, :component_id=>self.products.find_by_name("Bouteille Quillet-Bont 2005 75 cl").id, :quantity=>6, :warehouse_id=>self.warehouses.first.id)
  self.product_components.create!(:active=>true, :product_id=>product.id, :component_id=>self.products.find_by_name("Caisse Bois 6 btles").id, :quantity=>1, :warehouse_id=>self.warehouses.first.id)

  product = self.products.find_by_name("Bouteille Quillet-Bont 2005 75 cl")
  self.product_components.create!(:active=>true, :product_id=>product.id, :component_id=>self.products.find_by_name("Bouchon liège").id, :quantity=>1, :warehouse_id=>self.warehouses.first.id)
  self.product_components.create!(:active=>true, :product_id=>product.id, :component_id=>self.products.find_by_name("Étiquette").id, :quantity=>1, :warehouse_id=>self.warehouses.first.id)
  self.product_components.create!(:active=>true, :product_id=>product.id, :component_id=>self.products.find_by_name("Bouteille en verre 75 cl").id, :quantity=>1, :warehouse_id=>self.warehouses.first.id)
  self.product_components.create!(:active=>true, :product_id=>product.id, :component_id=>self.products.find_by_name("Vin Quillet-Bont 2005").id, :quantity=>0.75, :warehouse_id=>self.warehouses.first.id)
  self.product_components.create!(:active=>true, :product_id=>product.id, :component_id=>self.products.find_by_name("Capsule CRD").id, :quantity=>1, :warehouse_id=>self.warehouses.first.id)

  self.subscriptions.create!(:nature_id=>self.subscription_natures.first.id, :started_on=>Date.today, :stopped_on=>Date.today+(365), :entity_id=>self.entities.find(:first, :conditions=>{:client=>true}).id, :suspended=>false)

  product = self.products.find_by_name("Vin Quillet-Bont 2005")
  self.warehouses.create!(:name=>"Cuve Jupiter", :product_id=>product.id, :quantity_max=>1000, :number=>1, :reservoir=>true, :establishment_id=>self.establishments.first.id)


  units = self.units.find(:all, :conditions=>{:base =>'m2'})
  group = self.land_parcel_groups.create!(:name=>"General")
  for land_parcel in ["Milou", "Rantanplan", "Idéfix", "Cubitus", "Snoopy"]
    self.land_parcels.create!(:name=>land_parcel, :area_measure=>rand(1000)+10, :area_unit=>units[rand(units.size)], :group_id=>group.id)
  end
  for nature in ["Palissage", "Récolte", "Traitements", "Labour", "Vendange", "Épandange", "Éclaircissage"]
    self.operation_natures.create!(:name=>nature, :target_type=>"LandParcel")
  end
  for nature in ["Fabrication", "Transformation", "Ouillage"]
    self.operation_natures.create!(:name=>nature, :target_type=>"Stock")
  end
  for tool in ["Tracteur MF", "Renault 50"]
    self.tools.create!(:name=>tool, :nature=>"tractor")
  end
  for tool in ["Semoire en ligne", "Pulvérisateur porté", "Herse rotative", "Charrue"]
    self.tools.create!(:name=>tool, :nature=>"towed")
  end
  for tool in ["Embouteilleuse", "Pétrin"]
    self.tools.create!(:name=>tool, :nature=>"other")
  end
end

- (Object) preference(name)



263
264
265
266
267
268
269
270
271
# File 'app/models/company.rb', line 263

def preference(name)
  preference = self.preferences.find_by_name(name)
  if preference.nil? and ref = self.class.preferences_reference[name.to_s]
    preference = self.preferences.new(:name=>name, :nature=>ref[:nature], :record_value_type=>ref[:record_value_type])
    preference.value = ref[:default]
    preference.save!
  end
  preference
end

- (Object) private_directory



410
411
412
# File 'app/models/company.rb', line 410

def private_directory
  File.join(Ekylibre.private_directory, self.code)
end

- (Object) restore(file, options = {})

Restore backup with archived documents if requested This system requires a database with no foreign key constraints Steps of restoring

- Removes all existing data
- Add all backup records with bad IDs
- Update all records with new ID using a big hash containing all the new IDs
- Put in place the archived documents if present in backup

Raises:

  • (ArgumentError)


465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
# File 'app/models/company.rb', line 465

def restore(file, options={})
  raise ArgumentError.new("Expecting String, #{file.class.name} instead") unless file.is_a? String or file.is_a? Pathname
  verbose = options[:verbose]
  files_dir = self.private_directory
  # Décompression
  puts "R> Uncompressing archive..." if verbose
  temporary_dir = Rails.root.join("tmp", "backups")
  FileUtils.mkdir_p(temporary_dir)
  archive = temporary_dir.join("uncompressed-backup-#{self.code}-#{Time.now.strftime('%Y%m%d-%H%M%S')}")
  stream = nil

  # Extract all files in archive
  Zip::ZipFile.open(file) do |zile|
    zile.each do |entry|
      FileUtils.mkdir_p(File.join(archive, entry.name.split(/[\\\/]+/)[0..-2]))
      zile.extract(entry, File.join(archive, entry.name))
    end
  end

  # Parsing
  version = (ActiveRecord::Migrator.current_version rescue 0)
  puts "R> Parsing backup.xml (#{version})..."  if verbose
  doc = LibXML::XML::Document.file(File.join(archive, "backup.xml"))
  backup = doc.root
  attr_version = backup.attributes['version']
  return false if not attr_version or (attr_version != version.to_s)

  root = backup.children[1]
  ActiveRecord::Base.transaction do
    # Suppression des données
    puts "R> Removing existing data..."  if verbose
    ids  = {}
    models = Ekylibre.models # .delete_if{|x| x==:company}
    for model in models
      other_class = model.to_s.classify.constantize
      other_class.delete_all(:company_id=>self.id) if other_class != self.class
    end


    # Chargement des données sauvegardées
    puts "R> Loading backup data..."  if verbose
    data = {}
    keys = {}
    children = root.children
    elements = []
    children.size.times{|i| elements << {:index=>i, :attributes=>children[i].attributes} if children[i].element? }
    code = ''
    timed = false
    for element in elements
      model_name = nil
      if element[:attributes]['reflection']
        model_name = element[:attributes]['reflection'].singularize.to_sym
      elsif Ekylibre.models.include? element[:attributes]['model'].to_sym
        model_name = element[:attributes]['model'].to_sym
      else
        raise Exception.new("Unknown model #{element.inspect}")
      end
      model = model_name.to_s.classify.constantize
      keys[model.name] = Ekylibre.references[model_name].select{|k,v| v != :company}.to_a
      code += "puts('R> - #{model.name} (#{element[:attributes]['records-count']})')\n"  if verbose
      code += "start, tdb1, tdb2p = Time.now, 0, 0\n" if timed
      code += "data['#{model.name}'] = []\n"
      code += "ids['#{model.name}'] = {}\n"
      code += "children[#{element[:index]}].each_element do |r|\n"
      code += "  attributes = r.attributes.to_h\n"
      code += "  id = attributes['id']\n"
      code += "  dstart = Time.now\n" if timed

      code += "  record = #{model.name}.new(:company_id=>#{self.id})\n"
      model.columns_hash.keys.delete_if{|k| k=='id' or k=='company_id'}.each do |attr|
        code += "  record.#{attr} = attributes['#{attr}']\n"
      end

      code += "  tdb1 += Time.now-dstart\n" if timed
      # code += "  record.send(:create_without_callbacks)\n"
      # code += "  record.create_without_callbacks\n"
      # code += "  record.save(:validate=>false, :callbacks=>false)\n"
      code += "  record.send(:create_strictly)\n"
      code += "  tdb2p += Time.now-dstart\n" if timed
      code += "  ids['#{model.name}'][id] = record.id\n"
      # Load initial value of the keys to be renamed easily after.
      code += "  data['#{model.name}'] << [record.id, #{keys[model.name].collect{|key, target| target.is_a?(Symbol) ? 'record.'+key.to_s : '[record.'+target.to_s+', record.'+key.to_s+']'}.join(', ')}]\n"
      code += "end\n"
      if element[:attributes]['records-count'].to_i>30 and timed
        code += "duration, tdb2 = Time.now-start, tdb2p-tdb1\n"
        code += "duration = Time.now-start\n"
        code += "puts 'R>     T: '+duration.to_s[0..6]+' | TDB1: '+tdb1.to_s[0..6]+' | TDB2: '+tdb2.to_s[0..6]+' | RS: '+(duration-tdb2p).to_s[0..6]+' | AVG(TDB1): '+(tdb1/#{element[:attributes]['records-count']}).to_s[0..6]+' | AVG(TDB2): '+(tdb2/#{element[:attributes]['records-count']}).to_s[0..6]\n"  if verbose
      end
    end
    File.open(temporary_dir.join("restore-1.rb"), "wb") {|f| f.write(code)}  if verbose
    # list = code.split("\n"); list.each_index{|x| puts((x+1).to_s.rjust(4)+": "+list[x])}
    eval(code)

    # raise Exception.new(data.inspect)
    # Réorganisation des clés étrangères
    puts "R> Redifining primary keys..."  if verbose
    code  = ''

    for model_name in Ekylibre.models
      model = model_name.to_s.classify.constantize

      new_ids = "'"
      for i in 1..keys[model.name].size
        reference = keys[model.name][i-1]
        target = reference[1]
        new_ids += (i>1 ? "+', " : "")+"#{reference[0]}='+"
        if target.is_a? String # Polymorphic
          new_ids += "((ids[record[#{i}][0]] ? (ids[record[#{i}][0]][record[#{i}][1].to_s]) : nil)||record[#{i}][1]||'NULL').to_s"
        else # Classic reference
          new_ids += "((ids['#{target.to_s.classify}'][record[#{i}].to_s])||record[#{i}]||'NULL').to_s"
        end
      end
      code += "for record in data['#{model.name}']\n"
      code += "  #{model.name}.update_all(#{new_ids}, 'company_id=#{self.id} AND id='+record[0].to_s)\n"
      code += "end\n"
    end

    File.open(temporary_dir.join("restore-2.rb"), "wb") {|f| f.write(code)} if verbose
    start = Time.now
    eval(code)
    puts "R> Total: #{(Time.now-start)}s" if verbose



    # Chargement des paramètres de la société
    puts "R> Loading company data..." if verbose
    attrs = root.attributes.each do |attr|
      self.send(attr.name+'=', attr.value) unless ['id', 'lock_version', 'code'].include? attr.name
    end
    for key, target in Ekylibre.references[self.class.name.underscore.to_sym]
      v = ids[target.to_s.classify][self[key].to_s]
      self[key] = v unless v.nil?
    end
    # self.send(:update_without_callbacks)
    self.send(:update_strictly)
    self.reload
    # raise Active::Record::Rollback

    backup_files = File.join(archive, "Files")
    if File.exist?(backup_files)
      puts "R> Replacing files..." if verbose
      FileUtils.mv files_dir, files_dir+'.old'
      FileUtils.mv backup_files, files_dir
      FileUtils.rm_rf(files_dir+'.old')
    end
  end

  # Clean temporary directory by removing backup data
  FileUtils.rm_rf(archive)
  return true
end

- (Object) siren



244
245
246
# File 'app/models/company.rb', line 244

def siren
  self.entity ? self.entity.siren : '000000000'
end

- (Object) to_param



252
253
254
# File 'app/models/company.rb', line 252

def to_param
  self.code
end