item_builder_mwh 0.1.11 → 0.1.16

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: 89d5e20049b164c7a4cc3e29f928a4518378294d36aeb683f0a4af884dd5ca60
4
- data.tar.gz: 49bf961845d57d9af626bf10904dd81b142c049c7515bc8145488a7cf6950fd8
3
+ metadata.gz: 9267900d48fc70b5b7c41943cda2dde2b7a1c5732c26085bf2411e0683fe677a
4
+ data.tar.gz: bd40a5dfc2a2f9dfbc4278e59bdd795e8b375666e466faf641b9235fccbcfba3
5
5
  SHA512:
6
- metadata.gz: 1afa288d9ba3c158798fb6a09a9b5e76fd04515fc81eb97e81e6ddcd37222a5094ee912a06fddc769aa27e17c09be601be51803a7e79b3b17bd8ea06a613cf82
7
- data.tar.gz: 69c88f5ccdfa9672745822f683467147d43155cfaafed58e1ad4b56b5e5acec583e514e864019b525b495cc1e469c94852dfbcfc96a0e2e10d91f3c86e2a8630
6
+ metadata.gz: 9beefb0a4650bf6bdf4d5ff7613c220b503764091395573de87f09ad2db2208ff5e6cc329384c36ae76252ad44cfc88fb86929d78b17b96dcf525491e0663f49
7
+ data.tar.gz: 9303229b16cb1fee06661b10103e85602eb465b56d25a0336cc5663011013ac0e7e4f5da6b8f32b4cba6fd2144fbbd371b124a4bf9876b7f55692f5f17f303ad
@@ -7,6 +7,8 @@ require 'item_builder_mwh/modes/price_service'
7
7
  require 'item_builder_mwh/modes/quantity_service'
8
8
  require 'item_builder_mwh/modes/simple_service'
9
9
  require 'item_models'
10
+ require 'item_builder_mwh/zilingo_quantity_service'
11
+ require 'item_builder_mwh/zalora_quantity_service'
10
12
 
11
13
  class ItemBuilderMwh
12
14
  attr_reader :listing_ids
@@ -34,7 +36,19 @@ class ItemBuilderMwh
34
36
 
35
37
  def quantity_simple_mode
36
38
  listings.map do |listing|
37
- modes[mode].new(qty_simple_params(listing)).perform
39
+ if listing.channel_id == 18
40
+ new_param = qty_simple_params(listing)
41
+ .merge({zilingo_delta_quantity: zilingo_delta_quantity})
42
+
43
+ modes[mode].new(new_param).perform
44
+ elsif listing.channel_id == 13
45
+ new_param = qty_simple_params(listing)
46
+ .merge({zalora_reserved_stock: zalora_reserved_stock})
47
+
48
+ modes[mode].new(new_param).perform
49
+ else
50
+ modes[mode].new(qty_simple_params(listing)).perform
51
+ end
38
52
  end
39
53
  end
40
54
 
@@ -100,6 +114,22 @@ class ItemBuilderMwh
100
114
  @variant_ids ||= listings.map(&:variant_id).uniq
101
115
  end
102
116
 
117
+ def skus
118
+ @skus ||= listings.map(&:local_id).uniq
119
+ end
120
+
121
+ def zilingo_delta_quantity
122
+ @zilingo_delta_quantity ||= ItemBuilderMwh::ZilingoQuantityService.new(
123
+ listings: listings, skus: skus
124
+ ).perform
125
+ end
126
+
127
+ def zalora_reserved_stock
128
+ @zalora_reserved_stock ||= ItemBuilderMwh::ZaloraQuantityService.new(
129
+ listings: listings, skus: skus
130
+ ).perform
131
+ end
132
+
103
133
  def order_host
104
134
  url = ENV['ORDERS_URL'] || 'orders.forstok.com'
105
135
  url + '/api/v3/item_line/reserved_stock'
@@ -38,7 +38,7 @@ class ItemBuilderMwh
38
38
  def check_consignment_variant?
39
39
  listing.consignment? ||
40
40
  (
41
- !listing.active? && [11, 12, 15].include?(listing.channel_id)
41
+ !listing.active? && [11, 12, 15, 19].include?(listing.channel_id)
42
42
  )
43
43
  end
44
44
 
@@ -16,6 +16,8 @@ class ItemBuilderMwh
16
16
  attr_reader :existing_alloc_stocks
17
17
  attr_reader :variant_listings
18
18
  attr_reader :reserved_stocks
19
+ attr_reader :zilingo_delta_quantity
20
+ attr_reader :zalora_reserved_stock
19
21
  def initialize(args)
20
22
  @listing = args.fetch(:listing)
21
23
  @wh_spaces = args.fetch(:wh_spaces, [])
@@ -26,6 +28,8 @@ class ItemBuilderMwh
26
28
  @existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
27
29
  @variant_listings = args.fetch(:variant_listings, [])
28
30
  @reserved_stocks = args.fetch(:reserved_stocks, [])
31
+ @zilingo_delta_quantity = args.fetch(:zilingo_delta_quantity, [])
32
+ @zalora_reserved_stock = args.fetch(:zalora_reserved_stock, [])
29
33
  warehouse
30
34
  end
31
35
 
@@ -7,7 +7,11 @@ class ItemBuilderMwh
7
7
  module Modes
8
8
  module Price
9
9
  class SalePricePolicy
10
- include Modes
10
+ attr_reader :listing
11
+ def initialize(args)
12
+ @listing = args.fetch(:listing)
13
+ end
14
+
11
15
  def sale_price
12
16
  # has sale price but no sale date defined
13
17
  # then push sale price immediately
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder_mwh/modes/quantity/base'
4
+ class ItemBuilderMwh
5
+ module Modes
6
+ module Quantity
7
+ class ZilingoService < Base
8
+ def perform
9
+ available_quantity - reserved_stock.to_i
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -6,6 +6,8 @@ require 'item_builder_mwh/get_quantity_service'
6
6
  require 'item_builder_mwh/modes/quantity/base'
7
7
  require 'item_builder_mwh/modes/quantity/lazada_service'
8
8
  require 'item_builder_mwh/modes/quantity/zalora_service'
9
+ require 'item_builder_mwh/modes/quantity/zilingo_service'
10
+
9
11
  class ItemBuilderMwh
10
12
  module Modes
11
13
  class QuantityService
@@ -14,6 +16,7 @@ class ItemBuilderMwh
14
16
  QUANTITY_CHANNEL = {}.tap do |hash|
15
17
  hash[3] = :Lazada
16
18
  hash[13] = :Zalora
19
+ hash[18] = :Zilingo
17
20
  end.freeze
18
21
 
19
22
  def perform
@@ -24,7 +27,7 @@ class ItemBuilderMwh
24
27
 
25
28
  def to_h(warehouse_space)
26
29
  {
27
- quantity: qty(warehouse_space.quantity),
30
+ quantity: [qty(warehouse_space.quantity), 0].sort[1],
28
31
  warehouse_id: wh_mapping(
29
32
  warehouse_space.warehouse_id
30
33
  )
@@ -50,7 +53,13 @@ class ItemBuilderMwh
50
53
  end
51
54
 
52
55
  def reserved_stock
53
- reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
56
+ if channel_name == 'Zilingo'
57
+ zilingo_delta_quantity[listing.local_id].to_i
58
+ elsif channel_name == 'Zalora'
59
+ zalora_reserved_stock[listing.local_id].to_i
60
+ else
61
+ reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
62
+ end
54
63
  end
55
64
 
56
65
  def available_quantity(qty)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ItemBuilderMwh
4
- VERSION = '0.1.11'
4
+ VERSION = '0.1.16'
5
5
  end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder_mwh/modes.rb'
4
+ class ItemBuilderMwh
5
+ class ZaloraQuantityService
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 }
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 + "/zalora/product_stocks"
43
+ end
44
+
45
+ def response_process(resp)
46
+ if resp.dig("response_code") && resp.dig("response_code") != 200
47
+ raise "Response Code is #{resp.dig("response_code")}"
48
+ end
49
+
50
+ hash = Hash.new
51
+ resp.dig("SuccessResponse", "Body", "ProductStocks", "ProductStock").each do |sku|
52
+ hash[sku['SellerSku']] = sku['ReservedStock']
53
+ end
54
+ hash
55
+ end
56
+
57
+ def rest_client(params, rescued_codes = 200)
58
+ RestClient::Request.execute(params.merge(timeout: 3)) do |response|
59
+ code = response.code
60
+ unless Array.wrap(rescued_codes).include?(code)
61
+ raise "Response Code is #{code}"
62
+ end
63
+
64
+ response
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder_mwh/modes.rb'
4
+ class ItemBuilderMwh
5
+ class ZilingoQuantityService
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 }
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 + "/zilingo/item_quantity_by_sku"
43
+ end
44
+
45
+ def response_process(resp)
46
+ hash = Hash.new
47
+ resp['zilingoSKUQuantities'].each do |sku|
48
+ hash[sku['zilingoSKUId']] = sku['quantity'] + sku['frozenQuantity']
49
+ end
50
+ hash
51
+ end
52
+
53
+ def rest_client(params, rescued_codes = 200)
54
+ RestClient::Request.execute(params.merge(timeout: 3)) do |response|
55
+ code = response.code
56
+ unless Array.wrap(rescued_codes).include?(code)
57
+ raise "Response Code is #{code}"
58
+ end
59
+
60
+ response
61
+ end
62
+ end
63
+ end
64
+ 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.11
4
+ version: 0.1.16
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-02-15 00:00:00.000000000 Z
11
+ date: 2021-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,6 +131,7 @@ files:
131
131
  - lib/item_builder_mwh/modes/quantity/base.rb
132
132
  - lib/item_builder_mwh/modes/quantity/lazada_service.rb
133
133
  - lib/item_builder_mwh/modes/quantity/zalora_service.rb
134
+ - lib/item_builder_mwh/modes/quantity/zilingo_service.rb
134
135
  - lib/item_builder_mwh/modes/quantity_service.rb
135
136
  - lib/item_builder_mwh/modes/simple/base.rb
136
137
  - lib/item_builder_mwh/modes/simple/blibli_service.rb
@@ -143,6 +144,8 @@ files:
143
144
  - lib/item_builder_mwh/modes/simple/zalora_service.rb
144
145
  - lib/item_builder_mwh/modes/simple_service.rb
145
146
  - lib/item_builder_mwh/version.rb
147
+ - lib/item_builder_mwh/zalora_quantity_service.rb
148
+ - lib/item_builder_mwh/zilingo_quantity_service.rb
146
149
  homepage:
147
150
  licenses: []
148
151
  metadata: {}
@@ -161,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
164
  - !ruby/object:Gem::Version
162
165
  version: '0'
163
166
  requirements: []
164
- rubygems_version: 3.0.6
167
+ rubygems_version: 3.0.9
165
168
  signing_key:
166
169
  specification_version: 4
167
170
  summary: Item Builder Multiwarehouse