1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-18 12:54:27 +01:00
fab-manager/app/models/coupon.rb

19 lines
411 B
Ruby
Raw Normal View History

2016-08-03 17:25:00 +02:00
class Coupon < ActiveRecord::Base
has_many :invoices
2016-08-03 17:25:00 +02:00
2016-08-04 18:13:19 +02:00
validates :name, presence: true
2016-08-03 17:25:00 +02:00
validates :code, presence: true
2016-08-04 18:13:19 +02:00
validates :code, format: { with: /\A[A-Z0-9]+\z/ ,message: 'only caps letters and numbers'}
2016-08-03 17:25:00 +02:00
validates :percent_off, presence: true
validates :percent_off, :inclusion => 0..100
2016-08-08 12:25:27 +02:00
def safe_destroy
if self.invoices.size == 0
destroy
else
false
end
end
2016-08-03 17:25:00 +02:00
end