Check if invoice is already cancelled before cancelling

This commit is contained in:
Martin Lensment 2015-04-27 11:23:55 +03:00
parent a26ce110b2
commit 41c2e2d5e4
2 changed files with 7 additions and 0 deletions

View file

@ -72,6 +72,12 @@ class Invoice < ActiveRecord::Base
errors.add(:base, I18n.t('cannot_cancel_paid_invoice'))
return false
end
if cancelled?
errors.add(:base, I18n.t('cannot_cancel_cancelled_invoice'))
return false
end
self.cancelled_at = Time.zone.now
save
end

View file

@ -738,4 +738,5 @@ en:
cancelled: 'Cancelled'
cancel_date: 'Cancel date'
cannot_cancel_paid_invoice: 'Cannot cancel paid invoice'
cannot_cancel_cancelled_invoice: 'Cannot cancel cancelled invoice'
cannot_bind_cancelled_invoice: 'Cannot bind cancelled invoice'