Created
April 20, 2012 20:13
-
-
Save bighi/2431514 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
def merge(people) | |
people.each do |id| | |
person = Person.find(id) | |
return false unless person.account.id == self.account.id | |
self.transaction do | |
person.financial_transactions.each do |ft| | |
ft.person = self | |
errors[:base] << "Erro ao salvar financial transaction" unless ft.save! | |
end | |
person.financial_accounts.each do |fa| | |
fa.person = self | |
errors[:base] << "Erro ao salvar financial account" unless fa.save! | |
end | |
person.force_destroy = true | |
error[:base] << "Erro ao remover cliente / fornecedor" unless person.destroy | |
raise ActiveRecord::Rollback unless errors.empty? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment