Sha256: 9490da8703707fa696d8abbe4e0df597f9c74d52671acd1115c3398056a555d6

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

class Agreement < ActiveRecord::Base
  attr_protected :created_at, :updated_at

  belongs_to :agreement_type
	has_many 	 :agreement_items
	has_many 	 :agreement_party_roles
	has_many	 :parties, :through => :agreement_party_roles
  belongs_to :agreement_record, :polymorphic => true
  
  alias :items :agreement_items
  
  def agreement_relationships
    AgreementRelationship.where('agreement_id_from = ? OR agreement_id_to = ?',id,id)
  end
  
  def to_s
    description
  end
 
  def to_label
    to_s
  end

  def find_parties_by_role(role)
    self.parties.where("role_type_id = ?", role.id).all
  end

  def get_item_by_item_type_internal_identifier(item_type_internal_identifier)
    agreement_items.joins("join agreement_item_types on 
                           agreement_item_types.id = 
                           agreement_items.agreement_item_type_id").where("agreement_item_types.internal_identifier = '#{item_type_internal_identifier}'").first
  end
  
  def respond_to?(m, include_private_methods = false)
    ((get_item_by_item_type_internal_identifier(m.to_s).nil? ? false : true)) unless super
  end
  
  def method_missing(m, *args, &block)
    agreement_item = get_item_by_item_type_internal_identifier(m.to_s)
    (agreement_item.nil?) ? super : (return agreement_item.agreement_item_value)
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
erp_agreements-4.2.0 app/models/agreement.rb
erp_agreements-4.0.0 app/models/agreement.rb
erp_agreements-3.1.0 app/models/agreement.rb