solidus_brazilian_adaptations 1.0.3 → 1.0.5

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: 004dffeaecbe2d9575ec31ae699aae9e3faffaf3b87da4c452e4d72da531b5a7
4
- data.tar.gz: 578ec87ea251b6d6f3d4cce06ba432e8235e9a37f5e7050e66f2695073959da1
3
+ metadata.gz: abf9b101cad24f96d6b95af4b1c1587666d279a7ec9c38cd6eadf80588c2de3a
4
+ data.tar.gz: cea1c5c853b54b8b10dc962476b05fe04f2f9819155e14cf3e3c5931919c055e
5
5
  SHA512:
6
- metadata.gz: 78007a55b7cd0df20a3e29af7fef6f0c75702ba73881e07b2a56e0394a7152ec6dd8238b98351c14bbdc8ce6f12d03f463620795ad3201fb5316f509afa69511
7
- data.tar.gz: d4698a469fb2c16f642736302e42c34c28496597cd62eb3b754eee1305164a324700089270ef99193d836fd54518e5caa7c3cc6cb022c54e4248a62eb87c8d78
6
+ metadata.gz: df1c8d4801d1a4c440c86ecdf94954145053cbbfd42ca61b365b4f93c22b6c38f0868645b73a0456bd9d0a07abc7b9c3bfb9038ed9998e1502e4a76e8dff15a2
7
+ data.tar.gz: 48da079873137eddebd6b0e1fdaf62605cd11446abaacff3641493429943395b3f187c2337382dad2f9be5c3921e7c0011a365ceefe6319283eab60732e0e5dc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.0.3](https://github.com/ulysses-bull/solidus_brazilian_adaptations/tree/v1.0.3) (2023-09-19)
4
+
5
+ [Full Changelog](https://github.com/ulysses-bull/solidus_brazilian_adaptations/compare/v1.0.1.-t.1...v1.0.3)
6
+
3
7
  ## [v1.0.1.-t.1](https://github.com/ulysses-bull/solidus_brazilian_adaptations/tree/v1.0.1.-t.1) (2023-09-19)
4
8
 
5
9
  [Full Changelog](https://github.com/ulysses-bull/solidus_brazilian_adaptations/compare/e7afb9471571e91ab0d272436491ae190113f54d...v1.0.1.-t.1)
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- require 'solidus_dev_support/rake_tasks'
4
+ require "solidus_dev_support/rake_tasks"
5
5
  SolidusDevSupport::RakeTasks.install
6
6
 
7
- task default: 'extension:specs'
7
+ task default: "extension:specs"
@@ -12,23 +12,22 @@ module SolidusBrazilianAdaptations
12
12
  cnpj_allowed = SolidusBrazilianAdaptations.config.allow_cnpj
13
13
  document = TaxIdBr.new(tax_id)
14
14
  if document.valid?
15
- if document.document_type == :cnpj and cnpj_allowed == false
16
- self.errors.add(:base, "Insira um CPF, não um CNPJ.")
15
+ if document.document_type == :cnpj && cnpj_allowed == false
16
+ errors.add(:base, "Insira um CPF, não um CNPJ.")
17
17
  end
18
18
  else
19
- self.errors.add(:base, "#{cnpj_allowed ? "CPF/CPNJ" : "CPF"} inválido.")
19
+ errors.add(:base, "#{cnpj_allowed ? "CPF/CPNJ" : "CPF"} inválido.")
20
20
  end
21
21
  end
22
22
 
23
23
  def format_tax_id
24
- document = TaxIdBr.new(self.tax_id)
24
+ document = TaxIdBr.new(tax_id)
25
25
  self.tax_id = document.formatted
26
26
  end
27
-
28
27
  end
29
28
  end
30
29
 
31
30
  ::Spree::Order.prepend self
32
31
  end
33
32
  end
34
- end
33
+ end
@@ -1,5 +1,4 @@
1
1
  class TaxIdBr
2
-
3
2
  attr_reader :document_type, :formatted
4
3
  def initialize tax_id
5
4
  create_document tax_id
@@ -10,6 +9,7 @@ class TaxIdBr
10
9
  end
11
10
 
12
11
  private
12
+
13
13
  def create_document tax_id
14
14
  cpf = CPF.new(tax_id)
15
15
  cnpj = CNPJ.new(tax_id)
@@ -24,5 +24,4 @@ class TaxIdBr
24
24
  @valid = false
25
25
  end
26
26
  end
27
-
28
- end
27
+ end
data/db/seeds.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'thor'
2
+ shell = Thor::Base.shell.new
3
+
4
+ %w[
5
+ stores
6
+ store_credit
7
+ countries
8
+ return_reasons
9
+ states
10
+ stock_locations
11
+ refund_reasons
12
+ roles
13
+ shipping
14
+ payment
15
+ ].each do |seed|
16
+ shell.say_status :seed, seed
17
+ require_relative "spree_br/#{seed}"
18
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'carmen'
4
+
5
+ # Insert Countries into the spree_countries table, checking to ensure that no
6
+ # duplicates are created, using as few SQL statements as possible (2)
7
+
8
+ connection = Spree::Base.connection
9
+
10
+ country_mapper = ->(country) do
11
+ name = connection.quote country.name
12
+ iso3 = connection.quote country.alpha_3_code
13
+ iso = connection.quote country.alpha_2_code
14
+ iso_name = connection.quote country.name.upcase
15
+ numcode = connection.quote country.numeric_code
16
+ states_required = connection.quote country.subregions?
17
+
18
+ [name, iso3, iso, iso_name, numcode, states_required].join(", ")
19
+ end
20
+
21
+ country_values = -> do
22
+ carmen_countries = Carmen::Country.all
23
+
24
+ # find entires already in the database (so that we may ignore them)
25
+ existing_country_isos =
26
+ Spree::Country.where(iso: carmen_countries.map(&:alpha_2_code)).pluck(:iso)
27
+
28
+ # create VALUES statements for each country _not_ already in the database
29
+ carmen_countries
30
+ .reject { |c| existing_country_isos.include?(c.alpha_2_code) || c.alpha_2_code != 'BR' }
31
+ .map(&country_mapper)
32
+ .join("), (")
33
+ end
34
+
35
+ country_columns = %w(name iso3 iso iso_name numcode states_required).join(', ')
36
+ country_vals = country_values.call
37
+
38
+ if country_vals.present?
39
+ # execute raw SQL (insted of ActiveRecord.create) to use a single
40
+ # INSERT statement, and to avoid any validations or callbacks
41
+ connection.execute <<-SQL
42
+ INSERT INTO spree_countries (#{country_columns})
43
+ VALUES (#{country_vals});
44
+ SQL
45
+ end
@@ -0,0 +1,4 @@
1
+ Spree::PaymentMethod::Check.create!(
2
+ name: "Boleto",
3
+ available_to_users: true
4
+ )
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ Spree::RefundReason.find_or_create_by!(name: "Return processing", mutable: false)
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ Spree::ReturnReason.find_or_create_by(name: 'Better price available')
4
+ Spree::ReturnReason.find_or_create_by(name: 'Missed estimated delivery date')
5
+ Spree::ReturnReason.find_or_create_by(name: 'Missing parts or accessories')
6
+ Spree::ReturnReason.find_or_create_by(name: 'Damaged/Defective')
7
+ Spree::ReturnReason.find_or_create_by(name: 'Different from what was ordered')
8
+ Spree::ReturnReason.find_or_create_by(name: 'Different from description')
9
+ Spree::ReturnReason.find_or_create_by(name: 'No longer needed/wanted')
10
+ Spree::ReturnReason.find_or_create_by(name: 'Accidental order')
11
+ Spree::ReturnReason.find_or_create_by(name: 'Unauthorized purchase')
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ Spree::Role.where(name: "admin").first_or_create
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ category = Spree::ShippingCategory.find_or_create_by(name: "Default")
4
+ todo_brasil = Spree::Zone.find_or_create_by!(name: "todo_brasil", description: "Todo Brasil")
5
+ todo_brasil.zone_members.find_or_create_by!(zoneable: Spree::Country.find_by!(iso: "BR"))
6
+
7
+ Spree::ShippingMethod.create!(
8
+ name: "Coruja",
9
+ available_to_all: true,
10
+ code: "CRJ",
11
+ shipping_categories: [category],
12
+ calculator: Spree::Calculator::Shipping::FlatRate.create!(
13
+ preferred_amount: 20.0,
14
+ preferred_currency: "BRL"
15
+ ),
16
+ zones: [todo_brasil]
17
+ )
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ def create_states(subregions, country)
4
+ subregions.each do |subregion|
5
+ Spree::State.where(abbr: subregion.code, country: country).first_or_create!(
6
+ name: subregion.name
7
+ )
8
+ end
9
+ end
10
+
11
+ ActiveRecord::Base.transaction do
12
+ Spree::Country.all.find_each do |country|
13
+ carmen_country = Carmen::Country.coded(country.iso)
14
+ next unless carmen_country.subregions?
15
+
16
+ if Spree::Config[:countries_that_use_nested_subregions].include? country.iso
17
+ create_states(carmen_country.subregions.flat_map(&:subregions), country)
18
+ else
19
+ create_states(carmen_country.subregions, country)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ Spree::StockLocation.create_with(backorderable_default: true)
4
+ .find_or_create_by!(name: 'default')
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ Spree::PaymentMethod.create_with(
5
+ name: "Store Credit",
6
+ description: "Store credit",
7
+ active: true,
8
+ available_to_admin: false,
9
+ available_to_users: false
10
+ ).find_or_create_by!(
11
+ type: "Spree::PaymentMethod::StoreCredit"
12
+ )
13
+
14
+ Spree::StoreCreditType.create_with(priority: 1).find_or_create_by!(name: Spree::StoreCreditType::EXPIRING)
15
+ Spree::StoreCreditType.create_with(priority: 2).find_or_create_by!(name: Spree::StoreCreditType::NON_EXPIRING)
16
+
17
+ Spree::ReimbursementType.create_with(name: "Store Credit").find_or_create_by!(type: 'Spree::ReimbursementType::StoreCredit')
18
+ Spree::ReimbursementType.create_with(name: "Original").find_or_create_by!(type: 'Spree::ReimbursementType::OriginalPayment')
19
+
20
+ Spree::StoreCreditCategory.find_or_create_by!(name: Spree::StoreCreditCategory::GIFT_CARD)
21
+ Spree::StoreCreditCategory.find_or_create_by!(name: Spree::StoreCreditCategory::REIMBURSEMENT)
22
+
23
+ Spree::StoreCreditReason.find_or_create_by!(name: 'Credit Given In Error')
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ unless Spree::Store.where(code: 'sample-store').exists?
4
+ Spree::Store.create!(
5
+ name: "Sample Store",
6
+ code: "sample-store",
7
+ url: "example.com",
8
+ mail_from_address: "store@example.com"
9
+ )
10
+ end
@@ -14,16 +14,6 @@ module SolidusBrazilianAdaptations
14
14
  template 'initializer.rb', 'config/initializers/solidus_brazilian_adaptations.rb'
15
15
  end
16
16
 
17
- def add_javascripts
18
- append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_brazilian_adaptations\n"
19
- append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_brazilian_adaptations\n"
20
- end
21
-
22
- def add_stylesheets
23
- inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_brazilian_adaptations\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
24
- inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_brazilian_adaptations\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
25
- end
26
-
27
17
  def add_migrations
28
18
  run 'bin/rails railties:install:migrations FROM=solidus_brazilian_adaptations'
29
19
  end
@@ -10,7 +10,7 @@ module SolidusBrazilianAdaptations
10
10
  @configuration ||= Configuration.new
11
11
  end
12
12
 
13
- alias config configuration
13
+ alias_method :config, :configuration
14
14
 
15
15
  def configure
16
16
  yield configuration
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'solidus_core'
4
- require 'solidus_support'
3
+ require "solidus_core"
4
+ require "solidus_support"
5
5
 
6
6
  module SolidusBrazilianAdaptations
7
7
  class Engine < Rails::Engine
@@ -9,7 +9,7 @@ module SolidusBrazilianAdaptations
9
9
 
10
10
  isolate_namespace ::Spree
11
11
 
12
- engine_name 'solidus_brazilian_adaptations'
12
+ engine_name "solidus_brazilian_adaptations"
13
13
 
14
14
  ::Spree::PermittedAttributes.checkout_address_attributes.prepend :tax_id
15
15
  ::Spree::PermittedAttributes.address_attributes.prepend :number
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusBrazilianAdaptations
4
- VERSION = '1.0.3'
4
+ VERSION = "1.0.5"
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "cpf_cnpj"
4
- require 'solidus_brazilian_adaptations/configuration'
5
- require 'solidus_brazilian_adaptations/version'
6
- require 'solidus_brazilian_adaptations/engine'
4
+ require "solidus_brazilian_adaptations/configuration"
5
+ require "solidus_brazilian_adaptations/version"
6
+ require "solidus_brazilian_adaptations/engine"
@@ -1,36 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/solidus_brazilian_adaptations/version'
3
+ require_relative "lib/solidus_brazilian_adaptations/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = 'solidus_brazilian_adaptations'
6
+ spec.name = "solidus_brazilian_adaptations"
7
7
  spec.version = SolidusBrazilianAdaptations::VERSION
8
- spec.authors = ['ulysses-bull']
9
- spec.email = 'contato7bulloleo@gmail.com'
8
+ spec.authors = ["ulysses-bull"]
9
+ spec.email = "contato7bulloleo@gmail.com"
10
10
 
11
- spec.summary = ''
12
- spec.homepage = 'https://github.com/ulysses-bull/solidus_brazilian_adaptations#readme'
13
- spec.license = 'BSD-3-Clause'
11
+ spec.summary = ""
12
+ spec.homepage = "https://github.com/ulysses-bull/solidus_brazilian_adaptations#readme"
13
+ spec.license = "BSD-3-Clause"
14
14
 
15
- spec.metadata['homepage_uri'] = spec.homepage
16
- spec.metadata['source_code_uri'] = 'https://github.com/ulysses-bull/solidus_brazilian_adaptations'
17
- spec.metadata['changelog_uri'] = 'https://github.com/ulysses-bull/solidus_brazilian_adaptations/blob/master/CHANGELOG.md'
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/ulysses-bull/solidus_brazilian_adaptations"
17
+ spec.metadata["changelog_uri"] = "https://github.com/ulysses-bull/solidus_brazilian_adaptations/blob/master/CHANGELOG.md"
18
18
 
19
- spec.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 4')
19
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5", "< 4")
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
23
  files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
24
24
 
25
25
  spec.files = files.grep_v(%r{^(test|spec|features)/})
26
- spec.test_files = files.grep(%r{^(test|spec|features)/})
27
26
  spec.bindir = "exe"
28
27
  spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
29
28
  spec.require_paths = ["lib"]
30
29
 
31
- spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 5']
32
- spec.add_dependency 'solidus_support', '~> 0.5'
33
- spec.add_dependency 'cpf_cnpj'
30
+ spec.add_dependency "solidus_core", [">= 2.0.0", "< 5"]
31
+ spec.add_dependency "solidus_support", "~> 0.5"
32
+ spec.add_dependency "cpf_cnpj"
34
33
 
35
- spec.add_development_dependency 'solidus_dev_support', '~> 2.7'
34
+ spec.add_development_dependency "solidus_dev_support", "~> 2.7"
36
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_brazilian_adaptations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ulysses-bull
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-19 00:00:00.000000000 Z
11
+ date: 2023-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -84,16 +84,11 @@ files:
84
84
  - ".github_changelog_generator"
85
85
  - ".gitignore"
86
86
  - ".rspec"
87
- - ".rubocop.yml"
88
87
  - CHANGELOG.md
89
88
  - Gemfile
90
89
  - LICENSE
91
90
  - README.md
92
91
  - Rakefile
93
- - app/assets/javascripts/spree/backend/solidus_brazilian_adaptations.js
94
- - app/assets/javascripts/spree/frontend/solidus_brazilian_adaptations.js
95
- - app/assets/stylesheets/spree/backend/solidus_brazilian_adaptations.css
96
- - app/assets/stylesheets/spree/frontend/solidus_brazilian_adaptations.css
97
92
  - app/decorators/models/solidus_brazilian_adaptations/spree/order_decorator.rb
98
93
  - app/modules/tax_id_br.rb
99
94
  - bin/console
@@ -107,6 +102,17 @@ files:
107
102
  - config/routes.rb
108
103
  - db/migrate/20230911133000_add_tax_id_to_spree_orders.rb
109
104
  - db/migrate/20230911133157_add_number_district_to_addresses.rb
105
+ - db/seeds.rb
106
+ - db/spree_br/countries.rb
107
+ - db/spree_br/payment.rb
108
+ - db/spree_br/refund_reasons.rb
109
+ - db/spree_br/return_reasons.rb
110
+ - db/spree_br/roles.rb
111
+ - db/spree_br/shipping.rb
112
+ - db/spree_br/states.rb
113
+ - db/spree_br/stock_locations.rb
114
+ - db/spree_br/store_credit.rb
115
+ - db/spree_br/stores.rb
110
116
  - lib/generators/solidus_brazilian_adaptations/install/install_generator.rb
111
117
  - lib/generators/solidus_brazilian_adaptations/install/templates/initializer.rb
112
118
  - lib/solidus_brazilian_adaptations.rb
@@ -115,7 +121,6 @@ files:
115
121
  - lib/solidus_brazilian_adaptations/testing_support/factories.rb
116
122
  - lib/solidus_brazilian_adaptations/version.rb
117
123
  - solidus_brazilian_adaptations.gemspec
118
- - spec/spec_helper.rb
119
124
  homepage: https://github.com/ulysses-bull/solidus_brazilian_adaptations#readme
120
125
  licenses:
121
126
  - BSD-3-Clause
@@ -141,9 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
146
  - !ruby/object:Gem::Version
142
147
  version: '0'
143
148
  requirements: []
144
- rubygems_version: 3.4.6
149
+ rubygems_version: 3.4.19
145
150
  signing_key:
146
151
  specification_version: 4
147
152
  summary: ''
148
- test_files:
149
- - spec/spec_helper.rb
153
+ test_files: []
data/.rubocop.yml DELETED
@@ -1,5 +0,0 @@
1
- require:
2
- - solidus_dev_support/rubocop
3
-
4
- AllCops:
5
- NewCops: disable
@@ -1,2 +0,0 @@
1
- // Placeholder manifest file.
2
- // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/backend/all.js'
@@ -1,2 +0,0 @@
1
- // Placeholder manifest file.
2
- // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js'
@@ -1,4 +0,0 @@
1
- /*
2
- Placeholder manifest file.
3
- the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
4
- */
@@ -1,4 +0,0 @@
1
- /*
2
- Placeholder manifest file.
3
- the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
4
- */
data/spec/spec_helper.rb DELETED
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Configure Rails Environment
4
- ENV['RAILS_ENV'] = 'test'
5
-
6
- # Run Coverage report
7
- require 'solidus_dev_support/rspec/coverage'
8
-
9
- # Create the dummy app if it's still missing.
10
- dummy_env = "#{__dir__}/dummy/config/environment.rb"
11
- system 'bin/rake extension:test_app' unless File.exist? dummy_env
12
- require dummy_env
13
-
14
- # Requires factories and other useful helpers defined in spree_core.
15
- require 'solidus_dev_support/rspec/feature_helper'
16
-
17
- # Requires supporting ruby files with custom matchers and macros, etc,
18
- # in spec/support/ and its subdirectories.
19
- Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
20
-
21
- # Requires factories defined in Solidus core and this extension.
22
- # See: lib/solidus_brazilian_adaptations/testing_support/factories.rb
23
- SolidusDevSupport::TestingSupport::Factories.load_for(SolidusBrazilianAdaptations::Engine)
24
-
25
- RSpec.configure do |config|
26
- config.infer_spec_type_from_file_location!
27
- config.use_transactional_fixtures = false
28
-
29
- if Spree.solidus_gem_version < Gem::Version.new('2.11')
30
- config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
31
- end
32
- end