Rename invoices.var_prc to vat_rate

#623
This commit is contained in:
Artur Beljajev 2018-02-28 08:46:36 +02:00
parent f86ab085ac
commit 7dee10c683
13 changed files with 29 additions and 13 deletions

View file

@ -34,7 +34,7 @@ class Directo < ActiveRecord::Base
xml.line( xml.line(
"ProductID" => Setting.directo_receipt_product_name, "ProductID" => Setting.directo_receipt_product_name,
"Quantity" => 1, "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 "ProductName" => invoice.order
) )
} }

View file

@ -28,7 +28,7 @@ class Invoice < ActiveRecord::Base
validates :billing_email, email_format: { message: :invalid }, allow_blank: true validates :billing_email, email_format: { message: :invalid }, allow_blank: true
validates :invoice_type, :due_date, :currency, :seller_name, 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 before_create :set_invoice_number, :check_vat
@ -52,7 +52,7 @@ class Invoice < ActiveRecord::Base
def check_vat def check_vat
if buyer.country_code != 'EE' && buyer.vat_no.present? if buyer.country_code != 'EE' && buyer.vat_no.present?
self.vat_prc = 0 self.vat_rate = 0
end end
end end
@ -157,7 +157,7 @@ class Invoice < ActiveRecord::Base
end end
def vat def vat
(sum_without_vat * vat_prc).round(2) (sum_without_vat * vat_rate).round(2)
end end
def sum def sum

View file

@ -81,7 +81,7 @@ class Registrar < ActiveRecord::Base
payment_term: 'prepayment', payment_term: 'prepayment',
description: description, description: description,
currency: 'EUR', currency: 'EUR',
vat_prc: Setting.registry_vat_prc, vat_rate: Setting.registry_vat_prc,
seller_name: Setting.registry_juridical_name, seller_name: Setting.registry_juridical_name,
seller_reg_no: Setting.registry_reg_no, seller_reg_no: Setting.registry_reg_no,
seller_iban: Setting.registry_iban, seller_iban: Setting.registry_iban,

View file

@ -24,7 +24,7 @@
%td= currency(@invoice.sum_without_vat) %td= currency(@invoice.sum_without_vat)
%tr %tr
%th.no-border{colspan: 3} %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) %td= currency(@invoice.vat)
%tr %tr
%th.no-border{colspan: 3} %th.no-border{colspan: 3}

View file

@ -242,7 +242,7 @@
%td= "#{currency(@invoice.sum_without_vat)} #{@invoice.currency}" %td= "#{currency(@invoice.sum_without_vat)} #{@invoice.currency}"
%tr %tr
%th.no-border{colspan: 3} %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}" %td= "#{currency(@invoice.vat)} #{@invoice.currency}"
%tr %tr
%th.no-border{colspan: 3} %th.no-border{colspan: 3}

View file

@ -553,7 +553,7 @@ en:
invoice_number: Invoice no. invoice_number: Invoice no.
seller: 'Seller' seller: 'Seller'
prepayment: 'Prepayment' prepayment: 'Prepayment'
vat: 'VAT (%{vat_prc}%)' vat: 'VAT (%{rate}%)'
unpaid: 'Unpaid' unpaid: 'Unpaid'
your_current_account_balance_is: 'Your current account balance is %{balance} %{currency}' your_current_account_balance_is: 'Your current account balance is %{balance} %{currency}'
billing: 'Billing' billing: 'Billing'

View file

@ -0,0 +1,5 @@
class RenameInvoicesVarPrcToVatRate < ActiveRecord::Migration
def change
rename_column :invoices, :vat_prc, :vat_rate
end
end

View file

@ -1127,7 +1127,7 @@ CREATE TABLE invoices (
currency character varying NOT NULL, currency character varying NOT NULL,
description character varying, description character varying,
reference_no 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, paid_at timestamp without time zone,
seller_id integer, seller_id integer,
seller_name character varying NOT NULL, 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 ('20180228055259');
INSERT INTO schema_migrations (version) VALUES ('20180228064342');

View file

@ -1687,7 +1687,7 @@
<text text-anchor="start" x="121.5" y="-1481.3" font-family="Times,serif" font-size="14.00">currency :string</text> <text text-anchor="start" x="121.5" y="-1481.3" font-family="Times,serif" font-size="14.00">currency :string</text>
<text text-anchor="start" x="121.5" y="-1466.3" font-family="Times,serif" font-size="14.00">description :string</text> <text text-anchor="start" x="121.5" y="-1466.3" font-family="Times,serif" font-size="14.00">description :string</text>
<text text-anchor="start" x="121.5" y="-1451.3" font-family="Times,serif" font-size="14.00">reference_no :string</text> <text text-anchor="start" x="121.5" y="-1451.3" font-family="Times,serif" font-size="14.00">reference_no :string</text>
<text text-anchor="start" x="121.5" y="-1436.3" font-family="Times,serif" font-size="14.00">vat_prc :decimal</text> <text text-anchor="start" x="121.5" y="-1436.3" font-family="Times,serif" font-size="14.00">vat_rate :decimal</text>
<text text-anchor="start" x="121.5" y="-1421.3" font-family="Times,serif" font-size="14.00">paid_at :datetime</text> <text text-anchor="start" x="121.5" y="-1421.3" font-family="Times,serif" font-size="14.00">paid_at :datetime</text>
<text text-anchor="start" x="121.5" y="-1406.3" font-family="Times,serif" font-size="14.00">seller_id :integer</text> <text text-anchor="start" x="121.5" y="-1406.3" font-family="Times,serif" font-size="14.00">seller_id :integer</text>
<text text-anchor="start" x="121.5" y="-1391.3" font-family="Times,serif" font-size="14.00">seller_name :string</text> <text text-anchor="start" x="121.5" y="-1391.3" font-family="Times,serif" font-size="14.00">seller_name :string</text>

Before

Width:  |  Height:  |  Size: 228 KiB

After

Width:  |  Height:  |  Size: 228 KiB

Before After
Before After

View file

@ -8,7 +8,7 @@ FactoryBot.define do
seller_name { 'EIS' } seller_name { 'EIS' }
seller_city { 'Tallinn' } seller_city { 'Tallinn' }
seller_street { 'Paldiski mnt. 123' } seller_street { 'Paldiski mnt. 123' }
vat_prc 0.2 vat_rate 0.2
buyer { FactoryBot.create(:registrar) } buyer { FactoryBot.create(:registrar) }
after :build do |invoice| after :build do |invoice|

View file

@ -54,7 +54,7 @@ describe Invoice do
it 'should calculate sums correctly' do it 'should calculate sums correctly' do
@invoice = create(:invoice) @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.sum_without_vat.should == BigDecimal.new('300.0')
@invoice.vat.should == BigDecimal.new('60.0') @invoice.vat.should == BigDecimal.new('60.0')
@invoice.sum.should == BigDecimal.new('360.0') @invoice.sum.should == BigDecimal.new('360.0')

View file

@ -6,7 +6,7 @@ DEFAULTS: &DEFAULTS
seller_name: John Doe seller_name: John Doe
seller_iban: 1234 seller_iban: 1234
buyer_name: Jane Doe buyer_name: Jane Doe
vat_prc: 0.2 vat_rate: 0.2
valid: valid:
<<: *DEFAULTS <<: *DEFAULTS

View file

@ -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