diff --git a/app/models/registrar.rb b/app/models/registrar.rb index dd7a7a9f5..487bc513a 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -99,7 +99,7 @@ class Registrar < ActiveRecord::Base # rubocop:disable Metrics/AbcSize def issue_prepayment_invoice(amount, description = nil) vat_rate = if local_vat_payer? - Setting.registry_vat_prc + Registry.instance.vat_rate else if vat_no.blank? self.vat_rate @@ -114,7 +114,6 @@ class Registrar < ActiveRecord::Base payment_term: 'prepayment', description: description, currency: 'EUR', - vat_rate: Setting.registry_vat_prc, vat_rate: vat_rate, seller_name: Setting.registry_juridical_name, seller_reg_no: Setting.registry_reg_no, diff --git a/app/models/registry.rb b/app/models/registry.rb new file mode 100644 index 000000000..162ab4d71 --- /dev/null +++ b/app/models/registry.rb @@ -0,0 +1,11 @@ +class Registry + include Singleton + + def vat_rate + Setting.registry_vat_prc + end + + def legal_address_country + Country.new(Setting.registry_country_code) + end +end diff --git a/config/application.rb b/config/application.rb index 57106c8ea..04d697f55 100644 --- a/config/application.rb +++ b/config/application.rb @@ -15,7 +15,7 @@ require 'rails/all' # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) -module Registry +module DomainNameRegistry class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers diff --git a/test/models/registry_test.rb b/test/models/registry_test.rb new file mode 100644 index 000000000..2f25686c6 --- /dev/null +++ b/test/models/registry_test.rb @@ -0,0 +1,16 @@ +require 'test_helper' + +class RegistryTest < ActiveSupport::TestCase + def setup + @registry = Registry.send(:new) + end + + def test_implements_singleton + assert_equal Registry.instance.object_id, Registry.instance.object_id + end + + def test_vat_rate + Setting.registry_vat_prc = 0.2 + assert 0.2, @registry.vat_rate + end +end