module Ecom module Core class LookaheadPlan < ApplicationRecord include AASM belongs_to :prepared_by, class_name: 'Ecom::Core::User' has_many :lookahead_plan_review_times has_many :lookahead_plan_histories has_and_belongs_to_many :tasks, join_table: 'ecom_core_lookahead_plan_backlogs' validates :name, :start_date, :end_date, :status, :prepared_by_id, :prepared_by, presence: true validates :revision_number, numericality: { greater_than_or_equal_to: 0 } validates :lead_time, presence: true, numericality: { greater_than_or_equal_to: 1 } aasm column: 'status' do state :new, initial: true state :in_progress state :in_review state :completed event :start do transitions from: :new, to: :in_progress, guard: -> { status == 'new' } end event :review do transitions from: :in_progress, to: :in_review, guard: -> { status == 'in_progress' } end event :continue do transitions from: :in_review, to: :in_progress, guard: -> { status == 'in_review' } end event :complete do transitions from: :in_review, to: :completed, guard: -> { status == 'in_review' } end end end end end