solidus_brazilian_adaptations 1.0.5 → 1.0.7

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: abf9b101cad24f96d6b95af4b1c1587666d279a7ec9c38cd6eadf80588c2de3a
4
- data.tar.gz: cea1c5c853b54b8b10dc962476b05fe04f2f9819155e14cf3e3c5931919c055e
3
+ metadata.gz: a76efff4ad9d953e3b825eb176e237621450b260742c756eefa2d4f0af0619dd
4
+ data.tar.gz: a6b045f77cc4be284a6070fb9b65d02571f1511190b74b63bc9b0be64d62cb74
5
5
  SHA512:
6
- metadata.gz: df1c8d4801d1a4c440c86ecdf94954145053cbbfd42ca61b365b4f93c22b6c38f0868645b73a0456bd9d0a07abc7b9c3bfb9038ed9998e1502e4a76e8dff15a2
7
- data.tar.gz: 48da079873137eddebd6b0e1fdaf62605cd11446abaacff3641493429943395b3f187c2337382dad2f9be5c3921e7c0011a365ceefe6319283eab60732e0e5dc
6
+ metadata.gz: 959e7bb2737a3f8a90d93f5c30c0ca35195ec03876e3c2574f3a90998e651d006b9224eac771cb4cb4823203e871fa4f202209be81a0371662cbb940b8e0c783
7
+ data.tar.gz: 61fdc3b8035422d5379d84117aa6f372053e83d069108c4fcb75f36df1fd92c5ccba43c510967fff0f59b2077fca2e0626470fb3f1c79df83956e142047779eb
data/Gemfile CHANGED
@@ -1,42 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
5
 
6
- branch = ENV.fetch('SOLIDUS_BRANCH', 'main')
7
- gem 'solidus', github: 'solidusio/solidus', branch: branch
6
+ branch = ENV.fetch("SOLIDUS_BRANCH", "main")
7
+ gem "solidus", github: "solidusio/solidus", branch: branch
8
8
 
9
9
  # The solidus_frontend gem has been pulled out since v3.2
10
- if branch >= 'v3.2'
11
- gem 'solidus_frontend'
12
- elsif branch == 'main'
13
- gem 'solidus_frontend', github: 'solidusio/solidus_frontend'
10
+ if branch >= "v3.2"
11
+ gem "solidus_frontend"
12
+ elsif branch == "main"
13
+ gem "solidus_frontend", github: "solidusio/solidus_frontend"
14
14
  else
15
- gem 'solidus_frontend', github: 'solidusio/solidus', branch: branch
15
+ gem "solidus_frontend", github: "solidusio/solidus", branch: branch
16
16
  end
17
17
 
18
18
  # Needed to help Bundler figure out how to resolve dependencies,
19
19
  # otherwise it takes forever to resolve them.
20
20
  # See https://github.com/bundler/bundler/issues/6677
21
- gem 'rails', '>0.a'
22
-
21
+ gem "rails", ">0.a"
23
22
 
24
23
  # Provides basic authentication functionality for testing parts of your engine
25
- gem 'solidus_auth_devise'
24
+ gem "solidus_auth_devise"
26
25
 
27
- case ENV.fetch('DB', nil)
28
- when 'mysql'
29
- gem 'mysql2'
30
- when 'postgresql'
31
- gem 'pg'
26
+ case ENV.fetch("DB", nil)
27
+ when "mysql"
28
+ gem "mysql2"
29
+ when "postgresql"
30
+ gem "pg"
32
31
  else
33
- gem 'sqlite3'
32
+ gem "sqlite3"
34
33
  end
35
34
 
36
35
  # While we still support Ruby < 3 we need to workaround a limitation in
37
36
  # the 'async' gem that relies on the latest ruby, since RubyGems doesn't
38
37
  # resolve gems based on the required ruby version.
39
- gem 'async', '< 3' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')
38
+ gem "async", "< 3" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3")
40
39
 
41
40
  gemspec
42
41
 
@@ -45,4 +44,4 @@ gemspec
45
44
  #
46
45
  # We use `send` instead of calling `eval_gemfile` to work around an issue with
47
46
  # how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658.
48
- send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local'
47
+ send(:eval_gemfile, "Gemfile-local") if File.exist? "Gemfile-local"
@@ -0,0 +1,19 @@
1
+ module AddressValidations
2
+ extend ActiveSupport::Concern
3
+
4
+ prepended do
5
+ validates :number, presence: true, if: -> { country.iso == "BR" }
6
+ validates :district, presence: true, if: -> { country.iso == "BR" }
7
+ validate :compatible_zipcode_and_state
8
+
9
+ def compatible_zipcode_and_state
10
+ return if country.iso != "BR"
11
+ cep = CodigoPostal.new(zipcode)
12
+ unless cep.state_code == state.abbr
13
+ errors.add(:base, "CEP não corresponde ao Estado.")
14
+ end
15
+ end
16
+ end
17
+
18
+ ::Spree::Address.prepend self
19
+ end
@@ -0,0 +1,27 @@
1
+ module OrderValidations
2
+ extend ActiveSupport::Concern
3
+
4
+ prepended do
5
+ validate :check_tax_id, if: :email_required?
6
+ before_update :format_tax_id
7
+
8
+ def check_tax_id
9
+ cnpj_allowed = SolidusBrazilianAdaptations.config.allow_cnpj
10
+ document = TaxIdBr.new(tax_id)
11
+ if document.valid?
12
+ if document.document_type == :cnpj && cnpj_allowed == false
13
+ errors.add(:base, "Insira um CPF, não um CNPJ.")
14
+ end
15
+ else
16
+ errors.add(:base, "#{cnpj_allowed ? "CPF/CPNJ" : "CPF"} inválido.")
17
+ end
18
+ end
19
+
20
+ def format_tax_id
21
+ document = TaxIdBr.new(tax_id)
22
+ self.tax_id = document.formatted
23
+ end
24
+ end
25
+
26
+ ::Spree::Order.prepend self
27
+ end
data/db/seeds.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'thor'
1
+ require "thor"
2
2
  shell = Thor::Base.shell.new
3
3
 
4
4
  %w[
@@ -15,4 +15,4 @@ shell = Thor::Base.shell.new
15
15
  ].each do |seed|
16
16
  shell.say_status :seed, seed
17
17
  require_relative "spree_br/#{seed}"
18
- end
18
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'carmen'
3
+ require "carmen"
4
4
 
5
5
  # Insert Countries into the spree_countries table, checking to ensure that no
6
6
  # duplicates are created, using as few SQL statements as possible (2)
@@ -8,11 +8,11 @@ require 'carmen'
8
8
  connection = Spree::Base.connection
9
9
 
10
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
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
16
  states_required = connection.quote country.subregions?
17
17
 
18
18
  [name, iso3, iso, iso_name, numcode, states_required].join(", ")
@@ -27,12 +27,12 @@ country_values = -> do
27
27
 
28
28
  # create VALUES statements for each country _not_ already in the database
29
29
  carmen_countries
30
- .reject { |c| existing_country_isos.include?(c.alpha_2_code) || c.alpha_2_code != 'BR' }
30
+ .reject { |c| existing_country_isos.include?(c.alpha_2_code) || c.alpha_2_code != "BR" }
31
31
  .map(&country_mapper)
32
32
  .join("), (")
33
33
  end
34
34
 
35
- country_columns = %w(name iso3 iso iso_name numcode states_required).join(', ')
35
+ country_columns = %w[name iso3 iso iso_name numcode states_required].join(", ")
36
36
  country_vals = country_values.call
37
37
 
38
38
  if country_vals.present?
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
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')
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")
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Spree::StockLocation.create_with(backorderable_default: true)
4
- .find_or_create_by!(name: 'default')
4
+ .find_or_create_by!(name: "default")
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
-
4
3
  Spree::PaymentMethod.create_with(
5
4
  name: "Store Credit",
6
5
  description: "Store credit",
@@ -14,10 +13,10 @@ Spree::PaymentMethod.create_with(
14
13
  Spree::StoreCreditType.create_with(priority: 1).find_or_create_by!(name: Spree::StoreCreditType::EXPIRING)
15
14
  Spree::StoreCreditType.create_with(priority: 2).find_or_create_by!(name: Spree::StoreCreditType::NON_EXPIRING)
16
15
 
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')
16
+ Spree::ReimbursementType.create_with(name: "Store Credit").find_or_create_by!(type: "Spree::ReimbursementType::StoreCredit")
17
+ Spree::ReimbursementType.create_with(name: "Original").find_or_create_by!(type: "Spree::ReimbursementType::OriginalPayment")
19
18
 
20
19
  Spree::StoreCreditCategory.find_or_create_by!(name: Spree::StoreCreditCategory::GIFT_CARD)
21
20
  Spree::StoreCreditCategory.find_or_create_by!(name: Spree::StoreCreditCategory::REIMBURSEMENT)
22
21
 
23
- Spree::StoreCreditReason.find_or_create_by!(name: 'Credit Given In Error')
22
+ Spree::StoreCreditReason.find_or_create_by!(name: "Credit Given In Error")
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- unless Spree::Store.where(code: 'sample-store').exists?
3
+ unless Spree::Store.where(code: "sample-store").exists?
4
4
  Spree::Store.create!(
5
5
  name: "Sample Store",
6
6
  code: "sample-store",
@@ -4,26 +4,26 @@ module SolidusBrazilianAdaptations
4
4
  module Generators
5
5
  class InstallGenerator < Rails::Generators::Base
6
6
  class_option :auto_run_migrations, type: :boolean, default: false
7
- source_root File.expand_path('templates', __dir__)
7
+ source_root File.expand_path("templates", __dir__)
8
8
 
9
9
  def self.exit_on_failure?
10
10
  true
11
11
  end
12
12
 
13
13
  def copy_initializer
14
- template 'initializer.rb', 'config/initializers/solidus_brazilian_adaptations.rb'
14
+ template "initializer.rb", "config/initializers/solidus_brazilian_adaptations.rb"
15
15
  end
16
16
 
17
17
  def add_migrations
18
- run 'bin/rails railties:install:migrations FROM=solidus_brazilian_adaptations'
18
+ run "bin/rails railties:install:migrations FROM=solidus_brazilian_adaptations"
19
19
  end
20
20
 
21
21
  def run_migrations
22
- run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
22
+ run_migrations = options[:auto_run_migrations] || ["", "y", "Y"].include?(ask("Would you like to run the migrations now? [Y/n]")) # rubocop:disable Layout/LineLength
23
23
  if run_migrations
24
- run 'bin/rails db:migrate'
24
+ run "bin/rails db:migrate"
25
25
  else
26
- puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
26
+ puts "Skipping bin/rails db:migrate, don't forget to run it!" # rubocop:disable Rails/Output
27
27
  end
28
28
  end
29
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusBrazilianAdaptations
4
- VERSION = "1.0.5"
4
+ VERSION = "1.0.7"
5
5
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "cpf_cnpj"
4
+ require "codigo_postal"
4
5
  require "solidus_brazilian_adaptations/configuration"
5
6
  require "solidus_brazilian_adaptations/version"
6
7
  require "solidus_brazilian_adaptations/engine"
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "solidus_core", [">= 2.0.0", "< 5"]
31
31
  spec.add_dependency "solidus_support", "~> 0.5"
32
32
  spec.add_dependency "cpf_cnpj"
33
+ spec.add_dependency "codigo_postal"
33
34
 
34
35
  spec.add_development_dependency "solidus_dev_support", "~> 2.7"
35
36
  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.5
4
+ version: 1.0.7
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-10-24 00:00:00.000000000 Z
11
+ date: 2023-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: codigo_postal
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: solidus_dev_support
63
77
  requirement: !ruby/object:Gem::Requirement
@@ -89,8 +103,9 @@ files:
89
103
  - LICENSE
90
104
  - README.md
91
105
  - Rakefile
92
- - app/decorators/models/solidus_brazilian_adaptations/spree/order_decorator.rb
93
- - app/modules/tax_id_br.rb
106
+ - app/models/tax_id_br.rb
107
+ - app/overrides/address_validations.rb
108
+ - app/overrides/order_validations.rb
94
109
  - bin/console
95
110
  - bin/rails
96
111
  - bin/rails-engine
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusBrazilianAdaptations
4
- module Spree
5
- module OrderDecorator
6
- def self.prepended(base)
7
- base.class_eval do
8
- validate :verify, if: :email_required?
9
- before_update :format_tax_id
10
-
11
- def verify
12
- cnpj_allowed = SolidusBrazilianAdaptations.config.allow_cnpj
13
- document = TaxIdBr.new(tax_id)
14
- if document.valid?
15
- if document.document_type == :cnpj && cnpj_allowed == false
16
- errors.add(:base, "Insira um CPF, não um CNPJ.")
17
- end
18
- else
19
- errors.add(:base, "#{cnpj_allowed ? "CPF/CPNJ" : "CPF"} inválido.")
20
- end
21
- end
22
-
23
- def format_tax_id
24
- document = TaxIdBr.new(tax_id)
25
- self.tax_id = document.formatted
26
- end
27
- end
28
- end
29
-
30
- ::Spree::Order.prepend self
31
- end
32
- end
33
- end
File without changes