# The WorkProduct core represents a task being implemented on a specific # work product. To this regard, a work product is an assignable itself which # contains the basic product attributes (e.g. dimension, name, design reference) # on one hand, and task related attributes (e.g. start date and completion date) # on the other hand. A task may have multiple work products under it. It is # important to note that currently there is no direct way to link products and # sub products, as we have done with tasks and sub tasks. If there is a desire # to have such a link between products (e.g. we may later want to have reports # per specific high level products, which in turn asks for finding all sub products # under the selected high level product and do calculations), then a `code` field # has been introduced to the WorkProduct core. This field can be used in a similar # way as chart of accounts to identify parent and child relationships. Even then, # there needs to be a well defined coding scheme developed before using the column # field. # module Ecom module Core class WorkProduct < ApplicationRecord include AASM belongs_to :work_product_template belongs_to :task belongs_to :project belongs_to :performer, class_name: 'Ecom::Core::User' belongs_to :approver, class_name: 'Ecom::Core::User' belongs_to :supervisor, class_name: 'Ecom::Core::User' belongs_to :quality_controller, class_name: 'Ecom::Core::User' validates :name, presence: true validates :design_reference_no, uniqueness: true aasm column: 'task_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 aasm column: 'assignment_status' do state :unassigned, initial: true state :assigned event :assign do transitions from: :unassigned, to: :assigned end end end end end