item_builder 0.1.40 → 0.1.44

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9105f19ab628cbee42342b843bb2900ecb3d99d80036b2412c094d0a7386f2a1
4
- data.tar.gz: 52910c9fc720ea5932874ea1ea4fbb7d20eab29ccb3deb4b1f2a79f70e971725
3
+ metadata.gz: 20043fbc1916ef6f98c6429d101469353b46a0d9f8106be6ea94193a685aeb84
4
+ data.tar.gz: d4a1aefc9f150740af16fad42a5734088e3f584ce6b896a2c4b6b645fe4d629d
5
5
  SHA512:
6
- metadata.gz: 664f4c500f1b02523cec53db670303b0222d7fac1f160fac419a0f44dfa96c8cbcf386879ce6cdab42a8a41540a5339c651242e719684ed661ca21e2391e2499
7
- data.tar.gz: 0fd76898fc7610770498cbb58fa7d62d078189e6ed75f81df83db07e48c92c32af717bbf7dd0328b62b718628a0202e8fc13349b8802ba33ce75852c16a3300d
6
+ metadata.gz: 692cf4418adce24b9ff97045629804663b4043bf6bcf1305b87037f084d819b5d111a3674e79e1f4140e6aabe49d4107db13d94cebe2fe8fb4103ea785315f45
7
+ data.tar.gz: 1fc6d2ecb1425e180a7a069ca7f227fbb472664b50688be36176d5590e6ffa86d8ff4cc165eb3833df8d438fcf154f38bcab24e9a1bce199340feeaa8cb05ca9
@@ -122,9 +122,12 @@ class ItemBuilder
122
122
  end
123
123
 
124
124
  def params(allocated_stock)
125
- "channel_id=#{listing.channel_id}&item_variant_id=#{listing.variant_id}
126
- &start_at=#{allocated_stock.start_at.to_date.beginning_of_day}
127
- &end_at=#{allocated_stock.end_at.to_date.end_of_day}"
125
+ {
126
+ channel_id: allocated_stock.variant_listing.channel_id,
127
+ item_variant_id: allocated_stock.variant_listing.variant_id,
128
+ start_at: allocated_stock.start_at.to_date.beginning_of_day,
129
+ end_at: allocated_stock.end_at.to_date.end_of_day
130
+ }.to_query
128
131
  end
129
132
 
130
133
  # one_alloc_rsvd_stock fungsi untuk mendapatkan satu
@@ -13,7 +13,6 @@ class ItemBuilder
13
13
  include Modes
14
14
 
15
15
  QUANTITY_CHANNEL = {}.tap do |hash|
16
- hash[3] = :Lazada
17
16
  hash[2] = :Shopify
18
17
  hash[13] = :Zalora
19
18
  hash[18] = :Zilingo
@@ -21,7 +20,9 @@ class ItemBuilder
21
20
 
22
21
  def perform
23
22
  if channel_name == "Shopify"
24
- base.merge(to_h, shopify_inventory_location[listing.local_id])
23
+ dataSIL = shopify_inventory_location[listing.local_id]
24
+
25
+ base.merge(to_h, dataSIL) if dataSIL.present?
25
26
  else
26
27
  to_h.merge(base)
27
28
  end
@@ -13,11 +13,15 @@ class ItemBuilder
13
13
 
14
14
  def perform
15
15
  datas = {}
16
-
17
16
  @listings.each do |listing|
18
- @listing = listing
19
- @sku = listing.local_id
20
- datas[@sku] = response_process
17
+ if listing.local_id.present?
18
+ @listing = listing
19
+ @sku = listing.local_id
20
+ resp = response_process
21
+ next if resp[:inventory_item_id].nil? || resp[:inventory_item_id] == 0
22
+
23
+ datas[@sku] = resp
24
+ end
21
25
  end
22
26
 
23
27
  # update variant real_local_id database icava
@@ -98,8 +102,12 @@ class ItemBuilder
98
102
  def response_process
99
103
  hash = Hash.new
100
104
 
101
- hash[:inventory_item_id] = inventory_item_id.to_i
102
- hash[:location_id] = location_id.to_i
105
+ begin
106
+ hash[:inventory_item_id] = inventory_item_id.to_i
107
+ hash[:location_id] = location_id.to_i
108
+ rescue
109
+ hash
110
+ end
103
111
 
104
112
  hash
105
113
  end
@@ -107,8 +115,9 @@ class ItemBuilder
107
115
  def rest_client(params, rescued_codes = 200)
108
116
  RestClient::Request.execute(params.merge(timeout: 3)) do |response|
109
117
  code = response.code
118
+ resp = response.body.to_str
110
119
  unless Array.wrap(rescued_codes).include?(code)
111
- raise "Response Code is #{code}"
120
+ raise "Response Code is #{code}" unless resp.include?('Response code = 404')
112
121
  end
113
122
 
114
123
  response
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ItemBuilder
4
- VERSION = '0.1.40'
4
+ VERSION = '0.1.44'
5
5
  end
@@ -47,6 +47,8 @@ class ItemBuilder
47
47
  raise "Response Code is #{resp.dig('response_code')}"
48
48
  elsif resp.dig('ErrorResponse', 'Head', 'ErrorMessage') == 'E009: Access Denied'
49
49
  return nil
50
+ elsif resp.dig('ErrorResponse').present?
51
+ return nil
50
52
  end
51
53
 
52
54
  success_handle(resp)
data/lib/item_builder.rb CHANGED
@@ -38,6 +38,8 @@ class ItemBuilder
38
38
 
39
39
  def quantity_simple_mode
40
40
  listings.map do |listing|
41
+ next unless listing.local_id.present?
42
+
41
43
  if listing.channel_id == 18
42
44
  new_param = qty_simple_params(listing)
43
45
  .merge(zilingo_quantity: zilingo_quantity)
@@ -56,7 +58,7 @@ class ItemBuilder
56
58
  else
57
59
  modes[mode].new(qty_simple_params(listing)).perform
58
60
  end
59
- end
61
+ end.compact
60
62
  end
61
63
 
62
64
  def qty_simple_params(listing)
@@ -71,6 +73,8 @@ class ItemBuilder
71
73
 
72
74
  def default
73
75
  listings.map do |listing|
76
+ next unless listing.local_id.present?
77
+
74
78
  if listing.channel_id == 2 && mode == :active
75
79
  modes[mode].new(qty_simple_params(listing)).perform
76
80
  elsif listing.channel_id == 18 && mode == :active
@@ -130,7 +134,7 @@ class ItemBuilder
130
134
  end
131
135
 
132
136
  def listings
133
- @listings ||= VariantListing.where(id: listing_ids)
137
+ @listings ||= VariantListing.joins(:variant).where(id: listing_ids)
134
138
  end
135
139
 
136
140
  def skus
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: item_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.40
4
+ version: 0.1.44
5
5
  platform: ruby
6
6
  authors:
7
7
  - okaaryanata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-06 00:00:00.000000000 Z
11
+ date: 2021-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  requirements: []
168
- rubygems_version: 3.0.9
168
+ rubygems_version: 3.2.3
169
169
  signing_key:
170
170
  specification_version: 4
171
171
  summary: Item builder