mirror of
https://github.com/internetee/registry.git
synced 2025-07-01 08:43:37 +02:00
Merge pull request #46 from internetee/110245542-invoces_for_eu_users
110245542-callback_for_vat_percent
This commit is contained in:
commit
9f08bfa17a
1 changed files with 8 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue