mirror of
https://github.com/internetee/registry.git
synced 2025-08-04 00:42:04 +02:00
parent
6dfd57ee2e
commit
a73a8a0b89
5 changed files with 17 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue