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



25
26
27
# File 'app/models/dscf/marketplace/rfq_item.rb', line 25

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



21
22
23
# File 'app/models/dscf/marketplace/rfq_item.rb', line 21

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)


49
50
51
# File 'app/models/dscf/marketplace/rfq_item.rb', line 49

def has_quotations?
  quotation_items.exists?
end

#highest_quoted_priceObject



57
58
59
# File 'app/models/dscf/marketplace/rfq_item.rb', line 57

def highest_quoted_price
  quotation_items.where.not(unit_price: nil).maximum(:unit_price)
end

#lowest_quoted_priceObject



53
54
55
# File 'app/models/dscf/marketplace/rfq_item.rb', line 53

def lowest_quoted_price
  quotation_items.where.not(unit_price: nil).minimum(:unit_price)
end

#product_nameObject



29
30
31
# File 'app/models/dscf/marketplace/rfq_item.rb', line 29

def product_name
  product&.name
end

#product_skuObject



33
34
35
# File 'app/models/dscf/marketplace/rfq_item.rb', line 33

def product_sku
  product&.sku
end

#quotation_countObject



45
46
47
# File 'app/models/dscf/marketplace/rfq_item.rb', line 45

def quotation_count
  quotation_items.count
end

#quoted_price_rangeObject



61
62
63
64
65
66
67
68
69
# File 'app/models/dscf/marketplace/rfq_item.rb', line 61

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



71
72
73
74
75
76
# File 'app/models/dscf/marketplace/rfq_item.rb', line 71

def total_requested_quantity
  return nil unless quantity && unit

  # Convert to base unit for comparison if needed
  quantity
end

#unit_codeObject



41
42
43
# File 'app/models/dscf/marketplace/rfq_item.rb', line 41

def unit_code
  unit&.code
end

#unit_nameObject



37
38
39
# File 'app/models/dscf/marketplace/rfq_item.rb', line 37

def unit_name
  unit&.name
end