Rename attributes

#623
This commit is contained in:
Artur Beljajev 2018-03-13 11:32:15 +02:00
parent 3d107bd198
commit b68fe6e312
16 changed files with 110 additions and 92 deletions

View file

@ -34,6 +34,7 @@ class Invoice < ActiveRecord::Base
before_create :set_invoice_number
before_create :apply_default_vat_rate, unless: :vat_rate?
before_create :save_total
attribute :vat_rate, ::Type::VATRate.new
attr_readonly :vat_rate
@ -54,8 +55,6 @@ class Invoice < ActiveRecord::Base
false
end
before_save -> { self.sum_cache = sum }
class << self
def cancel_overdue_invoices
STDOUT << "#{Time.zone.now.utc} - Cancelling overdue invoices\n" unless Rails.env.test?
@ -150,17 +149,13 @@ class Invoice < ActiveRecord::Base
invoice_items
end
def sum_without_vat
def subtotal
(items.map(&:item_sum_without_vat).sum).round(2)
end
def vat
return 0 unless vat_rate
sum_without_vat * vat_rate / 100
end
def sum
(sum_without_vat + vat).round(2)
subtotal * vat_rate / 100
end
private
@ -168,4 +163,8 @@ class Invoice < ActiveRecord::Base
def apply_default_vat_rate
self.vat_rate = buyer.effective_vat_rate
end
def calculate_total
# (sum_without_vat + vat).round(2)
end
end