polish_invoicer 0.0.26 → 0.0.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +37 -0
- data/.rubocop.yml +7 -5
- data/.rubocop_todo.yml +66 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/README.md +1 -1
- data/Rakefile +2 -0
- data/doc/invoice.rb +2 -0
- data/doc/proforma.rb +2 -0
- data/lib/polish_invoicer/invoice.rb +10 -6
- data/lib/polish_invoicer/presenter.rb +5 -1
- data/lib/polish_invoicer/validator.rb +21 -11
- data/lib/polish_invoicer/vat.rb +4 -0
- data/lib/polish_invoicer/version.rb +3 -1
- data/lib/polish_invoicer/writer.rb +3 -2
- data/lib/polish_invoicer.rb +2 -0
- data/polish_invoicer.gemspec +10 -5
- data/test/invoice_test.rb +59 -10
- data/test/presenter_test.rb +11 -1
- data/test/test_generator.rb +2 -0
- data/test/test_helper.rb +5 -2
- data/test/validator_test.rb +20 -1
- data/test/vat_test.rb +3 -1
- data/test/writer_test.rb +7 -2
- data/tpl/invoice-es.slim +117 -0
- data/tpl/proforma-es.slim +104 -0
- metadata +42 -16
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fccdb341dfc3705a7bdc55fee93853caacd6f887a32bc19f8f889927c6eca4c6
|
4
|
+
data.tar.gz: e60c0759877ddb7bdf78d3de1f775ba0a3e1d135ecd1aaa041878ac7876f92c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f299544cdbda41f4e2dc3fcfd426d347236cdd2457d974dad75f6a59ebc9894a37ee254a54e8a045104dbed2407d4c8ebcfdbbd2e0e624ad7bc787f2233a17d9
|
7
|
+
data.tar.gz: b400adae2678fcdd0268d854b6eb9c31d6fb9690c023f8bfd96defbdd6996074c930c2238adfb1aac11a7f27609e60c2e0439309851dd0dd5f32d5782a041322
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ "master" ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ "master" ]
|
15
|
+
|
16
|
+
permissions:
|
17
|
+
contents: read
|
18
|
+
|
19
|
+
jobs:
|
20
|
+
test:
|
21
|
+
|
22
|
+
runs-on: ubuntu-22.04
|
23
|
+
strategy:
|
24
|
+
matrix:
|
25
|
+
ruby-version: ['3.0', '3.1', '3.2']
|
26
|
+
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v4
|
29
|
+
- name: Set up Ruby
|
30
|
+
uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Run tests
|
35
|
+
run: bundle exec rake
|
36
|
+
- name: Run linter
|
37
|
+
run: bundle exec rubocop
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2023-10-24 20:10:00 UTC using RuboCop version 1.57.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 7
|
10
|
+
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
|
11
|
+
# SupportedStyles: Gemfile, gems.rb, gemspec
|
12
|
+
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
|
13
|
+
Gemspec/DevelopmentDependencies:
|
14
|
+
Exclude:
|
15
|
+
- 'polish_invoicer.gemspec'
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
# Configuration parameters: Severity, Include.
|
19
|
+
# Include: **/*.gemspec
|
20
|
+
Gemspec/RequiredRubyVersion:
|
21
|
+
Exclude:
|
22
|
+
- 'polish_invoicer.gemspec'
|
23
|
+
|
24
|
+
# Offense count: 1
|
25
|
+
# This cop supports safe autocorrection (--autocorrect).
|
26
|
+
# Configuration parameters: AllowForAlignment.
|
27
|
+
Layout/CommentIndentation:
|
28
|
+
Exclude:
|
29
|
+
- 'lib/polish_invoicer/invoice.rb'
|
30
|
+
|
31
|
+
# Offense count: 12
|
32
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
33
|
+
Metrics/AbcSize:
|
34
|
+
Max: 32
|
35
|
+
|
36
|
+
# Offense count: 4
|
37
|
+
# Configuration parameters: CountComments, CountAsOne.
|
38
|
+
Metrics/ClassLength:
|
39
|
+
Max: 196
|
40
|
+
|
41
|
+
# Offense count: 14
|
42
|
+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
43
|
+
Metrics/MethodLength:
|
44
|
+
Max: 20
|
45
|
+
|
46
|
+
# Offense count: 11
|
47
|
+
Minitest/MultipleAssertions:
|
48
|
+
Max: 12
|
49
|
+
|
50
|
+
# Offense count: 5
|
51
|
+
# Configuration parameters: AllowedConstants.
|
52
|
+
Style/Documentation:
|
53
|
+
Exclude:
|
54
|
+
- 'spec/**/*'
|
55
|
+
- 'test/**/*'
|
56
|
+
- 'lib/polish_invoicer/invoice.rb'
|
57
|
+
- 'lib/polish_invoicer/presenter.rb'
|
58
|
+
- 'lib/polish_invoicer/validator.rb'
|
59
|
+
- 'lib/polish_invoicer/vat.rb'
|
60
|
+
- 'lib/polish_invoicer/writer.rb'
|
61
|
+
|
62
|
+
# Offense count: 2
|
63
|
+
Style/OpenStructUse:
|
64
|
+
Exclude:
|
65
|
+
- 'test/presenter_test.rb'
|
66
|
+
- 'test/validator_test.rb'
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# PolishInvoicer [![Code Climate](https://codeclimate.com/github/macuk/polish_invoicer.png)](https://codeclimate.com/github/macuk/polish_invoicer)
|
1
|
+
# PolishInvoicer [![Code Climate](https://codeclimate.com/github/macuk/polish_invoicer.png)](https://codeclimate.com/github/macuk/polish_invoicer)
|
2
2
|
|
3
3
|
PolishInvoicer gem creates Polish invoices and proforms in HTML and PDF formats.
|
4
4
|
|
data/Rakefile
CHANGED
data/doc/invoice.rb
CHANGED
data/doc/proforma.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PolishInvoicer
|
2
4
|
class Invoice
|
3
5
|
AVAILABLE_PARAMS = [
|
@@ -26,20 +28,19 @@ module PolishInvoicer
|
|
26
28
|
:lang, # język na fakturze, domyślnie: zależny od ustawienia foreign_buyer
|
27
29
|
# foreign_buyer = false => lang = 'pl'
|
28
30
|
# foreign_buyer = true => lang = 'pl_en'
|
29
|
-
# możliwe wartości: pl | pl_en | en
|
31
|
+
# możliwe wartości: pl | pl_en | en | es
|
30
32
|
:reverse_charge, # faktura z odwrotnym obciążeniem VAT
|
31
33
|
:currency, # waluta rozliczeniowa, domyślnie: PLN (string)
|
32
34
|
:exchange_rate # kurs waluty rozliczeniowej, domyślnie: 1.0000 (float)
|
33
35
|
].freeze
|
34
36
|
|
35
|
-
attr_accessor(*AVAILABLE_PARAMS)
|
36
|
-
attr_accessor :template_path
|
37
|
-
attr_accessor :logger, :wkhtmltopdf_path, :wkhtmltopdf_command
|
37
|
+
attr_accessor(*AVAILABLE_PARAMS, :template_path, :logger, :wkhtmltopdf_path, :wkhtmltopdf_command)
|
38
38
|
|
39
39
|
def initialize(params = {})
|
40
40
|
set_defaults
|
41
41
|
params.each do |k, v|
|
42
42
|
raise "Nierozpoznany parametr #{k}" unless AVAILABLE_PARAMS.include?(k)
|
43
|
+
|
43
44
|
send("#{k}=", v)
|
44
45
|
end
|
45
46
|
@validator = PolishInvoicer::Validator.new(self)
|
@@ -56,7 +57,8 @@ module PolishInvoicer
|
|
56
57
|
# cena/wartość netto
|
57
58
|
def net_value
|
58
59
|
return price unless gross_price
|
59
|
-
|
60
|
+
|
61
|
+
price / (1 + (Vat.to_i(vat) / 100.0))
|
60
62
|
end
|
61
63
|
|
62
64
|
# kwota VAT
|
@@ -67,7 +69,8 @@ module PolishInvoicer
|
|
67
69
|
# cena/wartość brutto
|
68
70
|
def gross_value
|
69
71
|
return price if gross_price
|
70
|
-
|
72
|
+
|
73
|
+
price + (price * Vat.to_i(vat) / 100.0)
|
71
74
|
end
|
72
75
|
|
73
76
|
def save_to_html(path)
|
@@ -126,6 +129,7 @@ module PolishInvoicer
|
|
126
129
|
|
127
130
|
def validate!
|
128
131
|
return if valid?
|
132
|
+
|
129
133
|
error_messages = errors.map { |k, v| "#{k}: #{v}" }.join(', ')
|
130
134
|
raise "Parametry do wystawienia faktury są nieprawidłowe: #{error_messages}"
|
131
135
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PolishInvoicer
|
2
4
|
class Presenter
|
3
5
|
attr_accessor :invoice
|
@@ -40,6 +42,7 @@ module PolishInvoicer
|
|
40
42
|
%w[trade_date create_date payment_date].each do |field|
|
41
43
|
v = @invoice.send(field)
|
42
44
|
next unless v
|
45
|
+
|
43
46
|
@out[field.to_sym] = v.strftime '%d.%m.%Y'
|
44
47
|
end
|
45
48
|
end
|
@@ -48,7 +51,8 @@ module PolishInvoicer
|
|
48
51
|
%w[net_value vat_value gross_value exchanged_tax total_to_pay_value paid_value to_pay_value].each do |field|
|
49
52
|
v = @invoice.send(field)
|
50
53
|
next unless v
|
51
|
-
|
54
|
+
|
55
|
+
@out[field.to_sym] = format('%02.2f', v).tr('.', ',')
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PolishInvoicer
|
2
4
|
class Validator
|
3
5
|
attr_reader :errors
|
@@ -41,7 +43,10 @@ module PolishInvoicer
|
|
41
43
|
end
|
42
44
|
|
43
45
|
def check_not_nil
|
44
|
-
|
46
|
+
if @invoice.gross_price.nil?
|
47
|
+
@errors[:gross_price] =
|
48
|
+
'Konieczne jest ustawienie znacznika rodzaju ceny (netto/brutto)'
|
49
|
+
end
|
45
50
|
@errors[:paid] = 'Konieczne jest ustawienie znacznika opłacenia faktury' if @invoice.paid.nil?
|
46
51
|
@errors[:currency] = 'Konieczne jest ustawienie waluty rozliczeniowej' if @invoice.currency.nil?
|
47
52
|
@errors[:exchange_rate] = 'Konieczne jest podanie kursu waluty rozliczeniowej' if @invoice.exchange_rate.nil?
|
@@ -56,18 +61,17 @@ module PolishInvoicer
|
|
56
61
|
unless [true, false].include?(@invoice.gross_price)
|
57
62
|
@errors[:gross_price] = 'Znacznik rodzaju ceny musi być podany jako boolean'
|
58
63
|
end
|
59
|
-
unless [true,
|
60
|
-
|
61
|
-
end
|
64
|
+
@errors[:paid] = 'Znacznik opłacenia faktury musi być podany jako boolean' unless [true,
|
65
|
+
false].include?(@invoice.paid)
|
62
66
|
unless [true, false].include?(@invoice.proforma)
|
63
67
|
@errors[:proforma] = 'Znacznik faktury pro-forma musi być podany jako boolean'
|
64
68
|
end
|
65
69
|
unless [true, false].include?(@invoice.foreign_buyer)
|
66
70
|
@errors[:foreign_buyer] = 'Znacznik zagranicznego nabywcy musi być podany jako boolean'
|
67
71
|
end
|
68
|
-
|
69
|
-
|
70
|
-
|
72
|
+
return if [true, false].include?(@invoice.reverse_charge)
|
73
|
+
|
74
|
+
@errors[:reverse_charge] = 'Znacznik odwrotnego obciążenia VAT musi być podany jako boolean'
|
71
75
|
end
|
72
76
|
|
73
77
|
def check_dates
|
@@ -78,7 +82,7 @@ module PolishInvoicer
|
|
78
82
|
|
79
83
|
def check_price
|
80
84
|
if @invoice.price.is_a?(Numeric)
|
81
|
-
@errors[:price] = 'Cena musi być liczbą dodatnią' unless @invoice.price
|
85
|
+
@errors[:price] = 'Cena musi być liczbą dodatnią' unless @invoice.price.positive?
|
82
86
|
else
|
83
87
|
@errors[:price] = 'Cena musi być liczbą'
|
84
88
|
end
|
@@ -90,7 +94,10 @@ module PolishInvoicer
|
|
90
94
|
|
91
95
|
if @invoice.price_paid.is_a?(Numeric)
|
92
96
|
@errors[:price_paid] = 'Kwota zapłacona musi być liczbą dodatnią' unless @invoice.price_paid >= 0
|
93
|
-
|
97
|
+
unless @invoice.price_paid <= @invoice.price
|
98
|
+
@errors[:price_paid] =
|
99
|
+
'Kwota zapłacona musi być mniejsza lub równa cenie'
|
100
|
+
end
|
94
101
|
else
|
95
102
|
@errors[:price_paid] = 'Kwota zapłacona musi być liczbą'
|
96
103
|
end
|
@@ -109,6 +116,7 @@ module PolishInvoicer
|
|
109
116
|
def check_proforma
|
110
117
|
return unless @invoice.proforma
|
111
118
|
return unless @invoice.paid
|
119
|
+
|
112
120
|
@errors[:paid] = 'Proforma nie może być opłacona'
|
113
121
|
end
|
114
122
|
|
@@ -116,18 +124,20 @@ module PolishInvoicer
|
|
116
124
|
return if @errors[:create_date]
|
117
125
|
return if @errors[:payment_date]
|
118
126
|
return if @invoice.create_date <= @invoice.payment_date
|
127
|
+
|
119
128
|
@errors[:payment_date] = 'Termin płatności nie może być wcześniejszy niż data wystawienia'
|
120
129
|
end
|
121
130
|
|
122
131
|
def check_currency
|
123
132
|
return if @errors[:currency]
|
124
|
-
return if %w[PLN EUR USD GBP].include?(@invoice.currency)
|
133
|
+
return if %w[PLN EUR USD GBP CHF CZK].include?(@invoice.currency)
|
134
|
+
|
125
135
|
@errors[:currency] = 'Nieznana waluta'
|
126
136
|
end
|
127
137
|
|
128
138
|
def check_lang
|
129
139
|
return if blank?(@invoice.lang)
|
130
|
-
return if %w[pl pl_en en].include?(@invoice.lang)
|
140
|
+
return if %w[pl pl_en en es].include?(@invoice.lang)
|
131
141
|
|
132
142
|
@errors[:lang] = 'Nieznany język'
|
133
143
|
end
|
data/lib/polish_invoicer/vat.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PolishInvoicer
|
2
4
|
class Vat
|
3
5
|
def self.rates
|
@@ -6,6 +8,7 @@ module PolishInvoicer
|
|
6
8
|
|
7
9
|
def self.valid?(rate)
|
8
10
|
return true if zw?(rate)
|
11
|
+
|
9
12
|
rates.include?(rate)
|
10
13
|
end
|
11
14
|
|
@@ -16,6 +19,7 @@ module PolishInvoicer
|
|
16
19
|
|
17
20
|
def self.to_s(rate)
|
18
21
|
return 'zw.' if zw?(rate)
|
22
|
+
|
19
23
|
"#{rate}%"
|
20
24
|
end
|
21
25
|
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PolishInvoicer
|
2
4
|
class Writer
|
3
|
-
attr_accessor :invoice
|
4
|
-
attr_accessor :logger, :wkhtmltopdf_path, :wkhtmltopdf_command
|
5
|
+
attr_accessor :invoice, :logger, :wkhtmltopdf_path, :wkhtmltopdf_command
|
5
6
|
|
6
7
|
def initialize(invoice)
|
7
8
|
@invoice = invoice
|
data/lib/polish_invoicer.rb
CHANGED
data/polish_invoicer.gemspec
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'English'
|
4
|
+
lib = File.expand_path('lib', __dir__)
|
2
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
6
|
require 'polish_invoicer/version'
|
4
7
|
|
@@ -12,16 +15,18 @@ Gem::Specification.new do |spec|
|
|
12
15
|
spec.homepage = ''
|
13
16
|
spec.license = 'MIT'
|
14
17
|
|
15
|
-
spec.files = `git ls-files`.split(
|
18
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
16
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
20
|
spec.require_paths = ['lib']
|
21
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
19
22
|
|
20
23
|
spec.add_development_dependency 'bundler'
|
21
|
-
spec.add_development_dependency 'rake'
|
22
24
|
spec.add_development_dependency 'minitest'
|
23
|
-
spec.add_development_dependency '
|
25
|
+
spec.add_development_dependency 'rake'
|
24
26
|
spec.add_development_dependency 'rubocop'
|
27
|
+
spec.add_development_dependency 'rubocop-minitest'
|
28
|
+
spec.add_development_dependency 'rubocop-rake'
|
29
|
+
spec.add_development_dependency 'simplecov'
|
25
30
|
|
26
31
|
spec.add_dependency 'slim2pdf'
|
27
32
|
end
|
data/test/invoice_test.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
module PolishInvoicer
|
4
6
|
class InvoiceTest < Minitest::Test
|
5
7
|
def test_init
|
6
8
|
i = Invoice.new
|
7
|
-
|
9
|
+
|
10
|
+
assert_kind_of Invoice, i
|
8
11
|
end
|
9
12
|
|
10
13
|
def test_set_available_param
|
11
14
|
i = Invoice.new(number: '1/2014')
|
15
|
+
|
12
16
|
assert_equal '1/2014', i.number
|
13
17
|
end
|
14
18
|
|
@@ -18,86 +22,111 @@ module PolishInvoicer
|
|
18
22
|
|
19
23
|
def test_validation_delegation
|
20
24
|
i = Invoice.new
|
21
|
-
|
25
|
+
|
26
|
+
refute_predicate i, :valid?
|
22
27
|
assert i.errors[:number]
|
23
28
|
i.number = '1/2014'
|
24
29
|
i.valid?
|
30
|
+
|
25
31
|
assert_nil i.errors[:number]
|
26
32
|
end
|
27
33
|
|
28
34
|
def test_net_value
|
29
35
|
i = Invoice.new(price: 123.45, gross_price: false)
|
30
36
|
i.vat = 23
|
37
|
+
|
31
38
|
assert_in_delta 123.45, i.net_value, 0.01
|
32
39
|
|
33
40
|
i.gross_price = true
|
34
41
|
i.vat = 23
|
42
|
+
|
35
43
|
assert_in_delta 100.37, i.net_value, 0.01
|
36
44
|
i.vat = 5.5
|
45
|
+
|
37
46
|
assert_in_delta 117.01, i.net_value, 0.01
|
38
47
|
i.vat = 0
|
48
|
+
|
39
49
|
assert_in_delta 123.45, i.net_value, 0.01
|
40
50
|
i.vat = -1
|
51
|
+
|
41
52
|
assert_in_delta 123.45, i.net_value, 0.01
|
42
53
|
|
43
54
|
i.gross_price = false
|
44
55
|
i.vat = 0
|
56
|
+
|
45
57
|
assert_in_delta 123.45, i.net_value, 0.01
|
46
58
|
i.vat = -1
|
59
|
+
|
47
60
|
assert_in_delta 123.45, i.net_value, 0.01
|
48
61
|
i.vat = 5.5
|
62
|
+
|
49
63
|
assert_in_delta 123.45, i.net_value, 0.01
|
50
64
|
end
|
51
65
|
|
52
66
|
def test_vat_value
|
53
67
|
i = Invoice.new(price: 123.45, gross_price: false)
|
54
68
|
i.vat = 23
|
69
|
+
|
55
70
|
assert_in_delta 28.39, i.vat_value, 0.01
|
56
71
|
i.vat = 5.5
|
72
|
+
|
57
73
|
assert_in_delta 6.79, i.vat_value, 0.01
|
58
74
|
|
59
75
|
i.gross_price = true
|
60
76
|
i.vat = 23
|
77
|
+
|
61
78
|
assert_in_delta 23.08, i.vat_value, 0.01
|
62
79
|
i.vat = 5.5
|
80
|
+
|
63
81
|
assert_in_delta 6.44, i.vat_value, 0.01
|
64
82
|
i.vat = 0
|
65
|
-
|
83
|
+
|
84
|
+
assert_in_delta(0.00, i.vat_value)
|
66
85
|
i.vat = -1
|
67
|
-
|
86
|
+
|
87
|
+
assert_in_delta(0.00, i.vat_value)
|
68
88
|
end
|
69
89
|
|
70
90
|
def test_gross_value
|
71
91
|
i = Invoice.new(price: 123.45, gross_price: false)
|
72
92
|
i.vat = 23
|
93
|
+
|
73
94
|
assert_in_delta 151.84, i.gross_value, 0.01
|
74
95
|
|
75
96
|
i.gross_price = true
|
76
97
|
i.vat = 23
|
98
|
+
|
77
99
|
assert_in_delta 123.45, i.gross_value, 0.01
|
78
100
|
i.vat = 5.5
|
101
|
+
|
79
102
|
assert_in_delta 123.45, i.gross_value, 0.01
|
80
103
|
i.vat = 0
|
104
|
+
|
81
105
|
assert_in_delta 123.45, i.gross_value, 0.01
|
82
106
|
i.vat = -1
|
107
|
+
|
83
108
|
assert_in_delta 123.45, i.gross_value, 0.01
|
84
109
|
|
85
110
|
i.gross_price = false
|
86
111
|
i.vat = 5.5
|
112
|
+
|
87
113
|
assert_in_delta 130.24, i.gross_value, 0.01
|
88
114
|
i.vat = 0
|
115
|
+
|
89
116
|
assert_in_delta 123.45, i.gross_value, 0.01
|
90
117
|
i.vat = -1
|
118
|
+
|
91
119
|
assert_in_delta 123.45, i.gross_value, 0.01
|
92
120
|
end
|
93
121
|
|
94
122
|
def test_defaults
|
95
123
|
i = Invoice.new
|
124
|
+
|
96
125
|
assert i.gross_price
|
97
|
-
|
98
|
-
|
126
|
+
assert_equal 23, i.vat
|
127
|
+
assert_equal 'Przelew', i.payment_type
|
99
128
|
assert i.paid
|
100
|
-
|
129
|
+
refute i.proforma
|
101
130
|
end
|
102
131
|
|
103
132
|
def test_raise_when_save_to_html_and_not_valid
|
@@ -114,7 +143,8 @@ module PolishInvoicer
|
|
114
143
|
i = create_valid_invoice
|
115
144
|
path = '/tmp/test.html'
|
116
145
|
i.save_to_html(path)
|
117
|
-
|
146
|
+
|
147
|
+
assert_path_exists path
|
118
148
|
File.unlink(path)
|
119
149
|
end
|
120
150
|
|
@@ -122,15 +152,17 @@ module PolishInvoicer
|
|
122
152
|
i = create_valid_invoice
|
123
153
|
path = '/tmp/test.pdf'
|
124
154
|
i.save_to_pdf(path)
|
125
|
-
|
155
|
+
|
156
|
+
assert_path_exists path
|
126
157
|
File.unlink(path)
|
127
158
|
end
|
128
159
|
|
129
160
|
def test_to_hash
|
130
161
|
i = Invoice.new(price: 123.45, gross_price: false)
|
131
162
|
h = i.to_hash
|
163
|
+
|
132
164
|
assert h[:paid] # default
|
133
|
-
|
165
|
+
refute h[:gross_price] # params
|
134
166
|
assert_equal '123,45', h[:net_value] # presenter
|
135
167
|
end
|
136
168
|
|
@@ -159,6 +191,7 @@ module PolishInvoicer
|
|
159
191
|
|
160
192
|
def test_gross_and_net_price
|
161
193
|
gross_invoice = Invoice.new(price: 123, price_paid: 60, paid: false)
|
194
|
+
|
162
195
|
assert_equal 100, gross_invoice.net_value
|
163
196
|
assert_equal 23, gross_invoice.vat_value
|
164
197
|
assert_equal 123, gross_invoice.gross_value
|
@@ -167,6 +200,7 @@ module PolishInvoicer
|
|
167
200
|
assert_equal 63, gross_invoice.to_pay_value
|
168
201
|
|
169
202
|
net_invoice = Invoice.new(price: 100, price_paid: 60, paid: false, gross_price: false)
|
203
|
+
|
170
204
|
assert_equal 100, net_invoice.net_value
|
171
205
|
assert_equal 23, net_invoice.vat_value
|
172
206
|
assert_equal 123, net_invoice.gross_value
|
@@ -177,6 +211,7 @@ module PolishInvoicer
|
|
177
211
|
|
178
212
|
def test_reverse_charge
|
179
213
|
gross_invoice = Invoice.new(price: 123, price_paid: 60, paid: false, reverse_charge: true)
|
214
|
+
|
180
215
|
assert_equal 100, gross_invoice.net_value
|
181
216
|
assert_equal 23, gross_invoice.vat_value
|
182
217
|
assert_equal 123, gross_invoice.gross_value
|
@@ -185,6 +220,7 @@ module PolishInvoicer
|
|
185
220
|
assert_equal 40, gross_invoice.to_pay_value
|
186
221
|
|
187
222
|
net_invoice = Invoice.new(price: 100, price_paid: 60, paid: false, gross_price: false, reverse_charge: true)
|
223
|
+
|
188
224
|
assert_equal 100, net_invoice.net_value
|
189
225
|
assert_equal 23, net_invoice.vat_value
|
190
226
|
assert_equal 123, net_invoice.gross_value
|
@@ -195,34 +231,47 @@ module PolishInvoicer
|
|
195
231
|
|
196
232
|
def test_template_lang
|
197
233
|
i = Invoice.new
|
234
|
+
|
198
235
|
assert_equal 'pl', i.template_lang
|
199
236
|
i.foreign_buyer = true
|
237
|
+
|
200
238
|
assert_equal 'pl_en', i.template_lang
|
201
239
|
i.lang = 'en'
|
240
|
+
|
202
241
|
assert_equal 'en', i.template_lang
|
203
242
|
end
|
204
243
|
|
205
244
|
def test_template_file
|
206
245
|
i = Invoice.new(proforma: true)
|
246
|
+
|
207
247
|
assert_equal 'proforma-pl.slim', i.template_file
|
208
248
|
i.foreign_buyer = true
|
249
|
+
|
209
250
|
assert_equal 'proforma-pl_en.slim', i.template_file
|
210
251
|
i.lang = 'en'
|
252
|
+
|
211
253
|
assert_equal 'proforma-en.slim', i.template_file
|
212
254
|
i.lang = 'pl'
|
255
|
+
|
213
256
|
assert_equal 'proforma-pl.slim', i.template_file
|
214
257
|
i.lang = 'pl_en'
|
258
|
+
|
215
259
|
assert_equal 'proforma-pl_en.slim', i.template_file
|
216
260
|
|
217
261
|
i = Invoice.new
|
262
|
+
|
218
263
|
assert_equal 'invoice-pl.slim', i.template_file
|
219
264
|
i.foreign_buyer = true
|
265
|
+
|
220
266
|
assert_equal 'invoice-pl_en.slim', i.template_file
|
221
267
|
i.lang = 'en'
|
268
|
+
|
222
269
|
assert_equal 'invoice-en.slim', i.template_file
|
223
270
|
i.lang = 'pl'
|
271
|
+
|
224
272
|
assert_equal 'invoice-pl.slim', i.template_file
|
225
273
|
i.lang = 'pl_en'
|
274
|
+
|
226
275
|
assert_equal 'invoice-pl_en.slim', i.template_file
|
227
276
|
end
|
228
277
|
end
|