Class: Warranty::Product

Inherits:
ApplicationRecord show all
Defined in:
app/models/warranty/product.rb

Overview

One registered UNIT under a Warranty — a qty-3 roll line is three
products, because every roll/cable has its own serial and resistance
readings on the card, and every product line its own term (TempZone 25yr,
snow melting 10yr, …) and therefore its own expiry.

Constant Summary

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

Belongs to collapse

Delegated Instance Attributes collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Method Details

#coverage_starts_onObject

Alias for Warranty#coverage_starts_on

Returns:

  • (Object)

    Warranty#coverage_starts_on

See Also:



42
# File 'app/models/warranty/product.rb', line 42

delegate :coverage_starts_on, to: :warranty, allow_nil: true

#expired?Boolean

Returns whether the stored expiration has passed.

Returns:

  • (Boolean)

    whether the stored expiration has passed



82
83
84
# File 'app/models/warranty/product.rb', line 82

def expired?
  valid_until.present? && valid_until < Date.current
end

#line_itemLineItem

The order line this unit came from (order-matched registrations).

Returns:

See Also:



37
# File 'app/models/warranty/product.rb', line 37

belongs_to :line_item, optional: true

#product_line_labelString

Returns human label for the product line.

Returns:

  • (String)

    human label for the product line



69
70
71
# File 'app/models/warranty/product.rb', line 69

def product_line_label
  Warranty::PRODUCT_LINE_LABELS.fetch(product_line, product_line.to_s.humanize)
end

#term_in_yearsInteger?

Warranty duration in years: the printed-term override when set,
otherwise the TERMS default for the line.

Returns:

  • (Integer, nil)


77
78
79
# File 'app/models/warranty/product.rb', line 77

def term_in_years
  (term_years.presence || Warranty::TERMS[product_line])&.to_i
end

#warrantyWarranty

Returns:

See Also:



35
# File 'app/models/warranty/product.rb', line 35

belongs_to :warranty, inverse_of: :products