solidus_bling 3.2.9 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cabc5846e34b3e9c1c422581c3ad569483a648c34862d9c9a92999a0b8889e6d
4
- data.tar.gz: 9c1c10957436f7431e873f85acc8c54081be03ff47a10432d65a4a8db9677bca
3
+ metadata.gz: a518315c339e59749416c354476f5074b785e5f6221aa2f85f48ff97589090bf
4
+ data.tar.gz: 39d8b9d853e301213aa05996f618537c6348e77d7f9d3bb93e911db04540a45d
5
5
  SHA512:
6
- metadata.gz: 870b5efd4acc82ec2ec78347e53d63d18496dafdc7a274c7270a5e1a5c423c92318099b994093bd86d9dcdcacad0d1df762053fa983301b3bb2cc08a4783377b
7
- data.tar.gz: 5776751a2fd3812a9155441476a049ecdd6f8ab619362534746c7b09cb5e6c03c52abf87b523e9c3d37baf43f1fe119c1fb5e5dc5b7d8bc10a0f77e2ac25a8d0
6
+ metadata.gz: 77d81b06264164cb160cb1c34a104235d654143d95f63d1ae1e8f7a4cdda3c51850b671c2d7da91556301be365e9cf8b10b21af8007a390e23449d30bd06b4df
7
+ data.tar.gz: 1bfea6fd4602f7602430750b32510c86ea91f00807c1906b997ae7a020912d270f170fcd9a40878d4f7e8978f8a4e4beada389a1308269bce53365a50b04a29c
@@ -0,0 +1,36 @@
1
+ module Spree
2
+ module Admin
3
+ module Orders
4
+ class SellersController < BaseController
5
+ before_action :set_order, only: [:edit, :update]
6
+
7
+ def edit
8
+ @sellers = ::SolidusBling::Seller.all.order(:name)
9
+ end
10
+
11
+ def update
12
+ if @order.update(solidus_bling_seller_id: params[:order][:seller_id])
13
+ flash[:success] = "Vendedor atualizado com sucesso."
14
+ else
15
+ flash[:error] = "Erro ao atualizar vendedor."
16
+ end
17
+ redirect_to admin_orders_seller_path(@order)
18
+ end
19
+
20
+ def model_class
21
+ ::SolidusBling::Seller
22
+ end
23
+
24
+ private
25
+
26
+ def order_params
27
+ params.require(:order).permit(:seller_id)
28
+ end
29
+
30
+ def set_order
31
+ @order = Spree::Order.find_by!(number: params[:order_number])
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -60,6 +60,12 @@ module Spree
60
60
  redirect_to edit_admin_solidus_bling_account_path(bling_account.id)
61
61
  end
62
62
 
63
+ def upsert_sellers
64
+ ::SolidusBling::UpsertSellersJob.perform_later
65
+ flash[:success] = "Vendedores atualizados"
66
+ redirect_to admin_solidus_bling_accounts_path
67
+ end
68
+
63
69
  private
64
70
 
65
71
  def set_account
@@ -0,0 +1,9 @@
1
+ module SolidusBling
2
+ class UpsertSellersJob < ApplicationJob
3
+ queue_as :default
4
+
5
+ def perform
6
+ SolidusBling::Seller.upsert_sellers SolidusBling::Account.first
7
+ end
8
+ end
9
+ end
@@ -14,6 +14,7 @@ module SolidusBling
14
14
  parcelas = installments
15
15
  observacoes_internas = internal_observations
16
16
  transporte = shipment
17
+ id_vendedor = seller_external_id
17
18
 
18
19
  bling_order = BlingApi::Order.new(
19
20
  id_contato: contato.id,
@@ -31,7 +32,7 @@ module SolidusBling
31
32
  valor_desconto: @order.adjustment_total.abs,
32
33
  id_categoria: @account.incoming_category_id,
33
34
  transporte: transporte,
34
- id_vendedor: @account.sellers.first.external_id
35
+ id_vendedor: id_vendedor
35
36
  ).create
36
37
 
37
38
  if bling_order
@@ -129,6 +130,10 @@ module SolidusBling
129
130
  }
130
131
  end
131
132
 
133
+ def seller_external_id
134
+ @order.solidus_bling_seller_id ? @account.sellers.find(@order.solidus_bling_seller_id).external_id : SolidusBling::Seller.default.external_id
135
+ end
136
+
132
137
  def build_customer
133
138
  {
134
139
  nome: @order.bill_address.name.strip,
@@ -4,5 +4,18 @@ module SolidusBling
4
4
  validates :external_id, presence: true
5
5
 
6
6
  belongs_to :account
7
+
8
+ def self.upsert_sellers account
9
+ account.check_token
10
+ BlingApi.configure { |config| config.access_token = account.access_token }
11
+
12
+ sellers = BlingApi::Seller.get_sellers
13
+ upsert_sellers = sellers.map { |seller| { name: seller[:nome], external_id: seller[:id], account_id: account.id } }
14
+ SolidusBling::Seller.upsert_all(upsert_sellers, unique_by: :external_id)
15
+ end
16
+
17
+ def self.default
18
+ find_by(default: true)
19
+ end
7
20
  end
8
21
  end
@@ -0,0 +1,9 @@
1
+ module Spree
2
+ module PermissionSets
3
+ class SellerUpdate < Spree::PermissionSets::Base
4
+ def activate!
5
+ can :manage, ::SolidusBling::Seller
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ <%= render partial: 'spree/admin/shared/order_tabs', locals: { current: 'Vendedor' } %>
2
+
3
+ <% admin_breadcrumb("Vendedor") %>
4
+
5
+ <div data-order-number="<%= @order.number %>">
6
+ <div>
7
+ <fieldset class="no-border-bottom">
8
+ <legend>Vendedor</legend>
9
+ <%= form_with model: @order, url: admin_orders_update_seller_path(@order) do |form| %>
10
+ <%= form.select :seller_id, @sellers.pluck(:name, :id), { selected: @order.solidus_bling_seller_id || @sellers.default&.id }, class:"custom-select fullwidth" %>
11
+ <div class="form-buttons filter-actions actions" data-hook="buttons">
12
+ <%= form.submit t('spree.actions.update'), class: 'btn btn-primary mt-4' %>
13
+ </div>
14
+ <% end %>
15
+ </fieldset>
16
+ </div>
17
+
18
+ <%= render partial: 'spree/shared/error_messages', locals: { target: @order } %>
19
+ </div>
@@ -0,0 +1,67 @@
1
+ <nav>
2
+ <ul class="tabs" data-hook="admin_order_tabs">
3
+ <% if (@order.shipments.count == 0 || @order.shipped_shipments.count == 0) %>
4
+ <li class="<%= "active" if current == "Cart" %>" data-hook='admin_order_tabs_order_details'>
5
+ <%= link_to t('spree.cart'), spree.cart_admin_order_url(@order) %>
6
+ </li>
7
+ <% end %>
8
+
9
+ <% if checkout_steps.include?("address") %>
10
+ <li class="<%= "active" if (current == "Customer Details") %>" data-hook='admin_order_tabs_customer_details'>
11
+ <% if can?(:update, @order) %>
12
+ <%= link_to t('spree.customer'), spree.edit_admin_order_customer_url(@order) %>
13
+ <% else %>
14
+ <%= link_to t('spree.customer'), spree.admin_order_customer_url(@order) %>
15
+ <% end %>
16
+ </li>
17
+ <% end %>
18
+
19
+ <li class="<%= "active" if current == "Vendedor" %>" data-hook='admin_order_tabs_order_details'>
20
+ <%= link_to "Vendedor", admin_orders_seller_path(@order) %>
21
+ </li>
22
+
23
+ <li class="<%= "active" if current == "Shipments" %>" data-hook='admin_order_tabs_order_details'>
24
+ <%= link_to plural_resource_name(Spree::Shipment), spree.edit_admin_order_url(@order) %>
25
+ </li>
26
+
27
+ <% if can? :show, Spree::Adjustment %>
28
+ <li class="<%= "active" if current == "Adjustments" %>" data-hook='admin_order_tabs_adjustments'>
29
+ <%= link_to plural_resource_name(Spree::Adjustment), spree.admin_order_adjustments_url(@order) %>
30
+ </li>
31
+ <% end %>
32
+
33
+ <% if can?(:show, Spree::Payment) %>
34
+ <li class="<%= "active" if current == "Payments" %>" data-hook='admin_order_tabs_payments'>
35
+ <%= link_to plural_resource_name(Spree::Payment), spree.admin_order_payments_url(@order) %>
36
+ </li>
37
+ <% end %>
38
+
39
+ <% if !@order.completed? && can?(:update, @order) %>
40
+ <li class="<%= "active" if current == "Confirm" %>" data-hook='admin_order_tabs_confirm'>
41
+ <%= link_to t('spree.confirm'), spree.confirm_admin_order_url(@order) %>
42
+ </li>
43
+ <% end %>
44
+
45
+ <% if can? :show, Spree::ReturnAuthorization %>
46
+ <% if @order.completed? %>
47
+ <li class="tab <%= "active" if current == "Return Authorizations" %>" data-hook='admin_order_tabs_return_authorizations'>
48
+ <%= link_to t('spree.admin.tab.rma'), spree.admin_order_return_authorizations_url(@order) %>
49
+ </li>
50
+ <% end %>
51
+ <% end %>
52
+
53
+ <% if can? :show, Spree::CustomerReturn %>
54
+ <% if @order.completed? %>
55
+ <li class="<%= "active" if current == "Customer Returns" %>" data-hook='admin_order_tabs_customer_returns'>
56
+ <%= link_to plural_resource_name(Spree::CustomerReturn), spree.admin_order_customer_returns_url(@order) %>
57
+ </li>
58
+ <% end %>
59
+ <% end %>
60
+
61
+ <% if can?(:manage, Spree::OrderCancellations) && @order.inventory_units.cancelable.present? %>
62
+ <li class="<%= "active" if current == "Cancel Inventory" %>" data-hook='admin_order_tabs_cancel_inventory'>
63
+ <%= link_to t('spree.cancel_inventory'), spree.admin_order_cancellations_path(@order) %>
64
+ </li>
65
+ <% end %>
66
+ </ul>
67
+ </nav>
@@ -0,0 +1,75 @@
1
+
2
+ <header id="order_tab_summary" data-hook>
3
+ <dl class="additional-info">
4
+ <dt class="order-state" id="order_status" data-hook><%= t('spree.status') %>:</dt>
5
+ <dd class="order-state">
6
+ <span class="pill pill-<%= @order.state %>">
7
+ <%= t(@order.state, scope: 'spree.order_state') %>
8
+ </span>
9
+
10
+ <% if @order.user.present? %>
11
+ <dt data-hook='admin_order_user_link'><%= t('spree.user') %>:</dt>
12
+ <dd id='order_user_link'><%= link_to @order.user.email, spree.edit_admin_user_path(@order.user) %></dd>
13
+ <% end %>
14
+
15
+ <dt data-hook='admin_order_tab_subtotal_title'><%= Spree::Order.human_attribute_name(:item_total) %>:</dt>
16
+ <dd id='item_total'><%= @order.display_item_total.to_html %></dd>
17
+
18
+ <% if checkout_steps.include?("delivery") %>
19
+ <dt class="order-shipment_total <%= "hidden" if @order.ship_total.zero? %>" data-hook='admin_order_tab_ship_total_title'><%= Spree::Order.human_attribute_name(:shipment_total) %>:</dt>
20
+ <dd class="order-shipment_total <%= "hidden" if @order.ship_total.zero? %>" id='ship_total'><%= @order.display_ship_total.to_html %></dd>
21
+ <% end %>
22
+
23
+ <dt class="order-included_tax_total <%= "hidden" if @order.included_tax_total.zero? %>" data-hook='admin_order_tab_included_tax_title'><%= Spree::Order.human_attribute_name(:included_tax_total) %>:</dt>
24
+ <dd class="order-included_tax_total <%= "hidden" if @order.included_tax_total.zero? %>" id='included_tax_total'><%= @order.display_included_tax_total.to_html %></dd>
25
+
26
+ <dt class="order-additional_tax_total <%= "hidden" if @order.additional_tax_total.zero? %>" data-hook='admin_order_tab_additional_tax_title'><%= Spree::Order.human_attribute_name(:additional_tax_total) %>:</dt>
27
+ <dd class="order-additional_tax_total <%= "hidden" if @order.additional_tax_total.zero? %>" id='additional_tax_total'><%= @order.display_additional_tax_total.to_html %></dd>
28
+
29
+ <dt data-hook='admin_order_tab_total_title'><%= Spree::Order.human_attribute_name(:total) %>:</dt>
30
+ <dd id='order_total'><%= @order.display_total.to_html %></dd>
31
+
32
+ <% if @order.shipment_state %>
33
+ <dt class="order-shipment_state"><%= Spree::Shipment.model_name.human %>: </dt>
34
+ <dd class="order-shipment_state" id='shipment_status'>
35
+ <span class="pill pill-<%= @order.shipment_state %>">
36
+ <%= t(@order.shipment_state, scope: 'spree.shipment_states') %>
37
+ </span>
38
+ </dd>
39
+ <% end %>
40
+
41
+ <% if @order.payment_state %>
42
+ <dt class="order-payment_state"><%= Spree::Payment.model_name.human %>: </dt>
43
+ <dd class="order-payment_state" id='payment_status'>
44
+ <span class="pill pill-<%= @order.payment_state %>">
45
+ <%= t(@order.payment_state, scope: 'spree.payment_states') %>
46
+ </span>
47
+ </dd>
48
+ <% end %>
49
+
50
+ <% if @order.completed? %>
51
+ <dt data-hook='admin_order_tab_date_completed_title'><%= Spree::Order.human_attribute_name(:completed_at) %>:</dt>
52
+ <dd id='date_complete'><%= pretty_time(@order.completed_at) %></dd>
53
+ <% end %>
54
+
55
+ <% if @order.approved? %>
56
+ <dt><%= Spree::Order.human_attribute_name(:approver) %></dt>
57
+ <dd><%= @order.approver.try(:email) || @order.approver_name %></dd>
58
+ <dt><%= Spree::Order.human_attribute_name(:approved_at) %></dt>
59
+ <dd><%= pretty_time(@order.approved_at) %></dd>
60
+ <% end %>
61
+
62
+ <% if @order.canceled? && @order.canceler && @order.canceled_at %>
63
+ <dt><%= Spree::Order.human_attribute_name(:canceler) %></dt>
64
+ <dd><%= @order.canceler.email %></dd>
65
+ <dt><%= Spree::Order.human_attribute_name(:canceled_at) %></dt>
66
+ <dd><%= pretty_time(@order.canceled_at) %></dd>
67
+ <% end %>
68
+
69
+ <% if @order.solidus_bling_seller_id %>
70
+ <dt data-hook='admin_order_tab_seller_title'>Vendedor:</dt>
71
+ <dd id='seller'><%= ::SolidusBling::Seller.find_by(id: @order.solidus_bling_seller_id).name %></dd>
72
+ <% end %>
73
+ </dl>
74
+
75
+ </header>
@@ -120,27 +120,14 @@
120
120
  <% end %>
121
121
  </fieldset>
122
122
 
123
- <fieldset class="no-border-top">
123
+ <fieldset class="no-border-top text-center">
124
124
  <legend>
125
- Vendedores
125
+ Vendedor padrão
126
126
  </legend>
127
- <% bling_account.sellers.each do |seller| %>
128
- <%= form.fields_for :sellers do |seller_form| %>
129
- <div class="row">
130
- <div class="col-12 col-md-6">
131
- <div class="field">
132
- <%= seller_form.label :name, "Nome do Vendedor", class: 'required' %>
133
- <%= seller_form.text_field :name, required: true, class:"fullwidth" %>
134
- </div>
135
- </div>
136
- <div class="col-12 col-md-6">
137
- <div class="field">
138
- <%= seller_form.label :external_id, "ID Vendedor", class: 'required' %>
139
- <%= seller_form.text_field :external_id, required: true, class:"fullwidth" %>
140
- </div>
141
- </div>
142
- </div>
143
- <% end %>
127
+ <% if bling_account.sellers.default %>
128
+ <span><%= bling_account.sellers.default.name %></span>
129
+ <% else %>
130
+ <span>Vendedor padrão não selecionado</span>
144
131
  <% end %>
145
132
  </fieldset>
146
133
 
@@ -36,6 +36,9 @@
36
36
  <%= label_tag :refresh_token, "Refresh Token" %>
37
37
  <%= text_field_tag :refresh_token, account.refresh_token, class:"fullwidth", disabled: true %>
38
38
  </div>
39
+ <div class="field">
40
+ <%= button_to "Atualizar vendedores", upsert_sellers_admin_solidus_bling_accounts_path %>
41
+ </div>
39
42
  </div>
40
43
 
41
44
  <div class="col-12 col-md-6">
data/config/routes.rb CHANGED
@@ -3,9 +3,15 @@
3
3
  Spree::Core::Engine.routes.draw do
4
4
  # Add your extension routes here
5
5
  namespace :admin do
6
+ namespace :orders do
7
+ get "/:order_number/sellers", controller: "sellers", action: "edit", as: :seller
8
+ patch "/:order_number/sellers", controller: "sellers", action: "update", as: :update_seller
9
+ end
10
+
6
11
  namespace :solidus_bling do
7
12
  resources :accounts do
8
13
  get "authorize", on: :collection
14
+ post "upsert_sellers", on: :collection
9
15
  end
10
16
  resources :orders, only: [:update]
11
17
  end
@@ -0,0 +1,5 @@
1
+ class AddSolidusBlingSellerIdToOrders < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_reference :spree_orders, :solidus_bling_seller, foreign_key: true
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddDeafultColumnToSellers < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :solidus_bling_sellers, :default, :boolean, default: false
4
+ add_index :solidus_bling_sellers, :external_id, unique: true
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusBling
4
- VERSION = "3.2.9"
4
+ VERSION = "3.3.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_bling
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.9
4
+ version: 3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamilton Tumenas Borges
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-14 00:00:00.000000000 Z
11
+ date: 2024-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -86,7 +86,7 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '2.7'
89
- description:
89
+ description:
90
90
  email: hamiltontubo@gmail.com
91
91
  executables: []
92
92
  extensions: []
@@ -105,10 +105,12 @@ files:
105
105
  - LICENSE
106
106
  - README.md
107
107
  - Rakefile
108
+ - app/controllers/spree/admin/orders/sellers_controller.rb
108
109
  - app/controllers/spree/admin/solidus_bling/accounts_controller.rb
109
110
  - app/controllers/spree/admin/solidus_bling/orders_controller.rb
110
111
  - app/jobs/solidus_bling/application_job.rb
111
112
  - app/jobs/solidus_bling/order_job.rb
113
+ - app/jobs/solidus_bling/upsert_sellers_job.rb
112
114
  - app/models/solidus_bling/account.rb
113
115
  - app/models/solidus_bling/event.rb
114
116
  - app/models/solidus_bling/order.rb
@@ -116,7 +118,11 @@ files:
116
118
  - app/models/solidus_bling/seller.rb
117
119
  - app/models/solidus_bling/shipping_method.rb
118
120
  - app/models/solidus_bling/token.rb
121
+ - app/models/spree/permission_sets/seller_update.rb
119
122
  - app/subscribers/solidus_bling/subscriber.rb
123
+ - app/views/spree/admin/orders/sellers/edit.html.erb
124
+ - app/views/spree/admin/shared/_order_submenu.html.erb
125
+ - app/views/spree/admin/shared/_order_summary.html.erb
120
126
  - app/views/spree/admin/solidus_bling/accounts/_form.html.erb
121
127
  - app/views/spree/admin/solidus_bling/accounts/_link_auth.html.erb
122
128
  - app/views/spree/admin/solidus_bling/accounts/edit.html.erb
@@ -140,6 +146,8 @@ files:
140
146
  - db/migrate/20231110112958_create_solidus_bling_payment_methods.rb
141
147
  - db/migrate/20231110113122_create_solidus_bling_sellers.rb
142
148
  - db/migrate/20231110113221_create_solidus_bling_shipping_methods.rb
149
+ - db/migrate/20240318171147_add_solidus_bling_seller_id_to_orders.rb
150
+ - db/migrate/20240318180555_add_deafult_column_to_sellers.rb
143
151
  - lib/generators/solidus_bling/install/install_generator.rb
144
152
  - lib/generators/solidus_bling/install/templates/initializer.rb
145
153
  - lib/solidus_bling.rb
@@ -155,7 +163,7 @@ metadata:
155
163
  homepage_uri: https://github.com/hamiltontborges/solidus_bling#readme
156
164
  source_code_uri: https://github.com/hamiltontborges/solidus_bling
157
165
  changelog_uri: https://github.com/hamiltontborges/solidus_bling/blob/master/CHANGELOG.md
158
- post_install_message:
166
+ post_install_message:
159
167
  rdoc_options: []
160
168
  require_paths:
161
169
  - lib
@@ -173,8 +181,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
181
  - !ruby/object:Gem::Version
174
182
  version: '0'
175
183
  requirements: []
176
- rubygems_version: 3.4.6
177
- signing_key:
184
+ rubygems_version: 3.5.3
185
+ signing_key:
178
186
  specification_version: 4
179
187
  summary: Solidus extension to integrate with the Bling
180
188
  test_files: []