item_builder 0.1.18 → 0.1.23
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.rb +39 -3
- data/lib/item_builder/get_quantity_service.rb +22 -26
- data/lib/item_builder/modes.rb +10 -0
- data/lib/item_builder/modes/quantity/base.rb +0 -28
- data/lib/item_builder/modes/quantity_service.rb +30 -5
- data/lib/item_builder/version.rb +1 -1
- metadata +2 -3
- data/lib/item_builder/modes/quantity/blibli_service.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6780bd1811cc5b5a70e34a875fbecc9f492d82c0755b80465fe06565f7f58ee
|
4
|
+
data.tar.gz: 0b45360d1a8651670204a8fa8638ea5454978b90122837d8447f0284ea39fa9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc7850d78db626648be0b915bf8a8f72d928268892d5360a83b071f65b2e6ba645505fbafae82548da165b0d7ed99f83f1ecdf195cff03c575fa7e4b60d3d7a7
|
7
|
+
data.tar.gz: 7cba37504ce2c06fec5d2bc5d9be2e80844629a214c1df12c9996147c4b779947867451d24575a30aea1d4455d7be26c5c118786d4491435f45d9ec544a01530
|
data/lib/item_builder.rb
CHANGED
@@ -41,9 +41,10 @@ class ItemBuilder
|
|
41
41
|
|
42
42
|
def qty_params(listing)
|
43
43
|
{
|
44
|
-
listing: listing,
|
45
|
-
|
46
|
-
|
44
|
+
listing: listing, wh_spaces: wh_spaces, variants: variants,
|
45
|
+
stock_allocs: stock_allocs, variant_listings: variant_listings,
|
46
|
+
bundles: bundles, item_bundle_variants: item_bundle_variants,
|
47
|
+
existing_alloc_stocks: existing_alloc_stocks
|
47
48
|
}
|
48
49
|
end
|
49
50
|
|
@@ -53,6 +54,41 @@ class ItemBuilder
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
57
|
+
def existing_alloc_stocks
|
58
|
+
@existing_alloc_stocks ||= VariantListingStockAllocation.where(
|
59
|
+
variant_association_id: vl_ids
|
60
|
+
).where('ADDTIME(end_at, "07:00") >= NOW()')
|
61
|
+
end
|
62
|
+
|
63
|
+
def vl_ids
|
64
|
+
@vl_ids ||= variant_listings.map(&:id).uniq
|
65
|
+
end
|
66
|
+
|
67
|
+
def variant_listings
|
68
|
+
@variant_listings ||= VariantListing.where(variant_id: variant_ids)
|
69
|
+
end
|
70
|
+
|
71
|
+
def item_bundle_variants
|
72
|
+
@item_bundle_variants ||= BundleVariant.where(
|
73
|
+
bundle_id: bundle_ids,
|
74
|
+
channel_id: listings[0].channel_id
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
def bundle_ids
|
79
|
+
@bundle_ids ||= bundles.map(&:id).uniq
|
80
|
+
end
|
81
|
+
|
82
|
+
def bundles
|
83
|
+
@bundles ||= Bundle.where(variant_id: variant_ids).group(:variant_id)
|
84
|
+
end
|
85
|
+
|
86
|
+
def stock_allocs
|
87
|
+
@stock_allocs ||= VariantListingStockAllocation.where(
|
88
|
+
variant_association_id: vl_ids
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
56
92
|
def wh_spaces
|
57
93
|
@wh_spaces ||= WarehouseSpace.where(item_variant_id: variant_ids)
|
58
94
|
end
|
@@ -9,6 +9,9 @@ class ItemBuilder
|
|
9
9
|
@listing = args.fetch(:listing)
|
10
10
|
@wh_sp = args.fetch(:wh_sp)
|
11
11
|
@variant = args.fetch(:variant)
|
12
|
+
@stock_alloc = args.fetch(:stock_alloc)
|
13
|
+
@bundle_variants = args.fetch(:bundle_variants)
|
14
|
+
@existing_allocated_stock = args.fetch(:existing_allocated_stock)
|
12
15
|
end
|
13
16
|
|
14
17
|
def perform
|
@@ -18,7 +21,7 @@ class ItemBuilder
|
|
18
21
|
# yang masuk di kondisi ini,
|
19
22
|
# artinya akun tersebut ada allocated stock yang aktif
|
20
23
|
allocated_stock
|
21
|
-
elsif existing_allocated_stock.present?
|
24
|
+
elsif @existing_allocated_stock.present?
|
22
25
|
# yang masuk di kondisi ini,
|
23
26
|
# artinya akun tersebut tidak ada allocated stock yang aktif,
|
24
27
|
# namun ada allocated stock yg aktif dari channel lain
|
@@ -35,25 +38,21 @@ class ItemBuilder
|
|
35
38
|
def check_consignment_variant?
|
36
39
|
listing.consignment? ||
|
37
40
|
(
|
38
|
-
!listing.active? && [12, 15].include?(listing.channel_id)
|
41
|
+
!listing.active? && [11, 12, 15].include?(listing.channel_id)
|
39
42
|
)
|
40
43
|
end
|
41
44
|
|
42
45
|
def allocated_stock_active?
|
43
|
-
listing.present? && stock_alloc.present? && allocated_start_end?
|
46
|
+
listing.present? && @stock_alloc.present? && allocated_start_end?
|
44
47
|
end
|
45
48
|
|
46
49
|
def allocated_start_end?
|
47
|
-
stock_alloc.start_at.beginning_of_day <= Time.now &&
|
48
|
-
stock_alloc.end_at.end_of_day >= Time.now
|
50
|
+
@stock_alloc.start_at.beginning_of_day <= Time.now &&
|
51
|
+
@stock_alloc.end_at.end_of_day >= Time.now
|
49
52
|
end
|
50
53
|
|
51
54
|
def allocated_stock
|
52
|
-
stock_alloc.quantity.to_i - one_alloc_rsvd_stock(stock_alloc).to_i
|
53
|
-
end
|
54
|
-
|
55
|
-
def stock_alloc
|
56
|
-
@stock_alloc ||= listing.variant_listing_stock_allocation
|
55
|
+
@stock_alloc.quantity.to_i - one_alloc_rsvd_stock(@stock_alloc).to_i
|
57
56
|
end
|
58
57
|
|
59
58
|
# warehouse_stock fungsi untuk mendapatkan available quantity
|
@@ -76,10 +75,11 @@ class ItemBuilder
|
|
76
75
|
|
77
76
|
def qty_bundle
|
78
77
|
# Quantity for bundle config
|
79
|
-
if bundle_variants.present?
|
78
|
+
if @bundle_variants.present?
|
80
79
|
qty_list = []
|
81
|
-
bundle_variants.each do |bvr|
|
82
|
-
|
80
|
+
@bundle_variants.each do |bvr|
|
81
|
+
warehouse_space = wh_space.select {|ws| ws.item_variant_id == bvr.variant_id }.first
|
82
|
+
qty = warehouse_space.quantity if warehouse_space.present?
|
83
83
|
qty ||= 0
|
84
84
|
qty = qty / bvr.unit
|
85
85
|
qty_list.push(qty)
|
@@ -90,31 +90,27 @@ class ItemBuilder
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
def
|
94
|
-
|
95
|
-
'variant_id = ?', variant.id
|
96
|
-
).first.bundle_variants.where(channel_id: listing.channel_id)
|
93
|
+
def wh_space
|
94
|
+
@wh_space ||= WarehouseSpace.where(item_variant_id: variant_ids)
|
97
95
|
end
|
98
96
|
|
99
|
-
def
|
100
|
-
@
|
97
|
+
def variant_ids
|
98
|
+
@variant_ids ||= @bundle_variants.map(&:variant_id).uniq
|
101
99
|
end
|
102
100
|
|
103
|
-
def
|
104
|
-
|
105
|
-
variant_association_id: variant.variant_listings.pluck(:id)
|
106
|
-
).where('ADDTIME(end_at, "07:00") >= NOW()')
|
101
|
+
def listing_wh_sp_quantity
|
102
|
+
@listing_wh_sp_quantity ||= wh_sp&.quantity || 0
|
107
103
|
end
|
108
104
|
|
109
105
|
def count_existing_alloc_stock
|
110
|
-
return 0 if existing_allocated_stock.blank?
|
106
|
+
return 0 if @existing_allocated_stock.blank?
|
111
107
|
|
112
|
-
existing_allocated_stock.sum(
|
108
|
+
@existing_allocated_stock.sum(&:quantity)
|
113
109
|
end
|
114
110
|
|
115
111
|
def count_alloc_rsvd_stock
|
116
112
|
stock = 0
|
117
|
-
existing_allocated_stock.each do |allocated_stock|
|
113
|
+
@existing_allocated_stock.each do |allocated_stock|
|
118
114
|
stock += one_alloc_rsvd_stock(allocated_stock).to_i
|
119
115
|
end
|
120
116
|
stock
|
data/lib/item_builder/modes.rb
CHANGED
@@ -11,10 +11,20 @@ class ItemBuilder
|
|
11
11
|
attr_reader :listing
|
12
12
|
attr_reader :wh_spaces
|
13
13
|
attr_reader :variants
|
14
|
+
attr_reader :stock_allocs
|
15
|
+
attr_reader :bundles
|
16
|
+
attr_reader :item_bundle_variants
|
17
|
+
attr_reader :existing_alloc_stocks
|
18
|
+
attr_reader :variant_listings
|
14
19
|
def initialize(args)
|
15
20
|
@listing = args.fetch(:listing)
|
16
21
|
@wh_spaces = args.fetch(:wh_spaces, [])
|
17
22
|
@variants = args.fetch(:variants, [])
|
23
|
+
@stock_allocs = args.fetch(:stock_allocs, [])
|
24
|
+
@bundles = args.fetch(:bundles, [])
|
25
|
+
@item_bundle_variants = args.fetch(:item_bundle_variants, [])
|
26
|
+
@existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
|
27
|
+
@variant_listings = args.fetch(:variant_listings, [])
|
18
28
|
end
|
19
29
|
|
20
30
|
def base
|
@@ -31,34 +31,6 @@ class ItemBuilder
|
|
31
31
|
def apigateway_get
|
32
32
|
RestClient.get("#{host}?#{params}")
|
33
33
|
end
|
34
|
-
|
35
|
-
def headers
|
36
|
-
{
|
37
|
-
content_type: :json,
|
38
|
-
accept: :json
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
def credential
|
43
|
-
account_id = listing.profile_channel_association_id
|
44
|
-
host = ENV['CREDENTIAL_URL'] || 'user.forstok.com'
|
45
|
-
RestClient.get("#{host}/credential?account_id=#{account_id}")
|
46
|
-
end
|
47
|
-
|
48
|
-
def data
|
49
|
-
{
|
50
|
-
"credential": JSON.parse(credential)['credential'],
|
51
|
-
"data": request
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
def api_data
|
56
|
-
data.to_json
|
57
|
-
end
|
58
|
-
|
59
|
-
def apigateway_post
|
60
|
-
RestClient.post(url, api_data, headers)
|
61
|
-
end
|
62
34
|
end
|
63
35
|
end
|
64
36
|
end
|
@@ -5,7 +5,6 @@ require 'item_builder/modes.rb'
|
|
5
5
|
require 'item_builder/get_quantity_service'
|
6
6
|
require 'item_builder/modes/quantity/base'
|
7
7
|
require 'item_builder/modes/quantity/lazada_service'
|
8
|
-
require 'item_builder/modes/quantity/blibli_service'
|
9
8
|
require 'item_builder/modes/quantity/zalora_service'
|
10
9
|
class ItemBuilder
|
11
10
|
module Modes
|
@@ -14,7 +13,6 @@ class ItemBuilder
|
|
14
13
|
|
15
14
|
QUANTITY_CHANNEL = {}.tap do |hash|
|
16
15
|
hash[3] = :Lazada
|
17
|
-
hash[9] = :Blibli
|
18
16
|
hash[13] = :Zalora
|
19
17
|
end.freeze
|
20
18
|
|
@@ -48,12 +46,39 @@ class ItemBuilder
|
|
48
46
|
|
49
47
|
def available_quantity
|
50
48
|
ItemBuilder::GetQuantityService.new(
|
51
|
-
listing: listing,
|
52
|
-
|
53
|
-
|
49
|
+
listing: listing, variant: variant,
|
50
|
+
wh_sp: warehouse, stock_alloc: stock_alloc,
|
51
|
+
bundle_variants: bundle_variants,
|
52
|
+
existing_allocated_stock: existing_allocated_stock
|
54
53
|
).perform
|
55
54
|
end
|
56
55
|
|
56
|
+
def existing_allocated_stock
|
57
|
+
existing_alloc_stocks.map do |els|
|
58
|
+
if listings.pluck(:id).include?(els.variant_association_id)
|
59
|
+
els
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def listings
|
65
|
+
variant_listings.select {|vl| vl.variant_id == listing.variant_id}
|
66
|
+
end
|
67
|
+
|
68
|
+
def bundle_variants
|
69
|
+
if bundle.present?
|
70
|
+
item_bundle_variants.select {|ibv| ibv.bundle_id == bundle.id }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def bundle
|
75
|
+
bundles.select {|b| b.variant_id == listing.variant_id }.first
|
76
|
+
end
|
77
|
+
|
78
|
+
def stock_alloc
|
79
|
+
stock_allocs.select {|sa| sa.variant_association_id == listing.id }.first
|
80
|
+
end
|
81
|
+
|
57
82
|
def warehouse
|
58
83
|
wh_spaces.select {|ws| ws.item_variant_id == listing.variant_id }.first
|
59
84
|
end
|
data/lib/item_builder/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okaaryanata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,7 +129,6 @@ files:
|
|
129
129
|
- lib/item_builder/modes/price/zalora_service.rb
|
130
130
|
- lib/item_builder/modes/price_service.rb
|
131
131
|
- lib/item_builder/modes/quantity/base.rb
|
132
|
-
- lib/item_builder/modes/quantity/blibli_service.rb
|
133
132
|
- lib/item_builder/modes/quantity/lazada_service.rb
|
134
133
|
- lib/item_builder/modes/quantity/zalora_service.rb
|
135
134
|
- lib/item_builder/modes/quantity_service.rb
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'item_builder/modes/quantity/base'
|
4
|
-
class ItemBuilder
|
5
|
-
module Modes
|
6
|
-
module Quantity
|
7
|
-
class BlibliService < Base
|
8
|
-
def perform
|
9
|
-
local_variant
|
10
|
-
end
|
11
|
-
|
12
|
-
def local_variant
|
13
|
-
qty = 0
|
14
|
-
local_product['value']['items'].each do |item|
|
15
|
-
qty = total_quantity(item) if item['itemSku'] == listing.local_id
|
16
|
-
end
|
17
|
-
qty
|
18
|
-
end
|
19
|
-
|
20
|
-
def total_quantity(item)
|
21
|
-
# Make stock 0
|
22
|
-
# if local reserved quantity is bigger than available quantity
|
23
|
-
if item['reservedStockLevel2'] > available_quantity
|
24
|
-
0
|
25
|
-
else
|
26
|
-
available_quantity
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# Find local product based on id
|
31
|
-
# @return [Hash] Local Blibli product
|
32
|
-
def local_product
|
33
|
-
@local_product ||= JSON.parse(apigateway_post)
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def request
|
39
|
-
{
|
40
|
-
"gdnSku": listing.local_id
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
|
-
def url
|
45
|
-
url = ENV['API_GATEWAY_URL'] || 'apigateway.forstok.com'
|
46
|
-
url + '/blibli/item'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|