Sha256: 326548a72459e7d0b5e8fafcb9b6e73a25a9f0e76c6d026d1949ae2381e4aef9

Contents?: true

Size: 986 Bytes

Versions: 35

Compression:

Stored size: 986 Bytes

Contents

module Comee
  module Core
    class QuotationRequest < ApplicationRecord
      before_validation :set_reference_no, if: proc { |rfq| rfq.reference_no.nil? }

      belongs_to :client
      belongs_to :delivery_address,
                 -> { where(address_type: ClientAddress::DELIVERY_ADDRESS) },
                 class_name: "Comee::Core::ClientAddress"
      belongs_to :invoice_address,
                 -> { where(address_type: ClientAddress::INVOICING_ADDRESS) },
                 class_name: "Comee::Core::ClientAddress"
      has_many :quotation_request_items

      enum :status, {draft: 0, submitted: 1, awaiting_confirmation: 2, confirmed: 3, converted: 4}

      validates :status, presence: true

      def self.ransackable_attributes(_auth_object = nil)
        %w[id client_id reference_no status]
      end

      private

      def set_reference_no
        stamp = DateTime.now.to_i
        self.reference_no = "RFQ-#{client.code}-#{stamp}"
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
comee_core-0.3.62 app/models/comee/core/quotation_request.rb
comee_core-0.3.61 app/models/comee/core/quotation_request.rb
comee_core-0.3.60 app/models/comee/core/quotation_request.rb
comee_core-0.3.59 app/models/comee/core/quotation_request.rb
comee_core-0.3.58 app/models/comee/core/quotation_request.rb
comee_core-0.3.57 app/models/comee/core/quotation_request.rb
comee_core-0.3.56 app/models/comee/core/quotation_request.rb
comee_core-0.3.55 app/models/comee/core/quotation_request.rb
comee_core-0.3.54 app/models/comee/core/quotation_request.rb
comee_core-0.3.53 app/models/comee/core/quotation_request.rb
comee_core-0.3.51 app/models/comee/core/quotation_request.rb
comee_core-0.3.50 app/models/comee/core/quotation_request.rb
comee_core-0.3.49 app/models/comee/core/quotation_request.rb
comee_core-0.3.48 app/models/comee/core/quotation_request.rb
comee_core-0.3.47 app/models/comee/core/quotation_request.rb
comee_core-0.3.46 app/models/comee/core/quotation_request.rb
comee_core-0.3.45 app/models/comee/core/quotation_request.rb
comee_core-0.3.44 app/models/comee/core/quotation_request.rb
comee_core-0.3.43 app/models/comee/core/quotation_request.rb
comee_core-0.3.42 app/models/comee/core/quotation_request.rb