Class: Dscf::Marketplace::SupplierProduct
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Dscf::Marketplace::SupplierProduct
- Defined in:
- app/models/dscf/marketplace/supplier_product.rb
Class Method Summary collapse
- .ransackable_associations(_auth_object = nil) ⇒ Object
- .ransackable_attributes(_auth_object = nil) ⇒ Object
Instance Method Summary collapse
- #available_for_order?(quantity = 1) ⇒ Boolean
- #can_fulfill?(quantity) ⇒ Boolean
- #display_name ⇒ Object
-
#in_stock? ⇒ Boolean
Custom methods.
- #price_per_unit ⇒ Object
Class Method Details
.ransackable_associations(_auth_object = nil) ⇒ Object
26 27 28 |
# File 'app/models/dscf/marketplace/supplier_product.rb', line 26 def self.ransackable_associations(_auth_object = nil) %w[business product listings order_items] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
22 23 24 |
# File 'app/models/dscf/marketplace/supplier_product.rb', line 22 def self.ransackable_attributes(_auth_object = nil) %w[id business_id product_id supplier_price available_quantity minimum_order_quantity status created_at updated_at] end |
Instance Method Details
#available_for_order?(quantity = 1) ⇒ Boolean
48 49 50 |
# File 'app/models/dscf/marketplace/supplier_product.rb', line 48 def available_for_order?(quantity = 1) active? && can_fulfill?(quantity) end |
#can_fulfill?(quantity) ⇒ Boolean
35 36 37 |
# File 'app/models/dscf/marketplace/supplier_product.rb', line 35 def can_fulfill?(quantity) available_quantity >= quantity end |
#display_name ⇒ Object
44 45 46 |
# File 'app/models/dscf/marketplace/supplier_product.rb', line 44 def display_name "#{business.name} - #{product.name}" end |
#in_stock? ⇒ Boolean
Custom methods
31 32 33 |
# File 'app/models/dscf/marketplace/supplier_product.rb', line 31 def in_stock? available_quantity > 0 end |
#price_per_unit ⇒ Object
39 40 41 42 |
# File 'app/models/dscf/marketplace/supplier_product.rb', line 39 def price_per_unit return nil unless supplier_price && product&.base_quantity supplier_price / product.base_quantity end |