Sha256: b5255df6cdf7b40eacf0806973eeb0e4db0bf2f0fc4c86294ca1758f95ae48cf

Contents?: true

Size: 605 Bytes

Versions: 17

Compression:

Stored size: 605 Bytes

Contents

module Ecom
  module Core
    class MaterialItem < ApplicationRecord
      before_save :assign_serial_number

      belongs_to :material_identity

      validates :serial_number, presence: true, uniqueness: true
      validates :material_identity_id, :material_identity, presence: true
      validates :serial_number, format: { with: /^SN_\d+$/, message: 'Invalid serial number format', multiline: true }
      validates :price, numericality: { greater_than: 0 }, allow_nil: true

      def assign_serial_number
        self.serial_number = "SN_#{(Time.now.to_f * 1000).to_i}"
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ecom_core-1.3.14 app/models/ecom/core/material_item.rb
ecom_core-1.3.13 app/models/ecom/core/material_item.rb
ecom_core-1.3.12 app/models/ecom/core/material_item.rb
ecom_core-1.3.11 app/models/ecom/core/material_item.rb
ecom_core-1.3.10 app/models/ecom/core/material_item.rb
ecom_core-1.3.9 app/models/ecom/core/material_item.rb
ecom_core-1.3.8 app/models/ecom/core/material_item.rb
ecom_core-1.3.7 app/models/ecom/core/material_item.rb
ecom_core-1.3.6 app/models/ecom/core/material_item.rb
ecom_core-1.3.5 app/models/ecom/core/material_item.rb
ecom_core-1.3.4 app/models/ecom/core/material_item.rb
ecom_core-1.3.3 app/models/ecom/core/material_item.rb
ecom_core-1.3.2 app/models/ecom/core/material_item.rb
ecom_core-1.3.1 app/models/ecom/core/material_item.rb
ecom_core-1.3.0 app/models/ecom/core/material_item.rb
ecom_core-1.2.36 app/models/ecom/core/material_item.rb
ecom_core-1.2.35 app/models/ecom/core/material_item.rb