Sha256: 4729fa81f5a66bf32fd120ad57f556921da9f51289899782353914e91b4b7e62

Contents?: true

Size: 1.94 KB

Versions: 3

Compression:

Stored size: 1.94 KB

Contents

module Ecom
  module Core
    class Task < ApplicationRecord
      include AASM

      has_ancestry

      belongs_to :work_product
      belongs_to :task_template
      belongs_to :work_package, optional: true
      belongs_to :work_order, optional: true
      belongs_to :plan, optional: true
      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

      has_many :task_steps
      has_many :task_resources
      has_one :takeoff

      validates_with DateRangeValidator
      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) }

      # State: planned -> The task has be planned for execution
      # State: ready_to_start -> All resources for the task has been set and is ready to start
      aasm column: 'status' do
        state :new, initial: true
        state :planned
        state :ready_to_start
        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

3 entries across 3 versions & 1 rubygems

Version Path
ecom_core-1.2.34 app/models/ecom/core/task.rb
ecom_core-1.2.33 app/models/ecom/core/task.rb
ecom_core-1.2.32 app/models/ecom/core/task.rb