item_builder_mwh 0.1.22 → 0.1.26

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: 2ce875fe2672b2be68449789dcf099b3566125f560988d201b1f50bae3e839c2
4
- data.tar.gz: 8a7b0b805534e368789e9a9da3168a7ac8d80e428caec01c2d8ccf4e8f71b108
3
+ metadata.gz: 7e01aa6ef954cf51bc3dcb92ca26f17d430c4ea1fc51d4ef8c90fecfc990f0fd
4
+ data.tar.gz: f11f2141638776fa7aa54fed48488b4b5435288dcd9367290d51443963d2434b
5
5
  SHA512:
6
- metadata.gz: 812acaa9c7b3d627147b3a9f3eb191bbea433ae85b07c3509bfc578dc843dae446e45196d67d3c2a15856839c966b59b78351ec968527cf3806fb7880be45121
7
- data.tar.gz: 5a9dfb30c053393f8ef5502a708d877d68d773ab4fe7b8d4962d09814ad557e8f3cfd4f5b7cf57c3164ae6033c12ffcca51399d5686b3f5bf9d03c1b0e87f1cc
6
+ metadata.gz: 6fff1385a38d7539f9ecf9776fb3fd2d6bc06047035cae7f529b9e5f11bb4de9107a21b1dca457a579d3fb6b59bcec691b0b5799b37ef5e98a40d45cb96e4982
7
+ data.tar.gz: 5e8dea305c73d37530197d3506d5f9a697c35e4690281d96465e93b0f65d59ad73f8ca20897fae1bdcc4ccee0b10f600d419968a7f596aeb977cafa06d305f03
@@ -79,10 +79,18 @@ class ItemBuilderMwh
79
79
  end
80
80
 
81
81
  def listing_warehouse_routing_quantity
82
- warehouse_spaces = WarehouseSpace.where(item_variant_id: variant.id)
82
+ warehouse_spaces = WarehouseSpace.where(item_variant_id: variant.id, warehouse_id: wh_ids)
83
83
  warehouse_spaces.sum(:quantity)
84
84
  end
85
85
 
86
+ def wh_mappings
87
+ WarehouseMapping.where(profile_channel_association_id: listing.profile_channel_association_id)
88
+ end
89
+
90
+ def wh_ids
91
+ @wh_ids ||= wh_mappings.map{|x|x.warehouse_id}.flatten.uniq
92
+ end
93
+
86
94
  def qty_bundle
87
95
  # Quantity for bundle config
88
96
  if @bundle_variants.present?
@@ -128,9 +136,12 @@ class ItemBuilderMwh
128
136
  end
129
137
 
130
138
  def params(allocated_stock)
131
- "channel_id=#{listing.channel_id}&item_variant_id=#{listing.variant_id}
132
- &start_at=#{allocated_stock.start_at.to_date.beginning_of_day}
133
- &end_at=#{allocated_stock.end_at.to_date.end_of_day}"
139
+ {
140
+ channel_id: allocated_stock.variant_listing.channel_id,
141
+ item_variant_id: allocated_stock.variant_listing.variant_id,
142
+ start_at: allocated_stock.start_at.to_date.beginning_of_day,
143
+ end_at: allocated_stock.end_at.to_date.end_of_day
144
+ }.to_query
134
145
  end
135
146
 
136
147
  # one_alloc_rsvd_stock fungsi untuk mendapatkan satu
@@ -21,7 +21,9 @@ class ItemBuilderMwh
21
21
 
22
22
  def perform
23
23
  if channel_name == "Shopify"
24
- base.merge!(shopify_inventory_location[listing.local_id], warehouse: warehouses )
24
+ dataSIL = shopify_inventory_location[listing.local_id]
25
+
26
+ base.merge!(dataSIL, warehouse: warehouses ) if dataSIL.present?
25
27
  else
26
28
  base.merge!(
27
29
  warehouse: warehouses
@@ -31,7 +33,7 @@ class ItemBuilderMwh
31
33
 
32
34
  def to_h(warehouse_space)
33
35
  if channel_name == "Zilingo"
34
- {
36
+ {
35
37
  quantity: qty(warehouse_space.quantity),
36
38
  warehouse_id: wh_mapping(
37
39
  warehouse_space.warehouse_id
@@ -14,9 +14,14 @@ class ItemBuilderMwh
14
14
  def perform
15
15
  datas = {}
16
16
  @listings.each do |listing|
17
- @listing = listing
18
- @sku = listing.local_id
19
- 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
20
25
  end
21
26
 
22
27
  # update variant real_local_id database icava
@@ -100,8 +105,12 @@ class ItemBuilderMwh
100
105
  def response_process
101
106
  hash = Hash.new
102
107
 
103
- hash[:inventory_item_id] = inventory_item_id.to_i
104
- hash[:location_id] = location_id.to_i
108
+ begin
109
+ hash[:inventory_item_id] = inventory_item_id.to_i
110
+ hash[:location_id] = location_id.to_i
111
+ rescue
112
+ hash
113
+ end
105
114
 
106
115
  hash
107
116
  end
@@ -109,8 +118,9 @@ class ItemBuilderMwh
109
118
  def rest_client(params, rescued_codes = 200)
110
119
  RestClient::Request.execute(params.merge(timeout: 3)) do |response|
111
120
  code = response.code
121
+ resp = response.body.to_str
112
122
  unless Array.wrap(rescued_codes).include?(code)
113
- raise "Response Code is #{code}"
123
+ raise "Response Code is #{code}" unless resp.include?('Response code = 404')
114
124
  end
115
125
 
116
126
  response
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ItemBuilderMwh
4
- VERSION = '0.1.22'
4
+ VERSION = '0.1.26'
5
5
  end
@@ -47,6 +47,8 @@ class ItemBuilderMwh
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
  success_handle(resp)
52
54
  end
@@ -37,6 +37,8 @@ class ItemBuilderMwh
37
37
 
38
38
  def quantity_simple_mode
39
39
  listings.map do |listing|
40
+ next unless listing.local_id.present?
41
+
40
42
  if listing.channel_id == 18
41
43
  new_param = qty_simple_params(listing)
42
44
  .merge({zilingo_quantity: zilingo_quantity})
@@ -55,19 +57,21 @@ class ItemBuilderMwh
55
57
  else
56
58
  modes[mode].new(qty_simple_params(listing)).perform
57
59
  end
58
- end
60
+ end.compact
59
61
  end
60
62
 
61
63
  def default
62
64
  listings.map do |listing|
63
- if listing.channel_id == 2 && mode == :active
64
- modes[mode].new(qty_simple_params(listing)).perform
65
- elsif listing.channel_id == 18 && mode == :active
66
- modes[mode].new(qty_simple_params(listing)
67
- .merge(zilingo_quantity: zilingo_quantity)
68
- ).perform
69
- else
70
- modes[mode].new(listing: listing).perform
65
+ if listing.local_id.present?
66
+ if listing.channel_id == 2 && mode == :active
67
+ modes[mode].new(qty_simple_params(listing)).perform
68
+ elsif listing.channel_id == 18 && mode == :active
69
+ modes[mode].new(qty_simple_params(listing)
70
+ .merge(zilingo_quantity: zilingo_quantity)
71
+ ).perform
72
+ else
73
+ modes[mode].new(listing: listing).perform
74
+ end
71
75
  end
72
76
  end
73
77
  end
@@ -176,6 +180,6 @@ class ItemBuilderMwh
176
180
  end
177
181
 
178
182
  def listings
179
- @listings ||= VariantListing.where(id: listing_ids)
183
+ @listings ||= VariantListing.joins(:variant).where(id: listing_ids)
180
184
  end
181
185
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: item_builder_mwh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.22
4
+ version: 0.1.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Ivander
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-09 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 Multiwarehouse