File tree Expand file tree Collapse file tree 2 files changed +30
-19
lines changed Expand file tree Collapse file tree 2 files changed +30
-19
lines changed Original file line number Diff line number Diff line change
1
+ class OrderItemsJob < ApplicationJob
2
+ queue_as :default
3
+ retry_on StandardError , attempts : 5 , wait : :exponentially_longer
4
+
5
+ def perform ( record )
6
+ account_id = record . account_id
7
+ items_attributes = [ ]
8
+ order = Services ::Bling ::FindOrder . call ( id : record . bling_order_id , order_command : 'find_order' , tenant : account_id )
9
+ raise StandardError if order [ 'error' ] . present?
10
+
11
+ order [ 'data' ] [ 'itens' ] . each do |item |
12
+ items_attributes << {
13
+ sku : item [ 'codigo' ] ,
14
+ unity : item [ 'unidade' ] ,
15
+ quantity : item [ 'quantidade' ] ,
16
+ discount : item [ 'desconto' ] ,
17
+ value : item [ 'valor' ] ,
18
+ ipi_tax : item [ 'aliquotaIPI' ] ,
19
+ description : item [ 'descricao' ] ,
20
+ long_description : item [ 'descricaoDetalhada' ] ,
21
+ product_id : item [ 'produto' ] [ 'id' ] ,
22
+ account_id :
23
+ }
24
+ end
25
+
26
+ record . items . build ( items_attributes )
27
+ record . save!
28
+ end
29
+ end
Original file line number Diff line number Diff line change @@ -131,24 +131,6 @@ def value
131
131
end
132
132
133
133
def synchronize_items
134
- items_attributes = [ ]
135
- order = Services ::Bling ::FindOrder . new ( id : bling_order_id , order_command : 'find_order' , tenant : account . id ) . call
136
- order [ 'data' ] [ 'itens' ] . each do |item |
137
- items_attributes << {
138
- sku : item [ 'codigo' ] ,
139
- unity : item [ 'unidade' ] ,
140
- quantity : item [ 'quantidade' ] ,
141
- discount : item [ 'desconto' ] ,
142
- value : item [ 'valor' ] ,
143
- ipi_tax : item [ 'aliquotaIPI' ] ,
144
- description : item [ 'descricao' ] ,
145
- long_description : item [ 'descricaoDetalhada' ] ,
146
- product_id : item [ 'produto' ] [ 'id' ] ,
147
- account_id : account . id
148
- }
149
- end
150
-
151
- items . build ( items_attributes )
152
- save
134
+ OrderItemsJob . perform_later ( self )
153
135
end
154
136
end
You can’t perform that action at this time.
0 commit comments