Add "VATCode" and "TotalVAT" fields to Directo

#623
This commit is contained in:
Artur Beljajev 2018-03-14 14:48:20 +02:00
parent 1107dc67b8
commit 169c67839e
5 changed files with 34 additions and 3 deletions

View file

@ -35,6 +35,7 @@ class Invoice < ActiveRecord::Base
before_create :set_invoice_number
before_create :apply_default_vat_rate, unless: :vat_rate?
before_create :calculate_total, unless: :total?
before_create :apply_default_buyer_vat_no, unless: :buyer_vat_no?
attribute :vat_rate, ::Type::VATRate.new
attr_readonly :vat_rate
@ -169,6 +170,10 @@ class Invoice < ActiveRecord::Base
self.vat_rate = buyer.effective_vat_rate
end
def apply_default_buyer_vat_no
self.buyer_vat_no = buyer.vat_no
end
def calculate_total
self.total = subtotal + vat_amount
end