Created
May 15, 2009 00:49
-
-
Save shwoodard/112005 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MigrateCoaInventoryAndCogs < ActiveRecord::Migration | |
def self.up | |
Subscriber.all.each do |subscriber| | |
ApplicationGlobals.subscriber = subscriber | |
#Inventory Asset Account | |
inv_asset = Account.find_by_path("Inventory Asset") | |
if inv_asset && inv_asset.children.any? | |
inv_asset.update_attributes!(:name => 'Inventory Asset - Original') | |
inv_asset = nil | |
end | |
acnt_type = AccountType.find_by_name("inventory_asset") | |
if inv_asset | |
inv_asset.active_flag = true | |
inv_asset.protected_account_flag = true | |
inv_asset.account_type = acnt_type | |
inv_asset.save! | |
else | |
inv_asset = Account.new(:name => "Inventory Asset", :account_type => acnt_type, :active_flag => true) | |
inv_asset.protected_account_flag = true | |
inv_asset.save! | |
end | |
#COGS | |
cogs = Account.find_by_path("Cost of Goods Sold") | |
if cogs && cogs.children.any? | |
cogs.update_attributes!(:name => 'Cost of Goods Sold - Original') | |
cogs = nil | |
end | |
acnt_type = AccountType.find_by_name("cost_of_sales") | |
if cogs | |
cogs.active_flag = true | |
cogs.protected_account_flag = true | |
cogs.account_type = acnt_type | |
cogs.save! | |
else | |
cogs = Account.new(:name => "Cost of Goods Sold", :account_type => acnt_type, :active_flag => true) | |
cogs.protected_account_flag = true | |
cogs.save! | |
end | |
end | |
end | |
def self.down | |
Subscriber.all.each do |subscriber| | |
ApplicationGlobals.subscriber = subscriber | |
#Inventory Asset Account | |
inv = Account.find_by_path("Inventory Asset") | |
if inv | |
inv.update_attributes!(:protected_account_flag => false) | |
end | |
#COGS | |
cogs = Account.find_by_path("Cost of Goods Sold") | |
if cogs | |
cogs.account_transactions.each {|at| at.destroy} | |
cogs.destroy | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment