module Logistics module Core class Operation < ApplicationRecord belongs_to :offer_request belongs_to :declarant, optional: true belongs_to :declaration_type, optional: true belongs_to :transport_mode, optional: true belongs_to :customs_office, optional: true belongs_to :customs_office_unit, optional: true belongs_to :country_of_origin, :class_name => 'Logistics::Core::Country', optional: true belongs_to :acquisition_mode, optional: true belongs_to :payment_term, optional: true belongs_to :delivery_term, optional: true belongs_to :container_arrangement, optional: true belongs_to :customs_transport_tariff, optional: true belongs_to :esl_transport_tariff, optional: true belongs_to :warehouse, optional: true belongs_to :owner, class_name: 'Mks::Auth::User', optional: true has_many :operation_documents validates :operation_number, presence: true delegate(:full_name, to: :declarant, prefix: true, allow_nil: true) delegate(:name, to: :declaration_type, prefix: true, allow_nil: true) delegate(:name, to: :transport_mode, prefix: true, allow_nil: true) delegate(:name, to: :customs_office, prefix: true, allow_nil: true) delegate(:name, to: :customs_office_unit, prefix: true, allow_nil: true) delegate(:name, to: :country_of_origin, prefix: true, allow_nil: true) delegate(:name, to: :acquisition_mode, prefix: true, allow_nil: true) delegate(:name, to: :payment_term, prefix: true, allow_nil: true) delegate(:name, to: :delivery_term, prefix: true, allow_nil: true) delegate(:name, to: :container_arrangement, prefix: true, allow_nil: true) delegate(:name, to: :warehouse, prefix: true, allow_nil: true) delegate(:client, to: :offer_request, prefix: false, allow_nil: true) delegate(:request_no, to: :offer_request, prefix: false, allow_nil: true) scope :fresh, -> { where(:tasks_generated => false) } def self.build(options = {}) Operation.new(options) end end end end