# 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 NEW = 'New'.freeze UNDER_CONSTRUCTION = 'Under Construction'.freeze COMPLETED = 'Completed'.freeze STATUSES = [NEW, UNDER_CONSTRUCTION, COMPLETED].freeze belongs_to :work_product_template belongs_to :project belongs_to :product_group, optional: true belongs_to :work_package, 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 :tasks validates :name, :design_reference_no, :status, :percent_completed, presence: true validates :design_reference_no, uniqueness: { scope: :project_id } validates :status, inclusion: STATUSES validates_numericality_of :percent_completed, only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 100 end end end