item_builder 0.1.19 → 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dea667fd969ce159a690f79ab45f3dd0ebe0994bb88364d43ec37a9b2a18a40d
4
- data.tar.gz: 13aa7b1c835273396ab747def854d80cba132133b6af0846204d076a8083a343
3
+ metadata.gz: e84c717790a58f223fe7c45bb48a5bd4af6cdddac870d065bd706ad2274bccc5
4
+ data.tar.gz: 57963c302c7f68816e6976d0eba8095407a403cf820c6e72eac04c42bc7bbb7a
5
5
  SHA512:
6
- metadata.gz: 982f5e5de1f4183151b0d1daada4c9fc3cc905f98db69195853fe16f59d65740f146446eec243aba23a2035362ed49ab029218e5ed5d2b0539c212fa8b97a433
7
- data.tar.gz: d4a60767cff226b0403d2c645b10cf1857bdf5d5e65b9b59e30a6379d3a6e3ea9f6f243095c7dcbf779a7c5fe68ffbf469f60e35362d2855818c04f71c5da31f
6
+ metadata.gz: 9bb7b47d6e283efd1d301726532a3929661d520640c600b3e42c74b5d1e58a6cf81d24c3577164d937a3919f1ca2ffe015554fb0b5357849c92bfe758a51b60f
7
+ data.tar.gz: 6854dd8d599eed25c3ab1b74e8a1c14437e74e80ea22f04d43bb2d54ce7cb0db0ab9a1f0adb368173cfb4830963206a98f62cfad0651bc562a420ab5d5b7fb8a
@@ -41,8 +41,8 @@ class ItemBuilder
41
41
 
42
42
  def qty_params(listing)
43
43
  {
44
- listing: listing, wh_spaces: wh_spaces,
45
- variants: variants, stock_allocs: stock_allocs,
44
+ listing: listing, wh_spaces: wh_spaces, variants: variants,
45
+ stock_allocs: stock_allocs, variant_listings: variant_listings,
46
46
  bundles: bundles, item_bundle_variants: item_bundle_variants,
47
47
  existing_alloc_stocks: existing_alloc_stocks
48
48
  }
@@ -85,7 +85,7 @@ class ItemBuilder
85
85
 
86
86
  def stock_allocs
87
87
  @stock_allocs ||= VariantListingStockAllocation.where(
88
- variant_association_id: variant_ids
88
+ variant_association_id: vl_ids
89
89
  )
90
90
  end
91
91
 
@@ -78,7 +78,8 @@ class ItemBuilder
78
78
  if @bundle_variants.present?
79
79
  qty_list = []
80
80
  @bundle_variants.each do |bvr|
81
- qty = wh_sp.select {|ws| s.variant_id == bvr.variant_id }.first.quantity
81
+ warehouse_space = wh_space.select {|ws| ws.item_variant_id == bvr.variant_id }.first
82
+ qty = warehouse_space.quantity if warehouse_space.present?
82
83
  qty ||= 0
83
84
  qty = qty / bvr.unit
84
85
  qty_list.push(qty)
@@ -89,8 +90,8 @@ class ItemBuilder
89
90
  end
90
91
  end
91
92
 
92
- def wh_sp
93
- @wh_sp ||= WarehouseSpace.where(item_variant_id: variant_ids)
93
+ def wh_space
94
+ @wh_space ||= WarehouseSpace.where(item_variant_id: variant_ids)
94
95
  end
95
96
 
96
97
  def variant_ids
@@ -104,7 +105,7 @@ class ItemBuilder
104
105
  def count_existing_alloc_stock
105
106
  return 0 if @existing_allocated_stock.blank?
106
107
 
107
- @existing_allocated_stock.sum(:quantity)
108
+ @existing_allocated_stock.sum(&:quantity)
108
109
  end
109
110
 
110
111
  def count_alloc_rsvd_stock
@@ -15,6 +15,7 @@ class ItemBuilder
15
15
  attr_reader :bundles
16
16
  attr_reader :item_bundle_variants
17
17
  attr_reader :existing_alloc_stocks
18
+ attr_reader :variant_listings
18
19
  def initialize(args)
19
20
  @listing = args.fetch(:listing)
20
21
  @wh_spaces = args.fetch(:wh_spaces, [])
@@ -23,6 +24,7 @@ class ItemBuilder
23
24
  @bundles = args.fetch(:bundles, [])
24
25
  @item_bundle_variants = args.fetch(:item_bundle_variants, [])
25
26
  @existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
27
+ @variant_listings = args.fetch(:variant_listings, [])
26
28
  end
27
29
 
28
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
 
@@ -56,11 +54,21 @@ class ItemBuilder
56
54
  end
57
55
 
58
56
  def existing_allocated_stock
59
- existing_alloc_stocks.select {|eas| eas.variant_association_id == listing.id }
57
+ existing_alloc_stocks.map do |els|
58
+ if listings.pluck(:id).include?(els.variant_association_id)
59
+ els
60
+ end
61
+ end.compact
62
+ end
63
+
64
+ def listings
65
+ variant_listings.select {|vl| vl.variant_id == listing.variant_id}
60
66
  end
61
67
 
62
68
  def bundle_variants
63
- item_bundle_variants.select {|ibv| ibv.bundle_id == bundle.id }
69
+ if bundle.present?
70
+ item_bundle_variants.select {|ibv| ibv.bundle_id == bundle.id }
71
+ end
64
72
  end
65
73
 
66
74
  def bundle
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ItemBuilder
4
- VERSION = '0.1.19'
4
+ VERSION = '0.1.24'
5
5
  end
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.19
4
+ version: 0.1.24
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-27 00:00:00.000000000 Z
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