Class: ElementPoleAssignment

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable, OrderQuery
Defined in:
app/models/element_pole_assignment.rb

Overview

== Schema Information

Table name: element_pole_assignments
Database name: primary

id :bigint not null, primary key
heating_element_number :integer not null
notes :string
pole_number :integer not null
relay_number :integer not null
created_at :datetime not null
updated_at :datetime not null
creator_id :integer
heating_element_item_id :integer not null
relay_item_id :integer not null
room_configuration_id :integer not null
updater_id :integer

Indexes

idx_unique_element_pole_assignment (relay_item_id,heating_element_item_id,relay_number,pole_number,heating_element_number) UNIQUE
index_element_pole_assignments_on_heating_element_item_id (heating_element_item_id)

Foreign Keys

fk_rails_... (heating_element_item_id => items.id)
fk_rails_... (relay_item_id => items.id)
fk_rails_... (room_configuration_id => room_configurations.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

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

#heating_element_comboObject

Returns the value of attribute heating_element_combo.



34
35
36
# File 'app/models/element_pole_assignment.rb', line 34

def heating_element_combo
  @heating_element_combo
end

#heating_element_item_idObject (readonly)



41
# File 'app/models/element_pole_assignment.rb', line 41

validates :heating_element_item_id, uniqueness: { scope: %i[room_configuration_id relay_item_id relay_number pole_number heating_element_number], message: "cannot be assigned to the same pole multiple times" }

#heating_element_numberObject (readonly)



40
# File 'app/models/element_pole_assignment.rb', line 40

validates :relay_number, :pole_number, :heating_element_number, presence: true, numericality: { only_integer: true, greater_than: 0 }

#pole_numberObject (readonly)



40
# File 'app/models/element_pole_assignment.rb', line 40

validates :relay_number, :pole_number, :heating_element_number, presence: true, numericality: { only_integer: true, greater_than: 0 }

#relay_numberObject (readonly)



40
# File 'app/models/element_pole_assignment.rb', line 40

validates :relay_number, :pole_number, :heating_element_number, presence: true, numericality: { only_integer: true, greater_than: 0 }

#relay_pole_comboObject

Returns the value of attribute relay_pole_combo.



34
35
36
# File 'app/models/element_pole_assignment.rb', line 34

def relay_pole_combo
  @relay_pole_combo
end

Class Method Details

.orderedActiveRecord::Relation<ElementPoleAssignment>

A relation of ElementPoleAssignments that are ordered. Active Record Scope

Returns:

See Also:



51
# File 'app/models/element_pole_assignment.rb', line 51

scope :ordered, -> { order_default }

Instance Method Details

#heating_element_combo_selectObject



98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/models/element_pole_assignment.rb', line 98

def heating_element_combo_select
  # Create an incremental label counter
  options = []
  index = 0
  heating_elements_grouped.each do |item, line_items|
    (1..line_items.sum(&:quantity)).each do |counter|
      index += 1
      options << ["#{item.sku} # #{index}", "#{item.id}|#{index}"]
    end
  end
  options
end

#heating_element_itemItem

Returns:

See Also:



38
# File 'app/models/element_pole_assignment.rb', line 38

belongs_to :heating_element_item, class_name: 'Item'

#heating_elements_groupedObject



111
112
113
# File 'app/models/element_pole_assignment.rb', line 111

def heating_elements_grouped
  room_configuration.line_items.heating_elements.sort_for_plan.joins(:item).group_by(&:item)
end

#nextObject



71
72
73
# File 'app/models/element_pole_assignment.rb', line 71

def next
  room_configuration.element_pole_assignments.order_default_at(self).next
end

#previousObject

partial: "/crm/room_configurations/element_pole_assignments/element_pole_assignment",
inserts_by: :append



67
68
69
# File 'app/models/element_pole_assignment.rb', line 67

def previous
  room_configuration.element_pole_assignments.order_default_at(self).previous
end

#relay_combo_selectObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/models/element_pole_assignment.rb', line 119

def relay_combo_select
  options = []
  relay_grouped.each do |item, line_items|
    index = 0
    (1..line_items.sum(&:quantity)).each do |counter|
      index += 1
      (1..item.num_poles).to_a.each do |pole_number|
        label = "#{item.sku} # #{index} - Pole #{pole_number}"
        if (assignments = room_configuration.element_pole_assignments.select{|epa| epa.relay_item_id == item.id && epa.relay_number == index && epa.pole_number == pole_number}).present?
          label << " [Assigned to Element #{assignments.map(&:heating_element_number).join(',')}]"
        end
        value = "#{item.id}|#{index}|#{pole_number}"
        options << [label, value]
      end
    end
  end
  options
end

#relay_groupedObject



115
116
117
# File 'app/models/element_pole_assignment.rb', line 115

def relay_grouped
  room_configuration.line_items.relay_panels.joins(:item).order(Item[:sku]).group_by(&:item)
end

#relay_identifierObject



92
93
94
95
96
# File 'app/models/element_pole_assignment.rb', line 92

def relay_identifier
  return unless relay_item_id && relay_number && pole_number
  #"#{relay_item.sku} ##{relay_number}"
  "#{relay_item.num_poles} PL ##{relay_number}"
end

#relay_itemItem

Returns:

See Also:



37
# File 'app/models/element_pole_assignment.rb', line 37

belongs_to :relay_item, class_name: 'Item'

#room_configurationRoomConfiguration

Returns:

  • (RoomConfiguration)

See Also:



36
# File 'app/models/element_pole_assignment.rb', line 36

belongs_to :room_configuration