Class: Dscf::Marketplace::QuotationItem
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Dscf::Marketplace::QuotationItem
- Defined in:
- app/models/dscf/marketplace/quotation_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
- #can_create_order? ⇒ Boolean
- #matches_rfq_request? ⇒ Boolean
- #price_per_base_unit ⇒ Object
- #product_name ⇒ Object
- #product_sku ⇒ Object
- #quantity_difference ⇒ Object
- #quantity_difference_percentage ⇒ Object
- #rfq_requested_quantity ⇒ Object
-
#subtotal ⇒ Object
Override subtotal getter to calculate if not set.
-
#subtotal=(value) ⇒ Object
Override subtotal setter to allow validation to work.
- #unit_code ⇒ Object
- #unit_name ⇒ Object
Class Method Details
.ransackable_associations(_auth_object = nil) ⇒ Object
31 32 33 |
# File 'app/models/dscf/marketplace/quotation_item.rb', line 31 def self.ransackable_associations(_auth_object = nil) %w[quotation rfq_item product unit] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
Ransack configuration for secure filtering
27 28 29 |
# File 'app/models/dscf/marketplace/quotation_item.rb', line 27 def self.ransackable_attributes(_auth_object = nil) %w[id quotation_id rfq_item_id product_id unit_id quantity unit_price subtotal notes created_at updated_at] end |
Instance Method Details
#can_create_order? ⇒ Boolean
79 80 81 |
# File 'app/models/dscf/marketplace/quotation_item.rb', line 79 def can_create_order? quotation.sent? || quotation.accepted? end |
#matches_rfq_request? ⇒ Boolean
73 74 75 76 77 |
# File 'app/models/dscf/marketplace/quotation_item.rb', line 73 def matches_rfq_request? return false unless rfq_item product_id == rfq_item.product_id && unit_id == rfq_item.unit_id end |
#price_per_base_unit ⇒ Object
67 68 69 70 71 |
# File 'app/models/dscf/marketplace/quotation_item.rb', line 67 def price_per_base_unit return nil unless unit_price && quantity && quantity > 0 unit_price / quantity end |
#product_name ⇒ Object
35 36 37 |
# File 'app/models/dscf/marketplace/quotation_item.rb', line 35 def product_name product&.name end |
#product_sku ⇒ Object
39 40 41 |
# File 'app/models/dscf/marketplace/quotation_item.rb', line 39 def product_sku product&.sku end |
#quantity_difference ⇒ Object
55 56 57 58 59 |
# File 'app/models/dscf/marketplace/quotation_item.rb', line 55 def quantity_difference return nil unless quantity && rfq_requested_quantity quantity - rfq_requested_quantity end |
#quantity_difference_percentage ⇒ Object
61 62 63 64 65 |
# File 'app/models/dscf/marketplace/quotation_item.rb', line 61 def quantity_difference_percentage return nil unless quantity && rfq_requested_quantity && rfq_requested_quantity > 0 ((quantity_difference.to_f / rfq_requested_quantity) * 100).round(2) end |
#rfq_requested_quantity ⇒ Object
51 52 53 |
# File 'app/models/dscf/marketplace/quotation_item.rb', line 51 def rfq_requested_quantity rfq_item&.quantity end |
#subtotal ⇒ Object
Override subtotal getter to calculate if not set
111 112 113 114 115 116 117 118 119 |
# File 'app/models/dscf/marketplace/quotation_item.rb', line 111 def subtotal stored_value = super # If we have a stored value (including 0), return it return stored_value unless stored_value.nil? # If no stored value but we have unit_price and quantity, calculate it return (unit_price * quantity).round(2) if unit_price && quantity # Otherwise return nil nil end |
#subtotal=(value) ⇒ Object
Override subtotal setter to allow validation to work
104 105 106 107 |
# File 'app/models/dscf/marketplace/quotation_item.rb', line 104 def subtotal=(value) # Allow any value to be set for validation purposes super end |
#unit_code ⇒ Object
47 48 49 |
# File 'app/models/dscf/marketplace/quotation_item.rb', line 47 def unit_code unit&.code end |
#unit_name ⇒ Object
43 44 45 |
# File 'app/models/dscf/marketplace/quotation_item.rb', line 43 def unit_name unit&.name end |