Class: Dscf::Marketplace::RfqItem
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Dscf::Marketplace::RfqItem
- Defined in:
- app/models/dscf/marketplace/rfq_item.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
- #has_quotations? ⇒ Boolean
- #highest_quoted_price ⇒ Object
- #lowest_quoted_price ⇒ Object
- #product_name ⇒ Object
- #product_sku ⇒ Object
- #quotation_count ⇒ Object
- #quoted_price_range ⇒ Object
- #total_requested_quantity ⇒ Object
- #unit_code ⇒ Object
- #unit_name ⇒ Object
Class Method Details
.ransackable_associations(_auth_object = nil) ⇒ Object
23 24 25 |
# File 'app/models/dscf/marketplace/rfq_item.rb', line 23 def self.ransackable_associations(_auth_object = nil) %w[request_for_quotation product unit quotation_items] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
Ransack configuration for secure filtering
19 20 21 |
# File 'app/models/dscf/marketplace/rfq_item.rb', line 19 def self.ransackable_attributes(_auth_object = nil) %w[id request_for_quotation_id product_id unit_id quantity notes created_at updated_at] end |
Instance Method Details
#has_quotations? ⇒ Boolean
47 48 49 |
# File 'app/models/dscf/marketplace/rfq_item.rb', line 47 def has_quotations? quotation_items.exists? end |
#highest_quoted_price ⇒ Object
55 56 57 |
# File 'app/models/dscf/marketplace/rfq_item.rb', line 55 def highest_quoted_price quotation_items.where.not(unit_price: nil).maximum(:unit_price) end |
#lowest_quoted_price ⇒ Object
51 52 53 |
# File 'app/models/dscf/marketplace/rfq_item.rb', line 51 def lowest_quoted_price quotation_items.where.not(unit_price: nil).minimum(:unit_price) end |
#product_name ⇒ Object
27 28 29 |
# File 'app/models/dscf/marketplace/rfq_item.rb', line 27 def product_name product&.name end |
#product_sku ⇒ Object
31 32 33 |
# File 'app/models/dscf/marketplace/rfq_item.rb', line 31 def product_sku product&.sku end |
#quotation_count ⇒ Object
43 44 45 |
# File 'app/models/dscf/marketplace/rfq_item.rb', line 43 def quotation_count quotation_items.count end |
#quoted_price_range ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'app/models/dscf/marketplace/rfq_item.rb', line 59 def quoted_price_range return nil unless has_quotations? low = lowest_quoted_price high = highest_quoted_price return low if low == high "#{low} - #{high}" end |
#total_requested_quantity ⇒ Object
69 70 71 72 73 74 |
# File 'app/models/dscf/marketplace/rfq_item.rb', line 69 def total_requested_quantity return nil unless quantity && unit # Convert to base unit for comparison if needed quantity end |
#unit_code ⇒ Object
39 40 41 |
# File 'app/models/dscf/marketplace/rfq_item.rb', line 39 def unit_code unit&.code end |
#unit_name ⇒ Object
35 36 37 |
# File 'app/models/dscf/marketplace/rfq_item.rb', line 35 def unit_name unit&.name end |