class Obra::FonteDeRecursoDoPreConvenio < ApplicationRecord
	has_paper_trail

	belongs_to :fonte_de_recurso, class_name: 'Base::FonteDeRecursos', foreign_key: :fonte_de_recurso_id
	belongs_to :pre_convenio, class_name: 'Obra::PreConvenio'

	validates :fonte_de_recurso_id, :pre_convenio_id, :valor, presence: true

	after_save :apaga_a_si_mesmo_se_valor_igual_a_zero

	def apaga_a_si_mesmo_se_valor_igual_a_zero
		self.delete unless self.valor.to_f > 0
	end

end
