Skip to main content
Skip table of contents

RAILS - Clear Fixed Assets Setup and Transaction Data

Description

RAILS command to clear Fixed Assets data

Usage

Either during implementation for a fresh start at the setup or when significant issues have been found with the existing setup.

SQL

CODE
### Custom Delete Methods
# Batch Group and Batch Processes
def batch_group_delete
  bgs = BatchGroup.where(control_type: "FixedAssets");nil
  count = bgs.count
  unless @dry_run
    bgs.each { |bg| bg.delete! }
  end
  "BatchGroup - Destroyed #{count} records and related BatchProcess records"
end

# FinancialIntegration
def financial_integration_delete
  fis = FinancialIntegration.where(source: "Fixed Assets");nil
  count = fis.count
  fis.destroy_all unless @dry_run
  "FinancialIntegration - Destroyed #{count} records"
end

# JournalEntry and GlDistribution and GLTransaction
def journal_entry_delete
  jes = JournalEntry.where(source: "Fixed Assets");nil
  je_ids = jes.pluck(:id)
  count = je_ids.count
  jes.each { |je| je.full_delete } unless @dry_run
  glts = GlTransaction.where(object_type: "JournalEntry", object_id: je_ids);nil
  glts.destroy_all unless @dry_run
  "JournalEntry - Destroyed #{count} records and related GLD/GLT records"
end

def run dry_run=true
  @dry_run = dry_run
  all_output = []
  delete_all_klasses = [FixedAssetAuditLog, FixedAssetBookSchedule, FixedAssetCategorySetup, FixedAssetFixedAssetStagingResult, FixedAssetPool, FixedAssetStagingResult, FixedAssetTaxDetailSchedule, FixedAsset, CostAdjustment, Retirement, Impairment, PoolDepletionRateResult, Reserve, LeveledReserve, TaxProductionAndReserve, LeveledReserve, BookTaxDifference, TaxDepletionResult, FixedAssetFinancialResult, FixedAssetProcessFlag, FixedAssetProcessLock, FixedAssetStagingSetup, FixedAssetSource, FixedAssetTaxPeriod, TaxDepletionRate, FixedAssetTransactionSummary, UnitsOfProductionResult, SchedulesWatcher];nil
  code_table_delete = [FixedAssetCategory, FixedAssetGroup, PoolCode];nil
  custom_deletes = [:batch_group_delete, :financial_integration_delete, :journal_entry_delete];nil

  all_output << "Dry run, not really doing any deletion" if @dry_run
  delete_all_klasses.each do |klass|
    count = klass.count
    klass.destroy_all unless @dry_run
    all_output << "#{klass.to_s} - Destroyed #{count} records"
  end;nil

  code_table_delete.each do |klass|
    count = klass.count
    klass.destroy_all unless @dry_run
    all_output << "#{klass.to_s} - Destroyed #{count} records"
  end;nil

  custom_deletes.each do |custom_delete_method|
    msg = send(custom_delete_method)
    all_output << msg
  end;nil

  puts all_output
end

run(true)
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.