Sha256: 6833e4057071e7cc1827005e060a6d52739197f5ffa4bc95dd751eedc0cad0f5

Contents?: true

Size: 1.52 KB

Versions: 29

Compression:

Stored size: 1.52 KB

Contents

module Comee
  module Core
    class CustomerOrder < ApplicationRecord
      OWN = "Own".freeze
      AGENT = "Agent".freeze
      SHIPPING_ARRANGEMENTS = [OWN, AGENT].freeze

      belongs_to :client
      belongs_to :shipment_address,
                 -> { where(address_type: ClientAddress::SHIPPING_ADDRESS) },
                 class_name: "Comee::Core::ClientAddress",
                 optional: true
      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 :customer_order_items
      has_one_attached :file

      enum :status, {draft: 0, submitted: 1, awaiting_confirmation: 2, accepted: 3, canceled: 4}

      validates :order_number, :order_date, :delivery_address, :invoice_address, :status, presence: true
      validates :shipping_arrangement, inclusion: {in: SHIPPING_ARRANGEMENTS}, allow_nil: true

      def self.ransackable_attributes(_auth_object = nil)
        %w[id client_id delivery_address invoice_address order_number status final_destination consignee]
      end

      def self.ransackable_associations(_auth_object = nil)
        %w[client customer_order_items]
      end

      def file_url
        file.attached? ? Rails.application.routes.url_helpers.rails_blob_url(file, only_path: false) : nil
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
comee_core-0.3.56 app/models/comee/core/customer_order.rb
comee_core-0.3.55 app/models/comee/core/customer_order.rb
comee_core-0.3.54 app/models/comee/core/customer_order.rb
comee_core-0.3.53 app/models/comee/core/customer_order.rb
comee_core-0.3.51 app/models/comee/core/customer_order.rb
comee_core-0.3.50 app/models/comee/core/customer_order.rb
comee_core-0.3.49 app/models/comee/core/customer_order.rb
comee_core-0.3.48 app/models/comee/core/customer_order.rb
comee_core-0.3.47 app/models/comee/core/customer_order.rb
comee_core-0.3.46 app/models/comee/core/customer_order.rb
comee_core-0.3.45 app/models/comee/core/customer_order.rb
comee_core-0.3.44 app/models/comee/core/customer_order.rb
comee_core-0.3.43 app/models/comee/core/customer_order.rb
comee_core-0.3.42 app/models/comee/core/customer_order.rb
comee_core-0.3.41 app/models/comee/core/customer_order.rb
comee_core-0.3.40 app/models/comee/core/customer_order.rb
comee_core-0.3.39 app/models/comee/core/customer_order.rb
comee_core-0.3.38 app/models/comee/core/customer_order.rb
comee_core-0.3.37 app/models/comee/core/customer_order.rb
comee_core-0.3.36 app/models/comee/core/customer_order.rb