110245542-callback_for_vat_percent

This commit is contained in:
Stas 2015-12-18 17:39:41 +02:00
parent 6b60aef4b1
commit 52d1f79df0

View file

@ -18,6 +18,8 @@ class Invoice < ActiveRecord::Base
:seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true
before_create :set_invoice_number
before_create :check_vat
def set_invoice_number
last_no = Invoice.order(number: :desc).where('number IS NOT NULL').limit(1).pluck(:number).first
@ -34,6 +36,12 @@ class Invoice < ActiveRecord::Base
false
end
def check_vat
if buyer.country_code = 'EE' && buyer.vat_no.present?
self.vat_prc = 0
end
end
before_save -> { self.sum_cache = sum }
class << self