item_builder_mwh 0.1.23 → 0.1.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/item_builder_mwh/get_quantity_service.rb +15 -4
- data/lib/item_builder_mwh/lazada_quantity_service.rb +67 -0
- data/lib/item_builder_mwh/modes/quantity_service.rb +8 -3
- data/lib/item_builder_mwh/modes.rb +2 -0
- data/lib/item_builder_mwh/shopify_quantity_service.rb +16 -6
- data/lib/item_builder_mwh/version.rb +1 -1
- data/lib/item_builder_mwh.rb +26 -10
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04b4fda61b151bdae803aa466654125bfdd93fac256ba962ddcc7e7e5c05aed0
|
4
|
+
data.tar.gz: fd2c4433e919374acd2d64065791eca10fb554c10408bc75a207d6fc104734b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 457e75fd354af093c0cfcf399d3657f555e0efcd2e9dd5e791fc68a0c6d33c3308bf233653f582065ea960cc9336974c54d77dbb5127980a7114f2b08b1223f7
|
7
|
+
data.tar.gz: d8cda55e85a6777e3ea70711c980209c864af0ae0b6d760f28ec9d9893a54bf5a28db8c230b91650208d83edae3a9b05a72c44e4a129f053c616a87d0b1d4644
|
@@ -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
|
-
|
132
|
-
|
133
|
-
|
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
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'item_builder_mwh/modes.rb'
|
4
|
+
class ItemBuilderMwh
|
5
|
+
class LazadaQuantityService
|
6
|
+
attr_reader :listings, :skus
|
7
|
+
def initialize(args)
|
8
|
+
@listings = args.fetch(:listings)
|
9
|
+
@skus = args.fetch(:skus)
|
10
|
+
end
|
11
|
+
|
12
|
+
def perform
|
13
|
+
args = {
|
14
|
+
method: :post, url: url, payload: data, headers: headers
|
15
|
+
}
|
16
|
+
resp = JSON.parse(rest_client(args, [200, 500, 406]))
|
17
|
+
response_process(resp)
|
18
|
+
end
|
19
|
+
|
20
|
+
def headers
|
21
|
+
{ content_type: :json, accept: :json }
|
22
|
+
end
|
23
|
+
|
24
|
+
def data
|
25
|
+
{
|
26
|
+
"credential": JSON.parse(credential)['credential'],
|
27
|
+
"data": { "skus": skus.to_json }
|
28
|
+
}.to_json
|
29
|
+
end
|
30
|
+
|
31
|
+
def credential
|
32
|
+
return @credential if @credential
|
33
|
+
|
34
|
+
account_id = listings[0].profile_channel_association_id
|
35
|
+
host = ENV['CREDENTIAL_URL'] || raise('credential url is not set')
|
36
|
+
url = "#{host}/credential?account_id=#{account_id}"
|
37
|
+
@credential = rest_client(method: :get, url: url)
|
38
|
+
end
|
39
|
+
|
40
|
+
def url
|
41
|
+
url = ENV['API_GATEWAY_URL'] || raise('api gateway is not set')
|
42
|
+
url + '/lazada/items'
|
43
|
+
end
|
44
|
+
|
45
|
+
def response_process(resp)
|
46
|
+
hash = {}
|
47
|
+
resp['data']['products'].each do |product|
|
48
|
+
product['skus'].each do |sku|
|
49
|
+
qty = sku['multiWarehouseInventories'][0]
|
50
|
+
hash[sku['SellerSku']] = qty['occupyQuantity'] + qty['withholdQuantity']
|
51
|
+
end
|
52
|
+
end
|
53
|
+
hash
|
54
|
+
end
|
55
|
+
|
56
|
+
def rest_client(params, rescued_codes = 200)
|
57
|
+
RestClient::Request.execute(params.merge(timeout: 3)) do |response|
|
58
|
+
code = response.code
|
59
|
+
unless Array.wrap(rescued_codes).include?(code)
|
60
|
+
raise "Response Code is #{code}"
|
61
|
+
end
|
62
|
+
|
63
|
+
response
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -15,13 +15,16 @@ class ItemBuilderMwh
|
|
15
15
|
|
16
16
|
QUANTITY_CHANNEL = {}.tap do |hash|
|
17
17
|
hash[2] = :Shopify
|
18
|
+
hash[3] = :Lazada
|
18
19
|
hash[13] = :Zalora
|
19
20
|
hash[18] = :Zilingo
|
20
21
|
end.freeze
|
21
22
|
|
22
23
|
def perform
|
23
24
|
if channel_name == "Shopify"
|
24
|
-
|
25
|
+
dataSIL = shopify_inventory_location[listing.local_id]
|
26
|
+
|
27
|
+
base.merge!(dataSIL, warehouse: warehouses ) if dataSIL.present?
|
25
28
|
else
|
26
29
|
base.merge!(
|
27
30
|
warehouse: warehouses
|
@@ -31,7 +34,7 @@ class ItemBuilderMwh
|
|
31
34
|
|
32
35
|
def to_h(warehouse_space)
|
33
36
|
if channel_name == "Zilingo"
|
34
|
-
{
|
37
|
+
{
|
35
38
|
quantity: qty(warehouse_space.quantity),
|
36
39
|
warehouse_id: wh_mapping(
|
37
40
|
warehouse_space.warehouse_id
|
@@ -75,7 +78,9 @@ class ItemBuilderMwh
|
|
75
78
|
|
76
79
|
zalora_reserved_stock[listing.local_id].to_i
|
77
80
|
else
|
78
|
-
|
81
|
+
return 0 if lazada_quantity.blank?
|
82
|
+
|
83
|
+
lazada_quantity[listing.local_id].to_i
|
79
84
|
end
|
80
85
|
end
|
81
86
|
|
@@ -17,6 +17,7 @@ class ItemBuilderMwh
|
|
17
17
|
attr_reader :variant_listings
|
18
18
|
attr_reader :reserved_stocks
|
19
19
|
attr_reader :zilingo_quantity
|
20
|
+
attr_reader :lazada_quantity
|
20
21
|
attr_reader :zalora_reserved_stock
|
21
22
|
attr_reader :shopify_inventory_location
|
22
23
|
def initialize(args)
|
@@ -30,6 +31,7 @@ class ItemBuilderMwh
|
|
30
31
|
@variant_listings = args.fetch(:variant_listings, [])
|
31
32
|
@reserved_stocks = args.fetch(:reserved_stocks, [])
|
32
33
|
@zilingo_quantity = args.fetch(:zilingo_quantity, [])
|
34
|
+
@lazada_quantity = args.fetch(:lazada_quantity, [])
|
33
35
|
@zalora_reserved_stock = args.fetch(:zalora_reserved_stock, [])
|
34
36
|
@shopify_inventory_location = args.fetch(:shopify_inventory_location, {})
|
35
37
|
warehouse
|
@@ -14,9 +14,14 @@ class ItemBuilderMwh
|
|
14
14
|
def perform
|
15
15
|
datas = {}
|
16
16
|
@listings.each do |listing|
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
104
|
-
|
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
|
data/lib/item_builder_mwh.rb
CHANGED
@@ -8,6 +8,7 @@ require 'item_builder_mwh/modes/quantity_service'
|
|
8
8
|
require 'item_builder_mwh/modes/simple_service'
|
9
9
|
require 'item_models'
|
10
10
|
require 'item_builder_mwh/zilingo_quantity_service'
|
11
|
+
require 'item_builder_mwh/lazada_quantity_service'
|
11
12
|
require 'item_builder_mwh/zalora_quantity_service'
|
12
13
|
require 'item_builder_mwh/shopify_quantity_service'
|
13
14
|
|
@@ -37,6 +38,8 @@ class ItemBuilderMwh
|
|
37
38
|
|
38
39
|
def quantity_simple_mode
|
39
40
|
listings.map do |listing|
|
41
|
+
next unless listing.local_id.present?
|
42
|
+
|
40
43
|
if listing.channel_id == 18
|
41
44
|
new_param = qty_simple_params(listing)
|
42
45
|
.merge({zilingo_quantity: zilingo_quantity})
|
@@ -51,23 +54,30 @@ class ItemBuilderMwh
|
|
51
54
|
new_param = qty_simple_params(listing)
|
52
55
|
.merge({shopify_inventory_location: shopify_inventory_location})
|
53
56
|
|
57
|
+
modes[mode].new(new_param).perform
|
58
|
+
elsif listing.channel_id == 3
|
59
|
+
new_param = qty_simple_params(listing)
|
60
|
+
.merge({lazada_quantity: lazada_quantity})
|
61
|
+
|
54
62
|
modes[mode].new(new_param).perform
|
55
63
|
else
|
56
64
|
modes[mode].new(qty_simple_params(listing)).perform
|
57
65
|
end
|
58
|
-
end
|
66
|
+
end.compact
|
59
67
|
end
|
60
68
|
|
61
69
|
def default
|
62
70
|
listings.map do |listing|
|
63
|
-
if listing.
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
+
if listing.local_id.present?
|
72
|
+
if listing.channel_id == 2 && mode == :active
|
73
|
+
modes[mode].new(qty_simple_params(listing)).perform
|
74
|
+
elsif listing.channel_id == 18 && mode == :active
|
75
|
+
modes[mode].new(qty_simple_params(listing)
|
76
|
+
.merge(zilingo_quantity: zilingo_quantity)
|
77
|
+
).perform
|
78
|
+
else
|
79
|
+
modes[mode].new(listing: listing).perform
|
80
|
+
end
|
71
81
|
end
|
72
82
|
end
|
73
83
|
end
|
@@ -150,6 +160,12 @@ class ItemBuilderMwh
|
|
150
160
|
).perform
|
151
161
|
end
|
152
162
|
|
163
|
+
def lazada_quantity
|
164
|
+
@lazada_quantity ||= ItemBuilderMwh::LazadaQuantityService.new(
|
165
|
+
listings: listings, skus: skus
|
166
|
+
).perform
|
167
|
+
end
|
168
|
+
|
153
169
|
def order_host
|
154
170
|
url = ENV['ORDERS_URL'] || 'orders.forstok.com'
|
155
171
|
url + '/api/v3/item_line/reserved_stock'
|
@@ -176,6 +192,6 @@ class ItemBuilderMwh
|
|
176
192
|
end
|
177
193
|
|
178
194
|
def listings
|
179
|
-
@listings ||= VariantListing.where(id: listing_ids)
|
195
|
+
@listings ||= VariantListing.joins(:variant).where(id: listing_ids)
|
180
196
|
end
|
181
197
|
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.
|
4
|
+
version: 0.1.27
|
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-
|
11
|
+
date: 2021-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -117,6 +117,7 @@ extra_rdoc_files: []
|
|
117
117
|
files:
|
118
118
|
- lib/item_builder_mwh.rb
|
119
119
|
- lib/item_builder_mwh/get_quantity_service.rb
|
120
|
+
- lib/item_builder_mwh/lazada_quantity_service.rb
|
120
121
|
- lib/item_builder_mwh/modes.rb
|
121
122
|
- lib/item_builder_mwh/modes/active_service.rb
|
122
123
|
- lib/item_builder_mwh/modes/base_service.rb
|