moss_generator 0.5.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19a3aed8d3c19657e6aece4428a384803ff7121622ac25b1c9933c599b63bb36
4
- data.tar.gz: 704bb07f3da892945cdcd224bf87df9cfd907c3d2ae02069e0a73582fc4e524b
3
+ metadata.gz: d76e193b26e8d61b718f567d7416a7a06b63d1869a8b4f8734093aee72120ca5
4
+ data.tar.gz: 47ce0bc69d2cdf03c0c783c6fc2ca464b7da346597df81d074fcfda209bb2be5
5
5
  SHA512:
6
- metadata.gz: 94a32082eb92e052b12e7c0b8402ebf669581c95598e78e445aca20d1a76726f5917d33ad544431fc44512ca3d3247ab82772789c1b3036ab40a9dc8329cc905
7
- data.tar.gz: 7e3bed7e7ac91a4c46500d60a3f65585076ce26f8c07b0a895a06fac7c2bfef71f9c8a60869bd4bbd1f331fe7ec4ea050f97fd4f9ccf4d7eb40b6e1ba5d2e2eb
6
+ metadata.gz: c6bb77da4514d7cfb3560f826160e5fa51bce80ec9f413b9d1334c70070e69e4c6da7eba70e5e5bf73a8a4db0ee558072d6041c5d323677db14678b248b7423b
7
+ data.tar.gz: 0ff1ae9664e557fd06897730c1cfae4dce0ffbb99dece76e4464678b11428fc492709ff5b3333ee20875eca31aff68c778843d4bcc3032d58f6c753a8d68247a
data/.rubocop.yml CHANGED
@@ -10,6 +10,9 @@ AllCops:
10
10
  Layout/LineLength:
11
11
  Max: 80
12
12
 
13
+ Metrics/ClassLength:
14
+ Max: 120
15
+
13
16
  Metrics/ParameterLists:
14
17
  Max: 6
15
18
 
@@ -18,4 +21,4 @@ Metrics/BlockLength:
18
21
  - 'spec/**/*'
19
22
 
20
23
  RSpec/NestedGroups:
21
- Max: 5
24
+ Max: 6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- moss_generator (0.5.1)
4
+ moss_generator (0.7.0)
5
5
  countries (~> 4.0)
6
6
  money (~> 6.14)
7
7
  valvat (~> 1.1)
@@ -18,25 +18,29 @@ GEM
18
18
  builder (3.2.4)
19
19
  byebug (11.1.3)
20
20
  coderay (1.1.3)
21
- concurrent-ruby (1.1.9)
22
- countries (4.0.1)
23
- i18n_data (~> 0.13.0)
21
+ concurrent-ruby (1.1.10)
22
+ countries (4.2.3)
23
+ i18n_data (~> 0.16.0)
24
24
  sixarm_ruby_unaccent (~> 1.1)
25
25
  diff-lcs (1.4.4)
26
- gyoku (1.3.1)
26
+ gyoku (1.4.0)
27
27
  builder (>= 2.1.2)
28
+ rexml (~> 3.0)
28
29
  httpi (2.5.0)
29
30
  rack
30
31
  socksify
31
- i18n (1.8.10)
32
+ i18n (1.10.0)
32
33
  concurrent-ruby (~> 1.0)
33
- i18n_data (0.13.0)
34
+ i18n_data (0.16.0)
35
+ simple_po_parser (~> 1.1)
34
36
  method_source (1.0.0)
35
- mini_portile2 (2.6.1)
37
+ mini_portile2 (2.8.0)
36
38
  money (6.16.0)
37
39
  i18n (>= 0.6.4, <= 2)
38
- nokogiri (1.12.5)
39
- mini_portile2 (~> 2.6.1)
40
+ nokogiri (1.13.6)
41
+ mini_portile2 (~> 2.8.0)
42
+ racc (~> 1.4)
43
+ nokogiri (1.13.6-x86_64-darwin)
40
44
  racc (~> 1.4)
41
45
  nori (2.6.0)
42
46
  parallel (1.20.1)
@@ -48,9 +52,9 @@ GEM
48
52
  pry-byebug (3.9.0)
49
53
  byebug (~> 11.0)
50
54
  pry (~> 0.13.0)
51
- public_suffix (4.0.6)
55
+ public_suffix (4.0.7)
52
56
  racc (1.6.0)
53
- rack (2.2.3)
57
+ rack (2.2.3.1)
54
58
  rainbow (3.0.0)
55
59
  rake (13.0.3)
56
60
  regexp_parser (2.0.3)
@@ -96,12 +100,13 @@ GEM
96
100
  nokogiri (>= 1.8.1)
97
101
  nori (~> 2.4)
98
102
  wasabi (~> 3.4)
103
+ simple_po_parser (1.1.6)
99
104
  sixarm_ruby_unaccent (1.2.0)
100
105
  socksify (1.7.1)
101
106
  unicode-display_width (1.7.0)
102
- valvat (1.1.2)
107
+ valvat (1.1.4)
103
108
  savon (>= 2.3.0)
104
- wasabi (3.6.1)
109
+ wasabi (3.7.0)
105
110
  addressable
106
111
  httpi (~> 2.0)
107
112
  nokogiri (>= 1.4.2)
@@ -121,4 +126,4 @@ DEPENDENCIES
121
126
  rubocop-rspec (~> 2.1)
122
127
 
123
128
  BUNDLED WITH
124
- 2.2.3
129
+ 2.2.32
data/README.md CHANGED
@@ -48,6 +48,23 @@ Vat rates currently needs to be updated manually in `config/vat_rates.json`.
48
48
 
49
49
  Rates can also be found on the official website of the European Union [https://europa.eu/youreurope/business/taxation/vat/vat-rules-rates/index_en.htm#shortcut-8](https://europa.eu/youreurope/business/taxation/vat/vat-rules-rates/index_en.htm#shortcut-8), updates two times a year.
50
50
 
51
+ ### Custom VAT rates
52
+
53
+ If standard VAT rates is not enough a custom VAT service can be written and used instead. To create a VAT service that change VAT for a country with a standard VAT rates fallback this one could be used.
54
+
55
+ ```ruby
56
+ class CustomVat
57
+ # Insane 50.5% VAT for France
58
+ def for(country_code)
59
+ return 50.5 if country_code == 'FR'
60
+
61
+ MossGenerator::VatRate.for(country_code)
62
+ end
63
+ end
64
+
65
+ csv_string = MossGenerator::Stripe.call(charges, vat_number, period, year, rates, 'SERVICES', CustomVat.new)
66
+ ```
67
+
51
68
  ## Contributing
52
69
 
53
70
  Bug reports and pull requests are welcome on GitHub at https://github.com/standout/moss_generator.
@@ -8,23 +8,33 @@ module MossGenerator
8
8
  class Stripe
9
9
  class NoTurnoverCountryError < StandardError; end
10
10
 
11
- attr_reader :charges, :vat_number, :period, :year, :rates, :sale_type
12
-
13
- def initialize(charges, vat_number, period, year, rates, sale_type)
11
+ attr_reader :charges, :vat_number, :period, :year, :rates, :sale_type,
12
+ :vat_rate_service
13
+
14
+ # rubocop:disable Metrics/ParameterLists
15
+ def initialize(charges,
16
+ vat_number,
17
+ period,
18
+ year,
19
+ rates,
20
+ sale_type,
21
+ vat_rate_service = MossGenerator::VatRate)
14
22
  @charges = charges
15
23
  @vat_number = vat_number
16
24
  @period = period
17
25
  @year = year
18
26
  @rates = rates
19
27
  @sale_type = sale_type
28
+ @vat_rate_service = vat_rate_service
20
29
  end
30
+ # rubocop:enable Metrics/ParameterLists
21
31
 
22
- def self.call(charges, vat_number, period, year, rates, sale_type)
23
- new(charges, vat_number, period, year, rates, sale_type).call
32
+ def self.call(*args)
33
+ new(*args).call
24
34
  end
25
35
 
26
36
  def call
27
- CSV.generate(csv_options) do |csv|
37
+ CSV.generate(**csv_options) do |csv|
28
38
  csv << first_row
29
39
  csv << second_row
30
40
  generate_charges_rows(csv)
@@ -47,7 +57,8 @@ module MossGenerator
47
57
 
48
58
  def group_charges_rows
49
59
  charges_rows = charges.map do |charge|
50
- charge_row = MossGenerator::StripeChargeRow.new(charge, rates)
60
+ charge_row = MossGenerator::StripeChargeRow.new(charge, rates,
61
+ vat_rate_service)
51
62
  next if charge_row.skippable?
52
63
 
53
64
  charge_row
@@ -68,7 +79,7 @@ module MossGenerator
68
79
 
69
80
  def country_row(country, charges, vat)
70
81
  [turnover_country,
71
- country,
82
+ country_code(country),
72
83
  format_to_two_decimals(vat),
73
84
  format_to_two_decimals(charges.sum(&:amount_without_vat)),
74
85
  format_to_two_decimals(charges.sum(&:vat_amount)),
@@ -87,6 +98,12 @@ module MossGenerator
87
98
  ';'
88
99
  end
89
100
 
101
+ def country_code(country)
102
+ return 'EL' if country == 'GR'
103
+
104
+ country
105
+ end
106
+
90
107
  def format_to_two_decimals(number)
91
108
  format('%.2f', number).sub('.', ',')
92
109
  end
@@ -14,11 +14,12 @@ module MossGenerator
14
14
 
15
15
  class NoExchangeRateForCurrencyOrDateError < StandardError; end
16
16
 
17
- attr_reader :charge, :rates
17
+ attr_reader :charge, :rates, :vat_rate_service
18
18
 
19
- def initialize(charge, rates)
19
+ def initialize(charge, rates, vat_rate_service = MossGenerator::VatRate)
20
20
  @charge = charge
21
21
  @rates = rates
22
+ @vat_rate_service = vat_rate_service
22
23
  end
23
24
 
24
25
  def country_code
@@ -63,7 +64,7 @@ module MossGenerator
63
64
 
64
65
  21
65
66
  else
66
- MossGenerator::VatRate.for(country_code)
67
+ vat_rate_service.for(country_code)
67
68
  end
68
69
  end
69
70
 
@@ -98,7 +99,37 @@ module MossGenerator
98
99
  end
99
100
 
100
101
  def fetch_country_code
101
- charge.dig('payment_method_details', 'card', 'country')
102
+ source_country || payment_method_country || fallback_country
103
+ end
104
+
105
+ def source_country
106
+ return source_owner_country if source_type.nil?
107
+
108
+ charge.dig('source', source_type, 'country') ||
109
+ charge.dig('source', source_type, 'address_country')
110
+ end
111
+
112
+ def payment_method_country
113
+ return if payment_type.nil?
114
+
115
+ charge.dig('payment_method_details', payment_type, 'country') ||
116
+ charge.dig('payment_method_details', payment_type, 'address_country')
117
+ end
118
+
119
+ def source_type
120
+ charge.dig('source', 'type') || charge.dig('source', 'object')
121
+ end
122
+
123
+ def source_owner_country
124
+ charge.dig('source', 'owner', 'address', 'country')
125
+ end
126
+
127
+ def payment_type
128
+ charge.dig('payment_method_details', 'type')
129
+ end
130
+
131
+ def fallback_country
132
+ charge.dig('shipping', 'address', 'country')
102
133
  end
103
134
 
104
135
  def amount_with_vat
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MossGenerator
4
- VERSION = '0.5.1'
4
+ VERSION = '0.7.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moss_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - frdrkolsson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-03 00:00:00.000000000 Z
11
+ date: 2022-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: countries
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubygems_version: 3.2.22
118
+ rubygems_version: 3.3.7
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: Skatteverket One Stop Shop (OSS) generator.