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