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
28 29 30 |
# File 'app/models/dscf/marketplace/supplier_product.rb', line 28 def self.ransackable_associations(_auth_object = nil) %w[business product supplier listings order_items] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
24 25 26 |
# File 'app/models/dscf/marketplace/supplier_product.rb', line 24 def self.ransackable_attributes(_auth_object = nil) %w[id business_id product_id supplier_id supplier_price available_quantity minimum_order_quantity status created_at updated_at] end |
Instance Method Details
#available_for_order?(quantity = 1) ⇒ Boolean
50 51 52 |
# File 'app/models/dscf/marketplace/supplier_product.rb', line 50 def available_for_order?(quantity = 1) active? && can_fulfill?(quantity) end |
#can_fulfill?(quantity) ⇒ Boolean
37 38 39 |
# File 'app/models/dscf/marketplace/supplier_product.rb', line 37 def can_fulfill?(quantity) available_quantity >= quantity end |
#display_name ⇒ Object
46 47 48 |
# File 'app/models/dscf/marketplace/supplier_product.rb', line 46 def display_name "#{business.name} - #{product.name}" end |
#in_stock? ⇒ Boolean
Custom methods
33 34 35 |
# File 'app/models/dscf/marketplace/supplier_product.rb', line 33 def in_stock? available_quantity > 0 end |
#price_per_unit ⇒ Object
41 42 43 44 |
# File 'app/models/dscf/marketplace/supplier_product.rb', line 41 def price_per_unit return nil unless supplier_price && product&.base_quantity supplier_price / product.base_quantity end |