Class: Dscf::Marketplace::Listing
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Dscf::Marketplace::Listing
- Defined in:
- app/models/dscf/marketplace/listing.rb
Class Method Summary collapse
- .ransackable_associations(_auth_object = nil) ⇒ Object
-
.ransackable_attributes(_auth_object = nil) ⇒ Object
Ransack configuration for secure filtering.
Instance Method Summary collapse
- #available? ⇒ Boolean
- #can_be_managed_by?(business) ⇒ Boolean
- #margin ⇒ Object
- #margin_percentage ⇒ Object
- #product ⇒ Object
- #supplier_business ⇒ Object
-
#total_value ⇒ Object
Custom methods.
Class Method Details
.ransackable_associations(_auth_object = nil) ⇒ Object
29 30 31 |
# File 'app/models/dscf/marketplace/listing.rb', line 29 def self.ransackable_associations(_auth_object = nil) %w[business supplier_product order_items] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
Ransack configuration for secure filtering
25 26 27 |
# File 'app/models/dscf/marketplace/listing.rb', line 25 def self.ransackable_attributes(_auth_object = nil) %w[id business_id supplier_product_id price quantity status created_at updated_at] end |
Instance Method Details
#available? ⇒ Boolean
48 49 50 |
# File 'app/models/dscf/marketplace/listing.rb', line 48 def available? active? && quantity > 0 end |
#can_be_managed_by?(business) ⇒ Boolean
60 61 62 |
# File 'app/models/dscf/marketplace/listing.rb', line 60 def can_be_managed_by?(business) self.business == business end |
#margin ⇒ Object
38 39 40 41 |
# File 'app/models/dscf/marketplace/listing.rb', line 38 def margin return nil unless supplier_product&.supplier_price price - supplier_product.supplier_price end |
#margin_percentage ⇒ Object
43 44 45 46 |
# File 'app/models/dscf/marketplace/listing.rb', line 43 def margin_percentage return nil unless supplier_product&.supplier_price && supplier_product.supplier_price > 0 ((margin / supplier_product.supplier_price) * 100).round(2) end |
#product ⇒ Object
56 57 58 |
# File 'app/models/dscf/marketplace/listing.rb', line 56 def product supplier_product&.product end |
#supplier_business ⇒ Object
52 53 54 |
# File 'app/models/dscf/marketplace/listing.rb', line 52 def supplier_business supplier_product&.business end |
#total_value ⇒ Object
Custom methods
34 35 36 |
# File 'app/models/dscf/marketplace/listing.rb', line 34 def total_value price * quantity end |