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
-
.by_newest ⇒ Object
returns sorted records by newest.
-
.stocked ⇒ Object
品切れでない在庫インスタンスを返す.
-
.unstocked ⇒ Object
品切れの在庫インスタンスを返す.
Instance Method Summary collapse
- #code ⇒ Object
- #product=(product) ⇒ Object
- #set_default_stock_location ⇒ Object
- #sku_h_choice_name ⇒ Object
- #sku_v_choice_name ⇒ Object
-
#stocked?(quantity: 1) ⇒ Boolean
在庫の有無を取得する.
-
#unstocked?(quantity: 1) ⇒ Boolean
在庫の有無を取得する.
Methods included from Csvable
Methods included from SkuChoice
Methods included from SkuItem
Class Method Details
.by_newest ⇒ Object
returns sorted records by newest.
30 |
# File 'app/models/comable/stock.rb', line 30 scope :by_newest, -> { reorder(created_at: :desc) } |
.stocked ⇒ Object
品切れでない在庫インスタンスを返す
22 |
# File 'app/models/comable/stock.rb', line 22 scope :stocked, -> { where('quantity > ?', 0) } |
.unstocked ⇒ Object
品切れの在庫インスタンスを返す
26 |
# File 'app/models/comable/stock.rb', line 26 scope :unstocked, -> { where('quantity <= ?', 0) } |
Instance Method Details
#code ⇒ Object
84 85 86 |
# File 'app/models/comable/stock.rb', line 84 def code variant.sku end |
#product=(product) ⇒ Object
88 89 90 91 92 93 94 |
# File 'app/models/comable/stock.rb', line 88 def product=(product) if variant variant.product = product else build_variant(product: product) end end |
#set_default_stock_location ⇒ Object
96 97 98 |
# File 'app/models/comable/stock.rb', line 96 def set_default_stock_location self.stock_location = Comable::StockLocation.default end |
#sku_h_choice_name ⇒ Object
76 77 78 |
# File 'app/models/comable/stock.rb', line 76 def sku_h_choice_name variant.option_values.first.try(:name) end |
#sku_v_choice_name ⇒ Object
80 81 82 |
# File 'app/models/comable/stock.rb', line 80 def sku_v_choice_name variant.option_values.second.try(:name) end |
#stocked?(quantity: 1) ⇒ Boolean
在庫の有無を取得する
59 60 61 |
# File 'app/models/comable/stock.rb', line 59 def stocked?(quantity: 1) (self.quantity - quantity) >= 0 end |
#unstocked?(quantity: 1) ⇒ Boolean
在庫の有無を取得する
72 73 74 |
# File 'app/models/comable/stock.rb', line 72 def unstocked?(quantity: 1) !stocked?(quantity: quantity) end |