Created
May 31, 2013 23:13
-
-
Save guipdutra/5688565 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Entity < Accounting::Model | |
include CustomData | |
reload_custom_data | |
attr_accessible :cnpj, :phone, :image, :email, :fax, | |
:budget_structure_id, :employee_ids, :tce_organ_type | |
attr_accessor :employee | |
mount_uploader :image, ImageUploader | |
attr_modal :description | |
has_enumeration_for :tce_organ_type, :create_helpers => true | |
belongs_to :budget_structure | |
has_many :capabilities, :dependent => :restrict | |
has_many :descriptors, :dependent => :restrict | |
has_many :government_actions, :dependent => :restrict | |
has_many :government_programs, :dependent => :restrict | |
has_many :signature_configurations, :dependent => :restrict | |
has_many :signatures, :dependent => :restrict | |
has_many :subfunctions, :dependent => :restrict | |
has_and_belongs_to_many :employees, :join_table => "accounting_employees_entities" | |
validates :budget_structure_id, :uniqueness => { :allow_blank => true } | |
validates :cnpj, :budget_structure, :presence => true | |
validates :email, :mail => true, :allow_blank => true | |
validates :phone, :fax, :mask => '(99) 9999-9999', :allow_blank => true | |
validates :cnpj, :mask => '99.999.999/9999-99', :cnpj => true, :allow_blank => true | |
validate :validate_custom_data | |
delegate :structure_sequence, :child_structure_sequence, :to => :budget_structure, :allow_nil => true | |
delegate :address_neighborhood_name, :address_street, :state_acronym, :to => :budget_structure, :allow_nil => true | |
delegate :address_number, :to => :budget_structure, :allow_nil => true | |
delegate :address_zip_code, :to => :budget_structure, :allow_nil => true | |
delegate :description, :to => :budget_structure, :allow_nil => true | |
orderize :budget_structure_id | |
def self.filter(options) | |
records = scoped | |
records = records.joins { budget_structure } | |
records = records.where { budget_structure.description.eq(options[:description]) } if options.name[:description].present? | |
records | |
end | |
def to_s | |
description | |
end | |
def rpps? | |
rpps_foresight_own_regime? || rpps_health_assistance? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment