Merge pull request #110 from internetee/115040781-legaldoc_on_delete

115040781 legaldoc on delete
This commit is contained in:
Timo Võhmar 2016-03-30 16:39:55 +03:00
commit 798b5739e0
3 changed files with 17 additions and 2 deletions

View file

@ -330,11 +330,25 @@ class Contact < ActiveRecord::Base
# TODO: refactor, it should not allow to destroy with normal destroy,
# no need separate method
# should use only in transaction
def destroy_and_clean
def destroy_and_clean frame
if domains_present?
errors.add(:domains, :exist)
return false
end
legal_document_data = Epp::Domain.parse_legal_document_from_frame(frame)
if legal_document_data
doc = LegalDocument.create(
documentable_type: Contact,
document_type: legal_document_data[:type],
body: legal_document_data[:body]
)
self.legal_documents = [doc]
self.legal_document_id = doc.id
self.save
end
destroy
end