summaryrefslogtreecommitdiff
path: root/app/models/concerns/destroy_if_zero_quantity.rb
blob: e57310870ca3f221e0702b984e55c5ef34f8b25e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module DestroyIfZeroQuantity
  extend ActiveSupport::Concern

  included do
    after_save :destroy_if_zero_quantity
  end

  private
    def destroy_if_zero_quantity
      if self.quantity == 0
        destroy
      elsif self.quantity < 0
        # TODO: Can improve this (at the least, with reporting, later).
        raise ItemQuantityError
      end
    end
end