moss_generator 0.5.2 → 0.7.2

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: 7f95b7ed0d7074f3ca87040394af09e0ba85bdd2f68eb70dcec3166027c2b204
4
- data.tar.gz: 8f333d25b73c6c3b03941bd15e7dd0ee8b96d35f0ad7469c99e8ca2512bfa142
3
+ metadata.gz: 18f66da8ca3ff0ae647ab90347dae10811325e4b2c56b810f0a155a1358c2af9
4
+ data.tar.gz: d54f775dd2dfc9bf6882cc8a325fb910ac902ea16bd17b36a8015d76d89f70f7
5
5
  SHA512:
6
- metadata.gz: a2d2cdc21fa1fc84da5561cf73b506d79f25c034d3f12d68eea7b4e9bca20fb46a2c7a2709c6d7ad9dce49b717308dabfaf251f7fdb8f6e476750b026ac67eda
7
- data.tar.gz: ba490e2a77965cbf52957977482e85ba6011f2374fa9c223abb8f528311d56a4f677f6b6f6841fa1b2d83978698739d7c787ca072b619af00a324343c0ca3936
6
+ metadata.gz: bf9f763a8a42827fae9d132d81221e5abb30daac4ebef3352345e133e8e0d2f6363cc1f3b02dfb184f49c62d02f7b88a07276b51d372974958e6e307afdc140b
7
+ data.tar.gz: 7127be1ac16f0e1339f7b5067a10f11925b5325dda454242f1dac583557b66f3817656751e278def8ad3f478dd416f5dce4ab8a7eb698efa1f58ca5159db9e8c
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.2)
4
+ moss_generator (0.7.2)
5
5
  countries (~> 4.0)
6
6
  money (~> 6.14)
7
7
  valvat (~> 1.1)
@@ -18,27 +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.11)
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)
40
42
  racc (~> 1.4)
41
- nokogiri (1.12.5-x86_64-darwin)
43
+ nokogiri (1.13.6-x86_64-darwin)
42
44
  racc (~> 1.4)
43
45
  nori (2.6.0)
44
46
  parallel (1.20.1)
@@ -50,13 +52,13 @@ GEM
50
52
  pry-byebug (3.9.0)
51
53
  byebug (~> 11.0)
52
54
  pry (~> 0.13.0)
53
- public_suffix (4.0.6)
55
+ public_suffix (4.0.7)
54
56
  racc (1.6.0)
55
- rack (2.2.3)
57
+ rack (2.2.4)
56
58
  rainbow (3.0.0)
57
59
  rake (13.0.3)
58
60
  regexp_parser (2.0.3)
59
- rexml (3.2.4)
61
+ rexml (3.2.5)
60
62
  rspec (3.10.0)
61
63
  rspec-core (~> 3.10.0)
62
64
  rspec-expectations (~> 3.10.0)
@@ -98,12 +100,13 @@ GEM
98
100
  nokogiri (>= 1.8.1)
99
101
  nori (~> 2.4)
100
102
  wasabi (~> 3.4)
103
+ simple_po_parser (1.1.6)
101
104
  sixarm_ruby_unaccent (1.2.0)
102
105
  socksify (1.7.1)
103
106
  unicode-display_width (1.7.0)
104
- valvat (1.1.2)
107
+ valvat (1.1.4)
105
108
  savon (>= 2.3.0)
106
- wasabi (3.6.1)
109
+ wasabi (3.7.0)
107
110
  addressable
108
111
  httpi (~> 2.0)
109
112
  nokogiri (>= 1.4.2)
@@ -123,4 +126,4 @@ DEPENDENCIES
123
126
  rubocop-rspec (~> 2.1)
124
127
 
125
128
  BUNDLED WITH
126
- 2.2.3
129
+ 2.3.6
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.
@@ -170,7 +170,7 @@
170
170
  },
171
171
  "IE": {
172
172
  "country_name": "Ireland",
173
- "standard_rate": 21,
173
+ "standard_rate": 23,
174
174
  "reduced_rates": {
175
175
  "medical": 13.5,
176
176
  "newspapers": 9,
@@ -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
@@ -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.2'
4
+ VERSION = '0.7.2'
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.2
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - frdrkolsson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-04 00:00:00.000000000 Z
11
+ date: 2022-07-07 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.32
118
+ rubygems_version: 3.3.7
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: Skatteverket One Stop Shop (OSS) generator.