solidus_brazilian_adaptations 1.0.4 → 1.0.6

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: b356e4123169f20ef2402662b44ceddd5abb97b0b5168ca57f4877928e834b4e
4
- data.tar.gz: 249f242993eca97dd87c7db21cbde15976446274ceb6b56e318cfb841987e5f8
3
+ metadata.gz: 24fa67771b38cee0a4d92caf9fdae494846fb87023ddfce3f3ed4077433661e7
4
+ data.tar.gz: 2adf6fce94c6ebdc966e6ff986daf61462e92dc0576de84f47b8e4d2ac2f0e22
5
5
  SHA512:
6
- metadata.gz: df81e4f22273092889875d3c9cd4b6bbec9779e241af27b869c960a49e5e8f7f3b6349d654ef43a1fc23692d0764bc56c157c2ba52b3f53bb6f13129cf68c30b
7
- data.tar.gz: c1ba5fbc771af841b50dc306e59da2daa85e55a00410bd313ed75309214aa1f86dc8d7a5997c6690df5ca4b2e36ae95669ec5f85539e6147b3e817fa859f5a67
6
+ metadata.gz: 77d168c0c7ad3c0cb2993817009a04a8cece0c88d1a5abf9ed9536ad594d34ca709d9069e7b4fb131fdf30c536c8362fd9f0755a46e75b185cdc4b5db87e7320
7
+ data.tar.gz: c37f09bace53817ef175c4758c199767726c466ef2399327bbf24b7275fe3526b90d8869bb28827f58d448813b39843140cb9cfa3f025b8ce5cd4c33405984a8
@@ -0,0 +1,10 @@
1
+ module AddressValidations
2
+ extend ActiveSupport::Concern
3
+
4
+ prepended do
5
+ validates :number, presence: true
6
+ validates :district, presence: true
7
+ end
8
+
9
+ ::Spree::Address.prepend self
10
+ end
@@ -0,0 +1,35 @@
1
+ module OrderValidations
2
+ extend ActiveSupport::Concern
3
+
4
+ prepended do
5
+ validate :check_tax_id, if: :email_required?
6
+ validate :check_compatible_zipcode_and_state
7
+ before_update :format_tax_id
8
+
9
+ def check_compatible_zipcode_and_state
10
+ cep = CodigoPostal.new(ship_address.zipcode)
11
+ unless cep.state_code == ship_address.state.abbr
12
+ errors.add(:base, "CEP não corresponde ao Estado.")
13
+ end
14
+ end
15
+
16
+ def check_tax_id
17
+ cnpj_allowed = SolidusBrazilianAdaptations.config.allow_cnpj
18
+ document = TaxIdBr.new(tax_id)
19
+ if document.valid?
20
+ if document.document_type == :cnpj && cnpj_allowed == false
21
+ errors.add(:base, "Insira um CPF, não um CNPJ.")
22
+ end
23
+ else
24
+ errors.add(:base, "#{cnpj_allowed ? "CPF/CPNJ" : "CPF"} inválido.")
25
+ end
26
+ end
27
+
28
+ def format_tax_id
29
+ document = TaxIdBr.new(tax_id)
30
+ self.tax_id = document.formatted
31
+ end
32
+ end
33
+
34
+ ::Spree::Order.prepend self
35
+ 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusBrazilianAdaptations
4
- VERSION = "1.0.4"
4
+ VERSION = "1.0.6"
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.4
4
+ version: 1.0.6
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-20 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
@@ -102,6 +117,17 @@ files:
102
117
  - config/routes.rb
103
118
  - db/migrate/20230911133000_add_tax_id_to_spree_orders.rb
104
119
  - db/migrate/20230911133157_add_number_district_to_addresses.rb
120
+ - db/seeds.rb
121
+ - db/spree_br/countries.rb
122
+ - db/spree_br/payment.rb
123
+ - db/spree_br/refund_reasons.rb
124
+ - db/spree_br/return_reasons.rb
125
+ - db/spree_br/roles.rb
126
+ - db/spree_br/shipping.rb
127
+ - db/spree_br/states.rb
128
+ - db/spree_br/stock_locations.rb
129
+ - db/spree_br/store_credit.rb
130
+ - db/spree_br/stores.rb
105
131
  - lib/generators/solidus_brazilian_adaptations/install/install_generator.rb
106
132
  - lib/generators/solidus_brazilian_adaptations/install/templates/initializer.rb
107
133
  - lib/solidus_brazilian_adaptations.rb
@@ -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