Class: BusinessUnit

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/business_unit.rb

Overview

== Schema Information

Table name: business_units
Database name: primary

id :integer not null, primary key
name :string(255)
number :integer
created_at :datetime
updated_at :datetime
company_id :integer

Indexes

business_units_company_id_idx (company_id)
idx_business_unit_number (number)

Foreign Keys

business_units_company_id_fkey (company_id => companies.id)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#company_idObject (readonly)



30
# File 'app/models/business_unit.rb', line 30

validates :number, :name, :company_id, presence: true

#nameObject (readonly)



30
# File 'app/models/business_unit.rb', line 30

validates :number, :name, :company_id, presence: true

#numberObject (readonly)



30
# File 'app/models/business_unit.rb', line 30

validates :number, :name, :company_id, presence: true

Class Method Details

.by_numberActiveRecord::Relation<BusinessUnit>

A relation of BusinessUnits that are by number. Active Record Scope

Returns:

See Also:



33
# File 'app/models/business_unit.rb', line 33

scope :by_number, -> { order(:number) }

.for_companyActiveRecord::Relation<BusinessUnit>

A relation of BusinessUnits that are for company. Active Record Scope

Returns:

See Also:



34
# File 'app/models/business_unit.rb', line 34

scope :for_company, ->(company_id) { where(company_id: company_id) }

.select_optionsObject



40
41
42
# File 'app/models/business_unit.rb', line 40

def self.select_options
  all.order('number asc').map { |bu| [bu.number_and_name, bu.id] }
end

Instance Method Details

#budgetsActiveRecord::Relation<Budget>

Returns:

  • (ActiveRecord::Relation<Budget>)

See Also:



27
# File 'app/models/business_unit.rb', line 27

has_many :budgets

#companyCompany

Returns:

See Also:



25
# File 'app/models/business_unit.rb', line 25

belongs_to :company, optional: true

#invoicesActiveRecord::Relation<Invoice>

Returns:

  • (ActiveRecord::Relation<Invoice>)

See Also:



28
# File 'app/models/business_unit.rb', line 28

has_many :invoices

#number_and_nameObject



36
37
38
# File 'app/models/business_unit.rb', line 36

def number_and_name
  "#{number} #{name}"
end

#suppliersActiveRecord::Relation<Supplier>

Returns:

See Also:



26
# File 'app/models/business_unit.rb', line 26

has_many :suppliers