Class: Accountability::Discount

Inherits:
ApplicationRecord show all
Defined in:
app/models/accountability/discount.rb

Instance Method Summary collapse

Methods inherited from ApplicationRecord

validates_attributes

Instance Method Details

#apply(credit) ⇒ Object



8
9
10
11
12
# File 'app/models/accountability/discount.rb', line 8

def apply(credit)
  return unless usable?

  credit.deductions.new(discount: self)
end

#expected_savingsObject



24
25
26
27
# File 'app/models/accountability/discount.rb', line 24

def expected_savings
  percent_off = coupon_amount / 100.00
  order_item.default_price * percent_off
end

#usable?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'app/models/accountability/discount.rb', line 18

def usable?
  return false if used_up?

  coupon.usable?
end

#usagesObject



14
15
16
# File 'app/models/accountability/discount.rb', line 14

def usages
  deductions.count
end