Sha256: 9ba7950eee026e23a22be6f1617ebaf13f737af10e385d739e9fe228ce3982dd

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

module Ecom
  module Core
    class Task < ApplicationRecord
      include AASM

      has_ancestry

      belongs_to :work_product
      belongs_to :task_template
      belongs_to :performer, class_name: 'Ecom::Core::User', optional: true
      belongs_to :approver, class_name: 'Ecom::Core::User', optional: true
      belongs_to :supervisor, class_name: 'Ecom::Core::User', optional: true
      belongs_to :quality_controller, class_name: 'Ecom::Core::User', optional: true

      validates :code, :name, :status, :percent_completed, presence: true
      validates_numericality_of :percent_completed,
                                only_integer: true,
                                greater_than_or_equal_to: 0,
                                less_than_or_equal_to: 100

      scope :by_status, ->(status) { where(status: status) }

      aasm column: 'status' do
        state :new, initial: true
        state :in_progress
        state :submitted
        state :under_review
        state :completed

        event :start do
          transitions from: :new, to: :in_progress
        end

        event :submit do
          transitions from: :in_progress, to: :submitted
        end

        event :review do
          transitions from: :submitted, to: :under_review
        end

        event :complete do
          transitions from: %i[submitted under_review], to: :completed
        end

        event :rework do
          transitions from: :under_review, to: :in_progress
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ecom_core-1.2.25 app/models/ecom/core/task.rb