Sha256: 8aba56fe344ad0aee6298e92bec80a1191a026a58eef50e03f60eec5d03a6db9

Contents?: true

Size: 1 KB

Versions: 33

Compression:

Stored size: 1 KB

Contents

module Comee
  module Core
    class CustomerOrderItem < ApplicationRecord
      default_scope { order(serial_no: :asc) }

      before_save :calculate_total_price

      belongs_to :customer_order
      belongs_to :product
      belongs_to :unit

      validates :serial_no, :customer_item_no, :customer_item_description, :quantity, :price, :delivery_date, presence: true
      validates :quantity, :price, numericality: {greater_than_or_equal_to: 0}
      validates :total_price, numericality: {greater_than_or_equal_to: 0}, allow_nil: true
      validates :serial_no, numericality: {greater_than: 0, only_integer: true}

      def calculate_total_price
        self.total_price = (price * quantity).round(2)
      end

      def self.ransackable_attributes(_auth_object = nil)
        %w[id customer_order_id product_id unit_id customer_item_no customer_item_description delivery_date]
      end

      def self.ransackable_associations(_auth_object = nil)
        %w[customer_order product unit]
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
comee_core-0.3.31 app/models/comee/core/customer_order_item.rb
comee_core-0.3.30 app/models/comee/core/customer_order_item.rb
comee_core-0.3.29 app/models/comee/core/customer_order_item.rb
comee_core-0.3.28 app/models/comee/core/customer_order_item.rb
comee_core-0.3.27 app/models/comee/core/customer_order_item.rb
comee_core-0.3.26 app/models/comee/core/customer_order_item.rb
comee_core-0.3.25 app/models/comee/core/customer_order_item.rb
comee_core-0.3.24 app/models/comee/core/customer_order_item.rb
comee_core-0.3.23 app/models/comee/core/customer_order_item.rb
comee_core-0.3.22 app/models/comee/core/customer_order_item.rb
comee_core-0.3.21 app/models/comee/core/customer_order_item.rb
comee_core-0.3.20 app/models/comee/core/customer_order_item.rb
comee_core-0.3.19 app/models/comee/core/customer_order_item.rb
comee_core-0.3.18 app/models/comee/core/customer_order_item.rb
comee_core-0.3.17 app/models/comee/core/customer_order_item.rb
comee_core-0.3.16 app/models/comee/core/customer_order_item.rb
comee_core-0.3.15 app/models/comee/core/customer_order_item.rb
comee_core-0.3.14 app/models/comee/core/customer_order_item.rb
comee_core-0.3.13 app/models/comee/core/customer_order_item.rb
comee_core-0.3.12 app/models/comee/core/customer_order_item.rb