12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/concerns/models/coupon_date_overridable.rb', line 12
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
unless 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
end
|