Class: Dscf::Marketplace::RfqItem

Inherits:
ApplicationRecord show all
Defined in:
app/models/dscf/marketplace/rfq_item.rb

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (Boolean)


47
48
49
# File 'app/models/dscf/marketplace/rfq_item.rb', line 47

def has_quotations?
  quotation_items.exists?
end

#highest_quoted_priceObject



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_priceObject



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_nameObject



27
28
29
# File 'app/models/dscf/marketplace/rfq_item.rb', line 27

def product_name
  product&.name
end

#product_skuObject



31
32
33
# File 'app/models/dscf/marketplace/rfq_item.rb', line 31

def product_sku
  product&.sku
end

#quotation_countObject



43
44
45
# File 'app/models/dscf/marketplace/rfq_item.rb', line 43

def quotation_count
  quotation_items.count
end

#quoted_price_rangeObject



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_quantityObject



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_codeObject



39
40
41
# File 'app/models/dscf/marketplace/rfq_item.rb', line 39

def unit_code
  unit&.code
end

#unit_nameObject



35
36
37
# File 'app/models/dscf/marketplace/rfq_item.rb', line 35

def unit_name
  unit&.name
end