diff --git a/app/models/directo.rb b/app/models/directo.rb index 62cf43804..4a5f00dd9 100644 --- a/app/models/directo.rb +++ b/app/models/directo.rb @@ -34,7 +34,7 @@ class Directo < ActiveRecord::Base xml.line( "ProductID" => Setting.directo_receipt_product_name, "Quantity" => 1, - "UnitPriceWoVAT" => ActionController::Base.helpers.number_with_precision(invoice.sum_cache/(1+invoice.vat_prc), precision: 2, separator: "."), + "UnitPriceWoVAT" => ActionController::Base.helpers.number_with_precision(invoice.sum_cache/(1+invoice.vat_rate), precision: 2, separator: "."), "ProductName" => invoice.order ) } diff --git a/app/models/invoice.rb b/app/models/invoice.rb index ad478443d..37eb8a72c 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -28,7 +28,7 @@ class Invoice < ActiveRecord::Base validates :billing_email, email_format: { message: :invalid }, allow_blank: true validates :invoice_type, :due_date, :currency, :seller_name, - :seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true + :seller_iban, :buyer_name, :invoice_items, :vat_rate, presence: true before_create :set_invoice_number, :check_vat @@ -52,7 +52,7 @@ class Invoice < ActiveRecord::Base def check_vat if buyer.country_code != 'EE' && buyer.vat_no.present? - self.vat_prc = 0 + self.vat_rate = 0 end end @@ -157,7 +157,7 @@ class Invoice < ActiveRecord::Base end def vat - (sum_without_vat * vat_prc).round(2) + (sum_without_vat * vat_rate).round(2) end def sum diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 46022808f..5fb68fea2 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -81,7 +81,7 @@ class Registrar < ActiveRecord::Base payment_term: 'prepayment', description: description, currency: 'EUR', - vat_prc: Setting.registry_vat_prc, + vat_rate: Setting.registry_vat_prc, seller_name: Setting.registry_juridical_name, seller_reg_no: Setting.registry_reg_no, seller_iban: Setting.registry_iban, diff --git a/app/views/registrar/invoices/partials/_items.haml b/app/views/registrar/invoices/partials/_items.haml index 6ed5144a8..64fc71786 100644 --- a/app/views/registrar/invoices/partials/_items.haml +++ b/app/views/registrar/invoices/partials/_items.haml @@ -24,7 +24,7 @@ %td= currency(@invoice.sum_without_vat) %tr %th.no-border{colspan: 3} - %th= t('vat', vat_prc: (@invoice.vat_prc * 100).round) + %th= t('vat', rate: (@invoice.vat_rate * 100).round) %td= currency(@invoice.vat) %tr %th.no-border{colspan: 3} diff --git a/app/views/registrar/invoices/pdf.haml b/app/views/registrar/invoices/pdf.haml index 61b4e5789..6f92c4a8a 100644 --- a/app/views/registrar/invoices/pdf.haml +++ b/app/views/registrar/invoices/pdf.haml @@ -242,7 +242,7 @@ %td= "#{currency(@invoice.sum_without_vat)} #{@invoice.currency}" %tr %th.no-border{colspan: 3} - %th= t('vat', vat_prc: (@invoice.vat_prc * 100).round) + %th= t('vat', rate: (@invoice.vat_rate * 100).round) %td= "#{currency(@invoice.vat)} #{@invoice.currency}" %tr %th.no-border{colspan: 3} diff --git a/config/locales/en.yml b/config/locales/en.yml index 4951f3b26..58c4e4c69 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -553,7 +553,7 @@ en: invoice_number: Invoice no. seller: 'Seller' prepayment: 'Prepayment' - vat: 'VAT (%{vat_prc}%)' + vat: 'VAT (%{rate}%)' unpaid: 'Unpaid' your_current_account_balance_is: 'Your current account balance is %{balance} %{currency}' billing: 'Billing' diff --git a/db/migrate/20180228064342_rename_invoices_var_prc_to_vat_rate.rb b/db/migrate/20180228064342_rename_invoices_var_prc_to_vat_rate.rb new file mode 100644 index 000000000..b1d13de1d --- /dev/null +++ b/db/migrate/20180228064342_rename_invoices_var_prc_to_vat_rate.rb @@ -0,0 +1,5 @@ +class RenameInvoicesVarPrcToVatRate < ActiveRecord::Migration + def change + rename_column :invoices, :vat_prc, :vat_rate + end +end diff --git a/db/structure.sql b/db/structure.sql index 722aa4111..cb47a50c0 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1127,7 +1127,7 @@ CREATE TABLE invoices ( currency character varying NOT NULL, description character varying, reference_no character varying, - vat_prc numeric(10,2) NOT NULL, + vat_rate numeric(10,2) NOT NULL, paid_at timestamp without time zone, seller_id integer, seller_name character varying NOT NULL, @@ -5115,3 +5115,5 @@ INSERT INTO schema_migrations (version) VALUES ('20180218004148'); INSERT INTO schema_migrations (version) VALUES ('20180228055259'); +INSERT INTO schema_migrations (version) VALUES ('20180228064342'); + diff --git a/doc/models_complete.svg b/doc/models_complete.svg index 148b12942..12fb078a4 100644 --- a/doc/models_complete.svg +++ b/doc/models_complete.svg @@ -1687,7 +1687,7 @@ currency :string description :string reference_no :string -vat_prc :decimal +vat_rate :decimal paid_at :datetime seller_id :integer seller_name :string diff --git a/spec/factories/invoice.rb b/spec/factories/invoice.rb index 7eeed32b9..0ea81d5e4 100644 --- a/spec/factories/invoice.rb +++ b/spec/factories/invoice.rb @@ -8,7 +8,7 @@ FactoryBot.define do seller_name { 'EIS' } seller_city { 'Tallinn' } seller_street { 'Paldiski mnt. 123' } - vat_prc 0.2 + vat_rate 0.2 buyer { FactoryBot.create(:registrar) } after :build do |invoice| diff --git a/spec/models/invoice_spec.rb b/spec/models/invoice_spec.rb index 49d15310f..eb8866d07 100644 --- a/spec/models/invoice_spec.rb +++ b/spec/models/invoice_spec.rb @@ -54,7 +54,7 @@ describe Invoice do it 'should calculate sums correctly' do @invoice = create(:invoice) - @invoice.vat_prc.should == BigDecimal.new('0.2') + @invoice.vat_rate.should == BigDecimal.new('0.2') @invoice.sum_without_vat.should == BigDecimal.new('300.0') @invoice.vat.should == BigDecimal.new('60.0') @invoice.sum.should == BigDecimal.new('360.0') diff --git a/test/fixtures/invoices.yml b/test/fixtures/invoices.yml index 7a1c85dd1..04cedc153 100644 --- a/test/fixtures/invoices.yml +++ b/test/fixtures/invoices.yml @@ -6,7 +6,7 @@ DEFAULTS: &DEFAULTS seller_name: John Doe seller_iban: 1234 buyer_name: Jane Doe - vat_prc: 0.2 + vat_rate: 0.2 valid: <<: *DEFAULTS diff --git a/test/models/invoice_test.rb b/test/models/invoice_test.rb new file mode 100644 index 000000000..c89c37626 --- /dev/null +++ b/test/models/invoice_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class InvoiceTest < ActiveSupport::TestCase + def test_invalid_without_vat_rate + invoice = Invoice.new(vat_rate: nil) + invoice.validate + assert invoice.errors.added?(:vat_rate, :blank) + end +end