Skip to content

Commit ca52d29

Browse files
authored
Merge pull request #242 from Purple-Stock/staging
create localization to bling order items
2 parents c45454d + 4eeee76 commit ca52d29

File tree

5 files changed

+43
-19
lines changed

5 files changed

+43
-19
lines changed

app/jobs/order_items_job.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def perform(bling_order_id)
55
record = BlingOrderItem.find_by(bling_order_id:)
66
account_id = record.account_id
77
items_attributes = []
8+
label_attributes = []
89
order = Services::Bling::FindOrder.call(id: bling_order_id, order_command: 'find_order', tenant: account_id)
910
raise(StandardError, order['error']) if order['error'].present?
1011

@@ -23,7 +24,23 @@ def perform(bling_order_id)
2324
}
2425
end
2526

27+
label = order['data']['transporte']['etiqueta']
28+
29+
label_attributes << {
30+
name: label['nome'],
31+
address: label['endereco'],
32+
number: label['numero'],
33+
complement: label['complemento'],
34+
city: label['municipio'],
35+
state: label['uf'],
36+
zip_code: label['cep'],
37+
neighborhood: label['bairro'],
38+
country_name: label['nomePais'],
39+
account_id:
40+
}
41+
2642
record.items.build(items_attributes)
43+
record.build_localization(label_attributes.first)
2744
record.save!
2845
end
2946
end

app/models/bling_order_item.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@
2828
#
2929
# Indexes
3030
#
31+
# bling_order_id_index_on_bling_order_items (bling_order_id)
3132
# index_bling_order_items_on_account_id (account_id)
3233
# index_bling_order_items_on_bling_order_id (bling_order_id) UNIQUE
34+
# situation_id_index_on_bling_order_items (situation_id,store_id)
3335
#
3436
class BlingOrderItem < ApplicationRecord
3537
# TODO, refactor me separating the tables
3638
# There are features hard to implement without this separation.
3739

3840
has_many :items, dependent: :destroy
41+
has_one :localization, dependent: :destroy
3942
belongs_to :account, optional: true
4043

4144
accepts_nested_attributes_for :items

app/models/localization.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Localization < ApplicationRecord
2+
belongs_to :account
3+
belongs_to :bling_order_item, optional: false
4+
end

app/views/home/index.html.erb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,4 @@
118118
setInterval(function() {
119119
window.location.reload();
120120
}, 60000);
121-
$(document).ready(function (){
122-
let isHidden = true;
123-
124-
$('#eye-slash, #eye').click(function (){
125-
if(isHidden) {
126-
$('#revenue-estimation').removeAttr('hidden');
127-
$('#average-ticket').removeAttr('hidden');
128-
$('.bi-eye').removeAttr('hidden');
129-
$('.bi-eye-slash').attr('hidden', true);
130-
isHidden = false;
131-
} else {
132-
$('#revenue-estimation').attr('hidden', true);
133-
$('#average-ticket').attr('hidden', true);
134-
$('.bi-eye').attr('hidden', true)
135-
$('.bi-eye-slash').removeAttr('hidden');
136-
isHidden = true;
137-
}
138-
});
139-
})
140121
</script>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class CreateLocalizations < ActiveRecord::Migration[7.0]
2+
def change
3+
create_table :localizations do |t|
4+
t.string :name
5+
t.string :address
6+
t.string :number
7+
t.string :complement
8+
t.string :city
9+
t.string :state
10+
t.string :zip_code
11+
t.string :neighborhood
12+
t.string :country_name
13+
t.integer :account_id
14+
t.bigint :bling_order_item_id
15+
16+
t.timestamps
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)