Sha256: 1e9b55ddaa4f88b82d062c5e9acd88adf292c5d312cf457a8be98a9608be86a7

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

class Commission < ApplicationRecord
  has_many :bundles, inverse_of: :commission, dependent: :destroy
  has_many :chosen_decks, inverse_of: :commission, dependent: :destroy
  has_many :decks, through: :chosen_decks, inverse_of: :commissions
  #accepts_nested_attributes_for :chosen_decks, allow_destroy: true

  # validates :name, uniqueness: { case_sensitive: false }, presence: true
  validates :code, uniqueness: { case_sensitive: false }, presence: true #, length: { is: 5 }
  # validates :issued_on, uniqueness: { case_sensitive: false }, presence: true

  before_save do
    self.name = code
  end

  def self.is_opened
    where closed: false
  end

  def self.is_closed
    where closed: true
  end
  # Items: I need a method to obtain all the items in the
  # current selected Commission
  def records_for_print id
    # TODO: move away from this pseudo code as soon as Bancolini tells me
    # what Mobilart wants
    # chosen_item.name
    # chosen_item.barcode
    # chosen_item.timetables.last.status
    # chosen_item.timetables.last.job_type
    ChosenItem.joins(chosen_furniture: {chosen_room: {chosen_deck: :commission}}).where(commissions: {id: id}).distinct
  end

  def list_associated_items
    true
  end

  rails_admin do
    navigation_label I18n.t(:operative_section)
    navigation_icon 'fa fa-anchor'
    weight 4

    field :code
    field :description
    field :closed, :toggle
    field :decks
    list do
      scopes [:is_opened, :is_closed, nil]
      field :updated_at
    end
  end

  amoeba do
    enable
    include_association :chosen_decks
    prepend :code => "Copia di "
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mobilart_models-1.2.14 app/models/commission.rb