Module: Models::CouponDateOverridable

Extended by:
ActiveSupport::Concern
Included in:
Order, Quote
Defined in:
app/concerns/models/coupon_date_overridable.rb

Overview

Validates that a redemption's override_coupon_date stays within ±45 days
of the record's created_at (the grace period for back-dating a coupon
redemption), unless override_coupon_date_without_limits is set.

Instance Method Summary collapse

Instance Method Details

#override_coupon_date_limitvoid

This method returns an undefined value.

Validation: rejects an override_coupon_date outside the 45-day grace
window around created_at.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/concerns/models/coupon_date_overridable.rb', line 19

def override_coupon_date_limit
  return unless override_coupon_date && created_at
  return if override_coupon_date_without_limits
  return unless will_save_change_to_override_coupon_date?

  min_date = (created_at - 45.days).to_date
  max_date = (created_at + 45.days).to_date
  valid_range = min_date..max_date
  return if valid_range === override_coupon_date

  message = "exceeds 45 days grace period limits.  Must be between #{valid_range.first.to_fs(:crm_date_only)} and #{valid_range.last.to_fs(:crm_date_only)}"
  errors.add(:override_coupon_date, message)
end