Fix VAT rate

#623
This commit is contained in:
Artur Beljajev 2018-03-13 09:02:08 +02:00
parent 6dfd57ee2e
commit a73a8a0b89
5 changed files with 17 additions and 12 deletions

View file

@ -32,8 +32,8 @@ class Invoice < ActiveRecord::Base
validates :vat_rate, numericality: { greater_than_or_equal_to: 0, less_than: 100 },
allow_nil: true
after_initialize :apply_defaults
before_create :set_invoice_number
before_create :apply_default_vat_rate, unless: :vat_rate?
attribute :vat_rate, ::Type::VATRate.new
attr_readonly :vat_rate
@ -156,7 +156,7 @@ class Invoice < ActiveRecord::Base
def vat
return 0 unless vat_rate
(sum_without_vat * vat_rate).round(2)
sum_without_vat * vat_rate / 100
end
def sum
@ -165,7 +165,7 @@ class Invoice < ActiveRecord::Base
private
def apply_defaults
self.vat_rate = buyer.effective_vat_rate unless vat_rate
def apply_default_vat_rate
self.vat_rate = buyer.effective_vat_rate
end
end

View file

@ -24,7 +24,7 @@
%td= currency(@invoice.sum_without_vat)
%tr
%th.no-border{colspan: 3}
%th= t('vat', rate: (@invoice.vat_rate * 100).round)
%th= t('vat', rate: number_to_percentage(@invoice.vat_rate, precision: 1))
%td= currency(@invoice.vat)
%tr
%th.no-border{colspan: 3}

View file

@ -242,7 +242,7 @@
%td= "#{currency(@invoice.sum_without_vat)} #{@invoice.currency}"
%tr
%th.no-border{colspan: 3}
%th= t('vat', rate: (@invoice.vat_rate * 100).round)
%th= t('vat', rate: number_to_percentage(@invoice.vat_rate, precision: 1))
%td= "#{currency(@invoice.vat)} #{@invoice.currency}"
%tr
%th.no-border{colspan: 3}