Class: Comable::Stock

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Ransackable, SkuChoice, SkuItem, Csvable
Defined in:
app/models/comable/stock.rb,
app/models/comable/stock/csvable.rb

Overview

在庫モデル。 商品に複数紐付き、品数やSKU(Stock Keeping Unit)情報を保持する。

Defined Under Namespace

Modules: Csvable

Scope collapse

Instance Method Summary collapse

Methods included from Csvable

#product_code=

Methods included from SkuChoice

#name_with_sku, #sku_name

Methods included from SkuItem

#sku_h?, #sku_v?

Class Method Details

.stockedObject

品切れでない在庫インスタンスを返す



20
# File 'app/models/comable/stock.rb', line 20

scope :stocked, -> { where('quantity > ?', 0) }

.unstockedObject

品切れの在庫インスタンスを返す



24
# File 'app/models/comable/stock.rb', line 24

scope :unstocked, -> { where('quantity <= ?', 0) }

Instance Method Details

#stocked?(quantity: 1) ⇒ Boolean

在庫の有無を取得する

Examples:

stock.quanaity = 1
stock.stocked? #=> true

Parameters:

  • quantity (Fixnum) (defaults to: 1)

    減算する在庫数を指定する

Returns:

  • (Boolean)

    在庫があれば true を返す

See Also:



53
54
55
# File 'app/models/comable/stock.rb', line 53

def stocked?(quantity: 1)
  (self.quantity - quantity) >= 0
end

#unstocked?(quantity: 1) ⇒ Boolean

在庫の有無を取得する

Examples:

stock.quanaity = 1
stock.unstocked? #=> false

Parameters:

  • quantity (Fixnum) (defaults to: 1)

    減算する在庫数を指定する

Returns:

  • (Boolean)

    #stocked? の逆。在庫がなければ true を返す

See Also:



66
67
68
# File 'app/models/comable/stock.rb', line 66

def unstocked?(quantity: 1)
  !stocked?(quantity: quantity)
end