Skip to content

Commit 4dddd44

Browse files
Merge pull request #43 from Purple-Stock/feat/add-items-to-count
Feat/add items to count
2 parents 49389b5 + 9cfcad8 commit 4dddd44

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

app/jobs/order_items_job.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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

app/models/bling_order_item.rb

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,6 @@ def value
131131
end
132132

133133
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)
153135
end
154136
end

0 commit comments

Comments
 (0)