Skip to content

Commit 8b70929

Browse files
Merge pull request #148 from Purple-Stock/staging
Staging
2 parents 71f844c + 9ca9ae7 commit 8b70929

21 files changed

+730
-105
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ jobs:
66
runs-on: ubuntu-latest
77

88
services:
9+
redis:
10+
image: redis
11+
options: >-
12+
--health-cmd "redis-cli ping"
13+
--health-interval 10s
14+
--health-timeout 5s
15+
--health-retries 5
16+
ports:
17+
- 6379:6379
918
postgres:
1019
image: postgres:13
1120
env:
@@ -61,4 +70,6 @@ jobs:
6170
env:
6271
RAILS_ENV: test
6372
DATABASE_URL: postgres://postgres:postgres@localhost:5432/inventory-control_test
73+
REDIS_HOST: localhost
74+
REDIS_PORT: 6379
6475
run: bundle exec rspec

app/controllers/bling_order_items_controller.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ def update
1717
end
1818
end
1919

20+
def destroy
21+
if resource.deleted_at_bling!
22+
redirect_to resource, notice: t('flash.success.destroy.bling_order_item')
23+
else
24+
redirect_to resource, alert: t('flash.failure.destroy.bling_order_item')
25+
end
26+
end
27+
2028
protected
2129

2230
def collection

app/enumerations/bling_order_item_status.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class BlingOrderItemStatus < EnumerateIt::Base
1010
pending: '94871',
1111
printed: '95745',
1212
canceled: '12',
13-
collected: '173631'
13+
collected: '173631',
14+
deleted_at_bling: '0',
15+
delete_in_progress: '-1'
1416
)
1517
end

app/javascript/application.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,4 @@ document.addEventListener("turbo:load", () => {
7979
altFormat: "d/m/Y H:i",
8080
});
8181
});
82+
import "@hotwired/turbo-rails"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class BlingOrderItemDestroyerJob < ApplicationJob
2+
def perform(bling_order_id)
3+
order = BlingOrderItem.find_by(bling_order_id:)
4+
if order.not_found_at_bling?
5+
order.update(situation_id: BlingOrderItemStatus::DELETED_AT_BLING)
6+
else
7+
order.update(situation_id: order.original_situation_id)
8+
end
9+
end
10+
end

app/models/bling_order_item.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# bling_id :integer
2323
# bling_order_id :string
2424
# marketplace_code_id :string
25+
# original_situation_id :string
2526
# situation_id :string
2627
# store_id :string
2728
#
@@ -45,6 +46,8 @@ class BlingOrderItem < ApplicationRecord
4546
has_enumeration_for :situation_id, with: BlingOrderItemStatus, skip_validation: true
4647
has_enumeration_for :store_id, with: BlingOrderItemStore, skip_validation: true
4748

49+
after_update_commit -> { broadcast_update_to self, partial: 'bling_order_items/bling_order_item_content', target: "bling_order_item_#{id}" if saved_change_to_situation_id? }
50+
4851
ANOTHER_SHEIN_STORE_ID = '204114350'
4952
SHEIN_STORE_ID = '204219105'
5053

@@ -165,6 +168,13 @@ def collected!
165168
update(situation_id: 173_631)
166169
end
167170

171+
def deleted_at_bling!
172+
return if processing_deletion?
173+
174+
update(situation_id: BlingOrderItemStatus::DELETE_IN_PROGRESS, original_situation_id: situation_id_was)
175+
BlingOrderItemDestroyerJob.perform_later(bling_order_id)
176+
end
177+
168178
def value
169179
super || 0.0
170180
end
@@ -181,8 +191,22 @@ def self.bulk_synchronize_items(collection)
181191
end
182192
end
183193

194+
def not_found_at_bling?
195+
result = Services::Bling::FindOrder.call(id: bling_order_id, order_command: 'find_order', tenant: account_id)
196+
if result['error'].present? && result['error']['type'] != 'RESOURCE_NOT_FOUND'
197+
raise StandardError, result['error']['type']
198+
end
199+
200+
result.dig('error', 'type') == 'RESOURCE_NOT_FOUND'
201+
end
202+
184203
private
185204

205+
def processing_deletion?
206+
situation_id.eql?(BlingOrderItemStatus::DELETED_AT_BLING)\
207+
|| situation_id.eql?(BlingOrderItemStatus::DELETE_IN_PROGRESS)
208+
end
209+
186210
def keep_old_collected_alteration_date
187211
return unless collected_alteration_date_was.present? && collected_alteration_date_changed?
188212

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<section class="main-content">
2+
<h1><%= bling_order_item.decorate.title %></h1>
3+
<hr>
4+
<table class="zebra-table">
5+
<tr>
6+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:situation_id) %></th>
7+
<td class="col-sm-4"><%= bling_order_item.decorate.situation_id %></td>
8+
</tr>
9+
<tr>
10+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:codigo) %></th>
11+
<td class="col-sm-4"><%= bling_order_item.decorate.codigo %></td>
12+
</tr>
13+
<tr>
14+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:unidade) %></th>
15+
<td class="col-sm-4"><%= bling_order_item.decorate.unidade %></td>
16+
</tr>
17+
<tr>
18+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:quantidade) %></th>
19+
<td class="col-sm-4"><%= bling_order_item.decorate.quantidade %></td>
20+
</tr>
21+
<tr>
22+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:desconto) %></th>
23+
<td class="col-sm-4"><%= bling_order_item.decorate.desconto %></td>
24+
</tr>
25+
<tr>
26+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:valor) %></th>
27+
<td class="col-sm-4"><%= bling_order_item.decorate.valor %></td>
28+
</tr>
29+
<tr>
30+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:aliquotaIPI) %></th>
31+
<td class="col-sm-4"><%= bling_order_item.decorate.aliquotaIPI %></td>
32+
</tr>
33+
<tr>
34+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:descricao) %></th>
35+
<td class="col-sm-4"><%= bling_order_item.decorate.descricao %></td>
36+
</tr>
37+
<tr>
38+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:descricaoDetalhada) %></th>
39+
<td class="col-sm-4"><%= bling_order_item.decorate.descricaoDetalhada %></td>
40+
</tr>
41+
<tr>
42+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:store_id) %></th>
43+
<td class="col-sm-4"><%= bling_order_item.decorate.store_id %></td>
44+
</tr>
45+
<tr>
46+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:created_at) %></th>
47+
<td class="col-sm-4"><%= bling_order_item.decorate.created_at %></td>
48+
</tr>
49+
<tr>
50+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:updated_at) %></th>
51+
<td class="col-sm-4"><%= bling_order_item.decorate.updated_at %></td>
52+
</tr>
53+
<tr>
54+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:date) %></th>
55+
<td class="col-sm-4"><%= bling_order_item.decorate.date %></td>
56+
</tr>
57+
<tr>
58+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:alteration_date) %></th>
59+
<td class="col-sm-4"><%= bling_order_item.decorate.alteration_date %></td>
60+
</tr>
61+
<tr>
62+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:marketplace_code_id) %></th>
63+
<td class="col-sm-4"><%= bling_order_item.decorate.marketplace_code_id %></td>
64+
</tr>
65+
<tr>
66+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:bling_id) %></th>
67+
<td class="col-sm-4"><%= bling_order_item.decorate.bling_id %></td>
68+
</tr>
69+
<tr>
70+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:account_id) %></th>
71+
<td class="col-sm-4"><%= bling_order_item.decorate.account_id %></td>
72+
</tr>
73+
<tr>
74+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:value) %></th>
75+
<td class="col-sm-4"><%= bling_order_item.decorate.value %></td>
76+
</tr>
77+
<tr>
78+
<th class="col-sm-8"><%= bling_order_item.decorate.human_attribute(:collected_alteration_date) %></th>
79+
<td class="col-sm-4"><%= bling_order_item.decorate.collected_alteration_date %></td>
80+
</tr>
81+
</table>
82+
<div class="mt-4">
83+
<%= link_to t('helpers.links.back'), bling_order_items_path, class: 'btn btn-primary btn-lg col-xs-12 col-sm-3 col-md-auto my-1 mx-md-1' %>
84+
<%= link_to t('.edit', :default => t("helpers.links.edit")),
85+
edit_bling_order_item_path(bling_order_item), :class => 'btn btn-dark btn-lg col-xs-12 col-sm-3 col-md-auto my-1 mx-md-1' %>
86+
<%= link_to t('.destroy', :default => t("helpers.links.destroy")),
87+
bling_order_item_path(bling_order_item),
88+
title: t('destroy'), class: 'btn btn-danger btn-lg col-xs-12 col-sm-3 col-md-auto my-1 mx-md-1',
89+
method: :delete,
90+
data: { toggle: 'tooltip', turbo: true, turbo_method: :delete } %>
91+
</div>
92+
</section>
Lines changed: 4 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,4 @@
1-
<section class="main-content">
2-
<h1><%= bling_order_item.title %></h1>
3-
<hr>
4-
<table class="zebra-table">
5-
<tr>
6-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:situation_id) %></th>
7-
<td class="col-sm-4"><%= bling_order_item.situation_id %></td>
8-
</tr>
9-
<tr>
10-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:codigo) %></th>
11-
<td class="col-sm-4"><%= bling_order_item.codigo %></td>
12-
</tr>
13-
<tr>
14-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:unidade) %></th>
15-
<td class="col-sm-4"><%= bling_order_item.unidade %></td>
16-
</tr>
17-
<tr>
18-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:quantidade) %></th>
19-
<td class="col-sm-4"><%= bling_order_item.quantidade %></td>
20-
</tr>
21-
<tr>
22-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:desconto) %></th>
23-
<td class="col-sm-4"><%= bling_order_item.desconto %></td>
24-
</tr>
25-
<tr>
26-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:valor) %></th>
27-
<td class="col-sm-4"><%= bling_order_item.valor %></td>
28-
</tr>
29-
<tr>
30-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:aliquotaIPI) %></th>
31-
<td class="col-sm-4"><%= bling_order_item.aliquotaIPI %></td>
32-
</tr>
33-
<tr>
34-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:descricao) %></th>
35-
<td class="col-sm-4"><%= bling_order_item.descricao %></td>
36-
</tr>
37-
<tr>
38-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:descricaoDetalhada) %></th>
39-
<td class="col-sm-4"><%= bling_order_item.descricaoDetalhada %></td>
40-
</tr>
41-
<tr>
42-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:store_id) %></th>
43-
<td class="col-sm-4"><%= bling_order_item.store_id %></td>
44-
</tr>
45-
<tr>
46-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:created_at) %></th>
47-
<td class="col-sm-4"><%= bling_order_item.created_at %></td>
48-
</tr>
49-
<tr>
50-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:updated_at) %></th>
51-
<td class="col-sm-4"><%= bling_order_item.updated_at %></td>
52-
</tr>
53-
<tr>
54-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:date) %></th>
55-
<td class="col-sm-4"><%= bling_order_item.date %></td>
56-
</tr>
57-
<tr>
58-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:alteration_date) %></th>
59-
<td class="col-sm-4"><%= bling_order_item.alteration_date %></td>
60-
</tr>
61-
<tr>
62-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:marketplace_code_id) %></th>
63-
<td class="col-sm-4"><%= bling_order_item.marketplace_code_id %></td>
64-
</tr>
65-
<tr>
66-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:bling_id) %></th>
67-
<td class="col-sm-4"><%= bling_order_item.bling_id %></td>
68-
</tr>
69-
<tr>
70-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:account_id) %></th>
71-
<td class="col-sm-4"><%= bling_order_item.account_id %></td>
72-
</tr>
73-
<tr>
74-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:value) %></th>
75-
<td class="col-sm-4"><%= bling_order_item.value %></td>
76-
</tr>
77-
<tr>
78-
<th class="col-sm-8"><%= bling_order_item.human_attribute(:collected_alteration_date) %></th>
79-
<td class="col-sm-4"><%= bling_order_item.collected_alteration_date %></td>
80-
</tr>
81-
</table>
82-
<div class="mt-4">
83-
<%= link_to t('helpers.links.back'), bling_order_items_path, class: 'btn btn-primary btn-lg col-xs-12 col-sm-3 col-md-auto my-1 mx-md-1' %>
84-
<%= link_to t('.edit', :default => t("helpers.links.edit")),
85-
edit_bling_order_item_path(@bling_order_item), :class => 'btn btn-dark btn-lg col-xs-12 col-sm-3 col-md-auto my-1 mx-md-1' %>
86-
<%= link_to t('.destroy', :default => t("helpers.links.destroy")),
87-
bling_order_item_path(@bling_order_item),
88-
title: t('destroy'), class: 'btn btn-danger btn-lg col-xs-12 col-sm-3 col-md-auto my-1 mx-md-1',
89-
method: :delete,
90-
data: { toggle: 'tooltip', turbo: true, turbo_method: :delete, turbo_confirm: t('confirm') } %>
91-
</div>
92-
</section>
1+
<%= turbo_stream_from @bling_order_item.decorate %>
2+
<div id="<%= dom_id @bling_order_item %>">
3+
<%= render 'bling_order_item_content', bling_order_item: @bling_order_item %>
4+
</div>

config/cable.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
development:
2+
adapter: redis
3+
url: <%= ENV['REDIS_URL'] %>
4+
test:
5+
adapter: redis
6+
url: <%= ENV['REDIS_URL'] %>
7+
production:
8+
adapter: redis
9+
url: <%= ENV['REDIS_URL'] %>

config/locales/pt-BR.models.bling_order_items.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
---
22
pt-BR:
3+
flash:
4+
success:
5+
destroy:
6+
bling_order_item: A verificar Pedido de compra junto à Bling
7+
failure:
8+
destroy:
9+
bling_order_item: Pedido já em processo de deletar!
310
enumerations:
411
bling_order_item_store:
512
all: Todas as Lojas
@@ -12,6 +19,8 @@ pt-BR:
1219
printed: Impresso
1320
canceled: Cancelado
1421
collected: Coletado
22+
delete_in_progress: Processando Deletar Pedido
23+
deleted_at_bling: Deletado da Bling
1524
activerecord:
1625
errors:
1726
models:

0 commit comments

Comments
 (0)