Class: Comable::Stock
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Comable::Stock
- 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
-
.stocked ⇒ Object
品切れでない在庫インスタンスを返す.
-
.unstocked ⇒ Object
品切れの在庫インスタンスを返す.
Instance Method Summary collapse
-
#stocked?(quantity: 1) ⇒ Boolean
在庫の有無を取得する.
-
#unstocked?(quantity: 1) ⇒ Boolean
在庫の有無を取得する.
Methods included from Csvable
Methods included from SkuChoice
Methods included from SkuItem
Class Method Details
.stocked ⇒ Object
品切れでない在庫インスタンスを返す
20 |
# File 'app/models/comable/stock.rb', line 20 scope :stocked, -> { where('quantity > ?', 0) } |
.unstocked ⇒ Object
品切れの在庫インスタンスを返す
24 |
# File 'app/models/comable/stock.rb', line 24 scope :unstocked, -> { where('quantity <= ?', 0) } |
Instance Method Details
#stocked?(quantity: 1) ⇒ Boolean
在庫の有無を取得する
53 54 55 |
# File 'app/models/comable/stock.rb', line 53 def stocked?(quantity: 1) (self.quantity - quantity) >= 0 end |
#unstocked?(quantity: 1) ⇒ Boolean
在庫の有無を取得する
66 67 68 |
# File 'app/models/comable/stock.rb', line 66 def unstocked?(quantity: 1) !stocked?(quantity: quantity) end |