spree_zaez_tnt_mercurio 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +7 -0
- data/Guardfile +90 -0
- data/LICENSE +22 -0
- data/README.md +89 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/spree/backend/spree_zaez_tnt_mercurio.js +2 -0
- data/app/assets/javascripts/spree/frontend/spree_zaez_tnt_mercurio.js +2 -0
- data/app/assets/stylesheets/spree/backend/spree_zaez_tnt_mercurio.css +3 -0
- data/app/assets/stylesheets/spree/frontend/spree_zaez_tnt_mercurio.css +4 -0
- data/app/controllers/spree/admin/tnt_mercurio_settings_controller.rb +20 -0
- data/app/models/spree/calculator/shipping/tnt_mercurio_anc.rb +13 -0
- data/app/models/spree/calculator/shipping/tnt_mercurio_base_calculator.rb +42 -0
- data/app/models/spree/calculator/shipping/tnt_mercurio_rnc.rb +13 -0
- data/app/overrides/spree/admin/shared/sub_menu/_configuration/add_tnt_mercurio_settings_tab.html.erb.deface +2 -0
- data/app/views/spree/admin/tnt_mercurio_settings/edit.html.erb +76 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +41 -0
- data/config/locales/pt-br.yml +41 -0
- data/config/routes.rb +5 -0
- data/lib/generators/spree_zaez_tnt_mercurio/install/install_generator.rb +31 -0
- data/lib/spree/tnt_mercurio_configuration.rb +18 -0
- data/lib/spree_zaez_tnt_mercurio/engine.rb +32 -0
- data/lib/spree_zaez_tnt_mercurio/factories.rb +9 -0
- data/lib/spree_zaez_tnt_mercurio.rb +3 -0
- data/spec/features/admin/tnt_settings_spec.rb +121 -0
- data/spec/fixtures/calcula_frete/error_response.xml +28 -0
- data/spec/fixtures/calcula_frete/invalid_credentials.xml +32 -0
- data/spec/fixtures/calcula_frete/success_response.xml +155 -0
- data/spec/models/spree/calculator/shipping/tnt_mercurio_anc_spec.rb +19 -0
- data/spec/models/spree/calculator/shipping/tnt_mercurio_rnc_spec.rb +18 -0
- data/spec/models/spree/tnt_mercurio_configuration_spec.rb +14 -0
- data/spec/shared_examples/tnt_calculator.rb +159 -0
- data/spec/spec_helper.rb +89 -0
- data/spec/support/capybara_login.rb +6 -0
- data/spec/support/verify_tnt_input_field.rb +16 -0
- data/spree_zaez_tnt_mercurio.gemspec +38 -0
- metadata +53 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6120bbc4b11e1faa0227ab3248eea24e4429dce
|
4
|
+
data.tar.gz: f517de387fb8e5a1837876c8b511d018b05d4358
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 287a20d61471473ae1b3cce67953053d610e0f72794ccd3d3a14502f96f326455ff3439b8d8565f3d03837123a8f5c826ece18949909da424274371538050b34
|
7
|
+
data.tar.gz: 877f488988aa72477fcbce31b385b6086254fc97d241d2633218189e9c3428b39fb38e84308dc8416ff6630642592e8322e885cfafeda64cd5abbb0d1333a081
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format documentation --color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec feature)
|
6
|
+
|
7
|
+
## Uncomment to clear the screen before every task
|
8
|
+
# clearing :on
|
9
|
+
|
10
|
+
## Guard internally checks for changes in the Guardfile and exits.
|
11
|
+
## If you want Guard to automatically start up again, run guard in a
|
12
|
+
## shell loop, e.g.:
|
13
|
+
##
|
14
|
+
## $ while bundle exec guard; do echo "Restarting Guard..."; done
|
15
|
+
##
|
16
|
+
## Note: if you are using the `directories` clause above and you are not
|
17
|
+
## watching the project directory ('.'), the you will want to move the Guardfile
|
18
|
+
## to a watched dir and symlink it back, e.g.
|
19
|
+
#
|
20
|
+
# $ mkdir config
|
21
|
+
# $ mv Guardfile config/
|
22
|
+
# $ ln -s config/Guardfile .
|
23
|
+
#
|
24
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
25
|
+
|
26
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
27
|
+
# rspec may be run, below are examples of the most common uses.
|
28
|
+
# * bundler: 'bundle exec rspec'
|
29
|
+
# * bundler binstubs: 'bin/rspec'
|
30
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
31
|
+
# installed the spring binstubs per the docs)
|
32
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
33
|
+
# * 'just' rspec: 'rspec'
|
34
|
+
|
35
|
+
guard :shell do
|
36
|
+
watch(/^db\/migrate\/.*\.rb/) do |m|
|
37
|
+
puts "#{m[0]} Changed"
|
38
|
+
`bundle exec rake test_app`
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
guard :bundler do
|
43
|
+
watch('Gemfile')
|
44
|
+
# Uncomment next line if Gemfile contain `gemspec' command
|
45
|
+
watch(/^.+\.gemspec/)
|
46
|
+
end
|
47
|
+
|
48
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
49
|
+
require "guard/rspec/dsl"
|
50
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
51
|
+
|
52
|
+
# Feel free to open issues for suggestions and improvements
|
53
|
+
|
54
|
+
# RSpec files
|
55
|
+
rspec = dsl.rspec
|
56
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
57
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
58
|
+
watch(rspec.spec_files)
|
59
|
+
|
60
|
+
# Ruby files
|
61
|
+
ruby = dsl.ruby
|
62
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
63
|
+
|
64
|
+
# Rails files
|
65
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
66
|
+
dsl.watch_spec_files_for(rails.app_files)
|
67
|
+
dsl.watch_spec_files_for(rails.views)
|
68
|
+
|
69
|
+
watch(rails.controllers) do |m|
|
70
|
+
[
|
71
|
+
rspec.spec.("routing/#{m[1]}_routing"),
|
72
|
+
rspec.spec.("controllers/#{m[1]}_controller"),
|
73
|
+
rspec.spec.("acceptance/#{m[1]}")
|
74
|
+
]
|
75
|
+
end
|
76
|
+
|
77
|
+
# Rails config changes
|
78
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
79
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
80
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
81
|
+
|
82
|
+
# Capybara features specs
|
83
|
+
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
|
84
|
+
|
85
|
+
# Turnip features and steps
|
86
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
87
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
88
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
89
|
+
end
|
90
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Zaez Inovação Digital
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
Spree TNT Mercúrio [![Build Status](https://travis-ci.org/zaeznet/spree_zaez_tnt_mercurio.svg?branch=master)](https://travis-ci.org/zaeznet/spree_zaez_tnt_mercurio)
|
2
|
+
=============
|
3
|
+
|
4
|
+
This gem implements diverse functions in order to enable the use of services from TNT Mercúrio in Spree Commerce.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Add spree_zaez_tnt_mercurio to your Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'spree_zaez_tnt_mercurio', github: 'zaeznet/spree_zaez_tnt_mercurio'
|
13
|
+
```
|
14
|
+
|
15
|
+
Bundle your dependencies and run the installation generator:
|
16
|
+
|
17
|
+
```shell
|
18
|
+
bundle
|
19
|
+
bundle exec rails g spree_zaez_tnt_mercurio:install
|
20
|
+
```
|
21
|
+
|
22
|
+
|
23
|
+
Settings
|
24
|
+
------------
|
25
|
+
|
26
|
+
In admin/tnt_mercurio_settings/edit, it's possible set the values of TNT Mercurio.
|
27
|
+
To set the settings through a config file, you can assign values to the settings like so:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Spree::TntMercurioConfig[:email] = 'yourlogin@email.com'
|
31
|
+
```
|
32
|
+
|
33
|
+
See all the fields in lib/spree/tnt_mercurio_configuration.rb
|
34
|
+
|
35
|
+
|
36
|
+
Deface
|
37
|
+
------------
|
38
|
+
|
39
|
+
```
|
40
|
+
Backend
|
41
|
+
* add_tnt_mercurio_settings_tab -> spree/admin/shared/sub_menu/_configuration.html.erb
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
Testing
|
46
|
+
-------
|
47
|
+
|
48
|
+
First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using `rake test_app`.
|
49
|
+
|
50
|
+
```shell
|
51
|
+
bundle
|
52
|
+
bundle exec rake
|
53
|
+
```
|
54
|
+
|
55
|
+
When testing your applications integration with this extension you may use it's factories.
|
56
|
+
Simply add this require statement to your spec_helper:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
require 'spree_zaez_tnt_mercurio/factories'
|
60
|
+
```
|
61
|
+
|
62
|
+
Copyright (c) 2015 Zaez Inovação Digital, released under the New BSD License
|
63
|
+
|
64
|
+
|
65
|
+
License
|
66
|
+
-------
|
67
|
+
|
68
|
+
The MIT License (MIT)
|
69
|
+
|
70
|
+
Copyright (c) 2015 Zaez Inovação Digital
|
71
|
+
|
72
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
73
|
+
of this software and associated documentation files (the "Software"), to deal
|
74
|
+
in the Software without restriction, including without limitation the rights
|
75
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
76
|
+
copies of the Software, and to permit persons to whom the Software is
|
77
|
+
furnished to do so, subject to the following conditions:
|
78
|
+
|
79
|
+
The above copyright notice and this permission notice shall be included in all
|
80
|
+
copies or substantial portions of the Software.
|
81
|
+
|
82
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
83
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
84
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
85
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
86
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
87
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
88
|
+
SOFTWARE.
|
89
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'spree/testing_support/extension_rake'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new
|
8
|
+
|
9
|
+
task :default do
|
10
|
+
if Dir["spec/dummy"].empty?
|
11
|
+
Rake::Task[:test_app].invoke
|
12
|
+
Dir.chdir("../../")
|
13
|
+
end
|
14
|
+
Rake::Task[:spec].invoke
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Generates a dummy app for testing'
|
18
|
+
task :test_app do
|
19
|
+
ENV['LIB_NAME'] = 'spree_zaez_tnt_mercurio'
|
20
|
+
Rake::Task['extension:test_app'].invoke
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Spree::Admin::TntMercurioSettingsController < Spree::Admin::BaseController
|
2
|
+
|
3
|
+
def edit
|
4
|
+
@tax_situations = [:co, :nc, :ci, :cm, :cn, :me, :mn, :pr, :pn, :op, :on, :of]
|
5
|
+
@user_attr = Spree::User.new.attribute_names
|
6
|
+
@config = Spree::TntMercurioConfiguration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def update
|
10
|
+
config = Spree::TntMercurioConfiguration.new
|
11
|
+
|
12
|
+
params.each do |name, value|
|
13
|
+
next unless config.has_preference? name
|
14
|
+
config[name] = value
|
15
|
+
end
|
16
|
+
flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:tnt_mercurio_settings))
|
17
|
+
redirect_to edit_admin_tnt_mercurio_settings_path
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Spree
|
2
|
+
class Calculator::Shipping::TntMercurioBaseCalculator < Spree::ShippingCalculator
|
3
|
+
|
4
|
+
attr_reader :delivery_time
|
5
|
+
|
6
|
+
def compute_package(object)
|
7
|
+
return if object.nil?
|
8
|
+
order = if object.is_a?(Spree::Order) then object else object.order end
|
9
|
+
|
10
|
+
stock_location = object.stock_location
|
11
|
+
|
12
|
+
cgc_customer = order.user.attributes[Spree::TntMercurioConfig.customer_field]
|
13
|
+
cgc_type = if cgc_customer.delete('.').delete('-').size <= 11 then 'F' else 'J' end
|
14
|
+
|
15
|
+
params = {in0: {login: Spree::TntMercurioConfig.email,
|
16
|
+
senha: Spree::TntMercurioConfig.password,
|
17
|
+
nr_identif_cliente_rem: Spree::TntMercurioConfig.cgc,
|
18
|
+
nr_inscricao_estadual_remetente: Spree::TntMercurioConfig.state_registry,
|
19
|
+
nr_identif_cliente_dest: cgc_customer,
|
20
|
+
tp_situacao_tributaria_remetente: Spree::TntMercurioConfig.tax_situation,
|
21
|
+
tp_pessoa_remetente: Spree::TntMercurioConfig.type_cgc,
|
22
|
+
tp_pessoa_destinatario: cgc_type,
|
23
|
+
tp_situacao_tributaria_destinatario: 'NC',
|
24
|
+
cep_origem: stock_location.zipcode,
|
25
|
+
cep_destino: order.ship_address.zipcode,
|
26
|
+
vl_mercadoria: order.amount.to_s,
|
27
|
+
ps_real: object.weight.to_s,
|
28
|
+
tp_servico: shipping_method,
|
29
|
+
tp_frete: Spree::TntMercurioConfig.billet_type,
|
30
|
+
cd_divisao_cliente: Spree::TntMercurioConfig.division}}
|
31
|
+
|
32
|
+
client = Savon.client(wsdl: 'http://ws.tntbrasil.com.br/servicos/CalculoFrete?wsdl')
|
33
|
+
response = client.call(:calcula_frete, message: params).body
|
34
|
+
|
35
|
+
@delivery_time = response[:calcula_frete_response][:out][:prazo_entrega].to_i + Spree::TntMercurioConfig.additional_days
|
36
|
+
|
37
|
+
response[:calcula_frete_response][:out][:vl_total_frete].to_f + Spree::TntMercurioConfig.additional_value
|
38
|
+
rescue
|
39
|
+
false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
<%= render :partial => 'spree/admin/shared/sub_menu/configuration' %>
|
2
|
+
|
3
|
+
<% content_for :page_title do %>
|
4
|
+
<%= Spree.t(:tnt_mercurio_settings) %>
|
5
|
+
<% end %>
|
6
|
+
|
7
|
+
<%= form_tag admin_tnt_mercurio_settings_path, :method => :put do |form| %>
|
8
|
+
<div id="tnt_mercurio_preferences" data-hook="tnt_mercurio_preferences">
|
9
|
+
<div class="row">
|
10
|
+
<div class="col-sm-6">
|
11
|
+
<%= label_tag(:email, Spree.t(:email) + ': ') + tag(:br) %>
|
12
|
+
<%= text_field_tag :email, @config.email, class: 'form-control' %>
|
13
|
+
</div>
|
14
|
+
<div class="col-sm-6">
|
15
|
+
<%= label_tag(:password, Spree.t(:password) + ': ') + tag(:br) %>
|
16
|
+
<%= text_field_tag :password, @config.password, class: 'form-control' %>
|
17
|
+
</div>
|
18
|
+
<div class="col-sm-6">
|
19
|
+
<%= label_tag(:division, Spree.t(:division) + ': ') + tag(:br) %>
|
20
|
+
<%= text_field_tag :division, @config.division, class: 'form-control' %>
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
<div class="row">
|
24
|
+
<div class="col-sm-6">
|
25
|
+
<%= label_tag(:cgc, Spree.t(:cgc) + ': ') + tag(:br) %>
|
26
|
+
<%= text_field_tag :cgc, @config.cgc, class: 'form-control' %>
|
27
|
+
</div>
|
28
|
+
<div class="col-sm-6">
|
29
|
+
<%= label_tag(:state_registry, Spree.t(:state_registry) + ': ') + tag(:br) %>
|
30
|
+
<%= text_field_tag :state_registry, @config.state_registry, class: 'form-control' %>
|
31
|
+
</div>
|
32
|
+
<div class="col-sm-6">
|
33
|
+
<%= label_tag(:type_cgc, Spree.t(:type_cgc) + ': ') + tag(:br) %>
|
34
|
+
<%= radio_button_tag :type_cgc, 'F', @config.type_cgc == 'F' %>
|
35
|
+
<%= label_tag(:type_cgc_f, Spree.t(:type_cgc_f)) %>
|
36
|
+
<%= radio_button_tag :type_cgc, 'J', @config.type_cgc == 'J' %>
|
37
|
+
<%= label_tag(:type_cgc_j, Spree.t(:type_cgc_j)) %>
|
38
|
+
</div>
|
39
|
+
<div class="col-sm-6">
|
40
|
+
<%= label_tag(:billet_type, Spree.t(:billet_type) + ': ') + tag(:br) %>
|
41
|
+
<%= radio_button_tag :billet_type, 'F', @config.billet_type == 'F' %>
|
42
|
+
<%= label_tag(:billet_type_f, Spree.t(:billet_type_f)) %>
|
43
|
+
<%= radio_button_tag :billet_type, 'C', @config.billet_type == 'C' %>
|
44
|
+
<%= label_tag(:billet_type_c, Spree.t(:billet_type_c)) %>
|
45
|
+
</div>
|
46
|
+
</div>
|
47
|
+
<div class="row">
|
48
|
+
<div class="col-sm-12">
|
49
|
+
<%= label_tag(:tax_situation, Spree.t(:tax_situation) + ': ') + tag(:br) %>
|
50
|
+
<% @tax_situations.each do |situation| %>
|
51
|
+
<div class="col-sm-6 <%= cycle('p-l-n', '') -%>">
|
52
|
+
<%= radio_button_tag :tax_situation, situation.to_s.upcase, @config.tax_situation.downcase == situation.to_s %>
|
53
|
+
<%= label_tag "tax_situation_#{situation}".to_sym, Spree.t("tax_situation_#{situation}") %>
|
54
|
+
</div>
|
55
|
+
<% end %>
|
56
|
+
</div>
|
57
|
+
</div>
|
58
|
+
<div class="row">
|
59
|
+
<div class="col-sm-6">
|
60
|
+
<%= label_tag(:additional_days, Spree.t(:additional_days) + ': ') + tag(:br) %>
|
61
|
+
<%= text_field_tag :additional_days, @config.additional_days, class: 'form-control' %>
|
62
|
+
</div>
|
63
|
+
<div class="col-sm-6">
|
64
|
+
<%= label_tag(:additional_value, Spree.t(:additional_value) + ': ') + tag(:br) %>
|
65
|
+
<%= text_field_tag :additional_value, @config.additional_value, class: 'form-control' %>
|
66
|
+
</div>
|
67
|
+
</div>
|
68
|
+
<div class="row">
|
69
|
+
<div class="col-sm-6">
|
70
|
+
<%= label_tag(:customer_field, Spree.t(:customer_field) + ': ') + tag(:br) %>
|
71
|
+
<%= select_tag :customer_field, options_for_select(@user_attr.collect { |item| [t(item), item] }, @config.customer_field), class: 'form-control' %>
|
72
|
+
</div>
|
73
|
+
</div>
|
74
|
+
</div>
|
75
|
+
<%= render partial: 'spree/admin/shared/edit_resource_links', locals: { collection_url: edit_admin_tnt_mercurio_settings_url } %>
|
76
|
+
<% end %>
|
data/bin/rails
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
2
|
+
|
3
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
4
|
+
ENGINE_PATH = File.expand_path('../../lib/spree_zaez_tnt_mercurio/engine', __FILE__)
|
5
|
+
|
6
|
+
require 'rails/all'
|
7
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
en:
|
2
|
+
tnt_mercurio_settings: TNT Mercurio Settings
|
3
|
+
additional_days: Additional delivery days
|
4
|
+
additional_value: Additional value
|
5
|
+
email: Email
|
6
|
+
password: Password
|
7
|
+
division: Division
|
8
|
+
type_cgc: CGC Type
|
9
|
+
cgc: CGC
|
10
|
+
state_registry: State Registry
|
11
|
+
tax_situation: Tax Situation
|
12
|
+
billet_type: Billet Type
|
13
|
+
spree:
|
14
|
+
tnt_mercurio_settings: TNT Mercurio Settings
|
15
|
+
email: Email
|
16
|
+
password: Password
|
17
|
+
division: Division
|
18
|
+
tax_situation: Tax Situation
|
19
|
+
tax_situation_co: CO - Contribuinte
|
20
|
+
tax_situation_nc: NC - Não Contribuinte
|
21
|
+
tax_situation_ci: CI - Contribuinte Incentivado
|
22
|
+
tax_situation_cm: CM - Contribuinte Incentivado
|
23
|
+
tax_situation_cn: CN - Cia. Mista Não Contribuinte
|
24
|
+
tax_situation_me: ME - Simples Nacional Contribuinte
|
25
|
+
tax_situation_mn: MN - Simples Nacional Não Contribuinte
|
26
|
+
tax_situation_pr: PR - Produtor Rural Contribuinte
|
27
|
+
tax_situation_pn: PN - Produtor Rural Não Contribuinte
|
28
|
+
tax_situation_op: OP - Órgão Público Contribuinte
|
29
|
+
tax_situation_on: ON - Órgão Público Não Contribuinte
|
30
|
+
tax_situation_of: OF - Órgão Público - Prog. de Fort. e Modern. Est.
|
31
|
+
state_registry: State Registry
|
32
|
+
cgc: CGC
|
33
|
+
type_cgc: CGC Type
|
34
|
+
type_cgc_f: Personal
|
35
|
+
type_cgc_j: Business
|
36
|
+
billet_type: Billet Type
|
37
|
+
billet_type_c: CIF
|
38
|
+
billet_type_f: FOB
|
39
|
+
additional_days: Additional Days
|
40
|
+
additional_value: Additional Value
|
41
|
+
customer_field: Customer Field
|
@@ -0,0 +1,41 @@
|
|
1
|
+
pt-BR:
|
2
|
+
tnt_mercurio_settings: Configurações TNT Mercúrio
|
3
|
+
additional_days: Dias adicionais
|
4
|
+
additional_value: Valor adicional
|
5
|
+
email: Email
|
6
|
+
password: Senha
|
7
|
+
division: Divisão
|
8
|
+
type_cgc: Tipo CGC
|
9
|
+
cgc: CGC (Cadastro Geral de Contribuintes)
|
10
|
+
state_registry: Inscrição Estadual
|
11
|
+
tax_situtation: Situação Tributária
|
12
|
+
billet_type: Tipo de Cobrança
|
13
|
+
spree:
|
14
|
+
tnt_mercurio_settings: Configurações TNT Mercúrio
|
15
|
+
email: Email
|
16
|
+
password: Senha
|
17
|
+
division: Código da Divisão
|
18
|
+
tax_situation: Situação Tributária
|
19
|
+
tax_situation_co: CO - Contribuinte
|
20
|
+
tax_situation_nc: NC - Não Contribuinte
|
21
|
+
tax_situation_ci: CI - Contribuinte Incentivado
|
22
|
+
tax_situation_cm: CM - Contribuinte Incentivado
|
23
|
+
tax_situation_cn: CN - Cia. Mista Não Contribuinte
|
24
|
+
tax_situation_me: ME - Simples Nacional Contribuinte
|
25
|
+
tax_situation_mn: MN - Simples Nacional Não Contribuinte
|
26
|
+
tax_situation_pr: PR - Produtor Rural Contribuinte
|
27
|
+
tax_situation_pn: PN - Produtor Rural Não Contribuinte
|
28
|
+
tax_situation_op: OP - Órgão Público Contribuinte
|
29
|
+
tax_situation_on: ON - Órgão Público Não Contribuinte
|
30
|
+
tax_situation_of: OF - Órgão Público - Prog. de Fort. e Modern. Est.
|
31
|
+
state_registry: Inscrição Estadual
|
32
|
+
cgc: CGC (Cadastro Geral de Contribuintes)
|
33
|
+
type_cgc: Tipo CGC
|
34
|
+
type_cgc_f: Física
|
35
|
+
type_cgc_j: Jurídica
|
36
|
+
billet_type: Tipo de Cobrança
|
37
|
+
billet_type_c: CIF
|
38
|
+
billet_type_f: FOB
|
39
|
+
additional_days: Dias Adicionais
|
40
|
+
additional_value: Valor Adicional
|
41
|
+
customer_field: Campo do cliente (onde fica armazenado o CPF/CNPJ)
|
data/config/routes.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module SpreeZaezTntMercurio
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
class_option :auto_run_migrations, :type => :boolean, :default => false
|
6
|
+
|
7
|
+
def add_javascripts
|
8
|
+
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/spree_zaez_tnt_mercurio\n"
|
9
|
+
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/spree_zaez_tnt_mercurio\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_stylesheets
|
13
|
+
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/spree_zaez_tnt_mercurio\n", :before => /\*\//, :verbose => true
|
14
|
+
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/spree_zaez_tnt_mercurio\n", :before => /\*\//, :verbose => true
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_migrations
|
18
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_zaez_tnt_mercurio'
|
19
|
+
end
|
20
|
+
|
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]')
|
23
|
+
if run_migrations
|
24
|
+
run 'bundle exec rake db:migrate'
|
25
|
+
else
|
26
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Spree::TntMercurioConfiguration < Spree::Preferences::Configuration
|
2
|
+
|
3
|
+
preference :email, :string # email
|
4
|
+
preference :password, :string # senha
|
5
|
+
preference :division, :integer # codigo da divisao
|
6
|
+
|
7
|
+
preference :type_cgc, :string, default: 'J' # pessoa fisica (F) ou juridica (J)
|
8
|
+
preference :cgc, :string # cpf ou cnpj do remetente
|
9
|
+
preference :state_registry, :string # inscricao estadual
|
10
|
+
preference :tax_situation, :string, default: 'CO' # situacao tributaria
|
11
|
+
preference :billet_type, :string, default: 'C' # tipo de cobranca (CIF ou FOB)
|
12
|
+
|
13
|
+
preference :customer_field, :string # campo que esta armazenado o CPF/CNPJ do cliente
|
14
|
+
|
15
|
+
preference :additional_days, :integer, default: 0
|
16
|
+
preference :additional_value, :integer, default: 0
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module SpreeTntMercurio
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'spree_zaez_tnt_mercurio'
|
6
|
+
|
7
|
+
initializer 'spree.tnt_zaez_mercurio.preferences', :before => :load_config_initializers do |app|
|
8
|
+
# require file with the preferences of the TNT Mercurio
|
9
|
+
require 'spree/tnt_mercurio_configuration'
|
10
|
+
Spree::TntMercurioConfig = Spree::TntMercurioConfiguration.new
|
11
|
+
#
|
12
|
+
end
|
13
|
+
|
14
|
+
# use rspec for tests
|
15
|
+
config.generators do |g|
|
16
|
+
g.test_framework :rspec
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.activate
|
20
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
21
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
initializer 'spree_zaez_tnt_mercurio.register.calculators' do |app|
|
26
|
+
app.config.spree.calculators.shipping_methods << Spree::Calculator::Shipping::TntMercurioRNC
|
27
|
+
app.config.spree.calculators.shipping_methods << Spree::Calculator::Shipping::TntMercurioANC
|
28
|
+
end
|
29
|
+
|
30
|
+
config.to_prepare &method(:activate).to_proc
|
31
|
+
end
|
32
|
+
end
|