mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 03:30:33 +02:00
parent
3d107bd198
commit
b68fe6e312
16 changed files with 110 additions and 92 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue