item_builder 0.1.21 → 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: 48928bd692d1e23385b374cf0c1e488b40bde748a86a0a648148ec82cb91fce3
4
- data.tar.gz: 34d42d47a3fe0310969409df85b1b70d29ccdcc7e6ede904d22a078bec914bfb
3
+ metadata.gz: 8492d320599234405f053957073589a52c3338b44df6d9788de69a166dda571a
4
+ data.tar.gz: 61ca9debe7fbd6eb3fb52e7231a486049f2d223fc7f511fbac1bb1aeea63bbc5
5
5
  SHA512:
6
- metadata.gz: 4a17685ebc1909ec2e0156f6f2f0246c5768618ee42e650c2b63f76d78e1bfaef0d392334b6641e186ee8fd816ba324eb5cd94f427fe00a34a1dcb8f5845c7ab
7
- data.tar.gz: cbfcc3fbc08ee067efeeafe5b02a4a6bbfb48ecc4c8d6c47c4e576ccee00a20ebae46c7cdc2b2897fc0118e6651988d2edba6d549136f106e4f5c9e18744858e
6
+ metadata.gz: 7bc64e7ef1ca238fb7ba1d09348501f55b3417de1982a6b8009fae8687bf3e6213491f209a6104df813ec35a059d935daaab89b8d927a0ee091aa5e551ae7201
7
+ data.tar.gz: 97670ab47df3c2f85bf88fb8f3eb3f56faf6c77d8c302255777eb6e1819ab847235feda7b633c5af06f56df3c6648183c5bc080e4f2640273d10434450df52f6
data/lib/item_builder.rb CHANGED
@@ -26,25 +26,26 @@ class ItemBuilder
26
26
  end
27
27
 
28
28
  def mode_check
29
- if mode == :quantity
30
- quantity_mode
29
+ if mode == :quantity || mode == :simple
30
+ quantity_simple_mode
31
31
  else
32
32
  default
33
33
  end
34
34
  end
35
35
 
36
- def quantity_mode
36
+ def quantity_simple_mode
37
37
  listings.map do |listing|
38
- modes[mode].new(qty_params(listing)).perform
38
+ modes[mode].new(qty_simple_params(listing)).perform
39
39
  end
40
40
  end
41
41
 
42
- def qty_params(listing)
42
+ def qty_simple_params(listing)
43
43
  {
44
44
  listing: listing, wh_spaces: wh_spaces, variants: variants,
45
45
  stock_allocs: stock_allocs, variant_listings: variant_listings,
46
46
  bundles: bundles, item_bundle_variants: item_bundle_variants,
47
- existing_alloc_stocks: existing_alloc_stocks
47
+ existing_alloc_stocks: existing_alloc_stocks,
48
+ reserved_stocks: reserved_stocks
48
49
  }
49
50
  end
50
51
 
@@ -114,4 +115,20 @@ class ItemBuilder
114
115
  update: ItemBuilder::Modes::UpdateService
115
116
  }
116
117
  end
118
+
119
+ def order_host
120
+ url = ENV['ORDERS_URL'] || 'orders.forstok.com'
121
+ url + '/api/v3/item_line/reserved_stock'
122
+ end
123
+
124
+ def reserved_params
125
+ "account_id=#{listings[0].profile_channel_association_id}
126
+ &item_variant_ids=#{variant_ids.join(',')}"
127
+ end
128
+
129
+ def reserved_stocks
130
+ @reserved_stocks ||= JSON.parse(RestClient.get(
131
+ "#{order_host}?#{reserved_params}"
132
+ ).body) if [3,13].include?(listings[0].channel_id)
133
+ end
117
134
  end
@@ -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_space.select {|ws| ws.item_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)
@@ -16,6 +16,7 @@ class ItemBuilder
16
16
  attr_reader :item_bundle_variants
17
17
  attr_reader :existing_alloc_stocks
18
18
  attr_reader :variant_listings
19
+ attr_reader :reserved_stocks
19
20
  def initialize(args)
20
21
  @listing = args.fetch(:listing)
21
22
  @wh_spaces = args.fetch(:wh_spaces, [])
@@ -25,6 +26,7 @@ class ItemBuilder
25
26
  @item_bundle_variants = args.fetch(:item_bundle_variants, [])
26
27
  @existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
27
28
  @variant_listings = args.fetch(:variant_listings, [])
29
+ @reserved_stocks = args.fetch(:reserved_stocks, [])
28
30
  end
29
31
 
30
32
  def base
@@ -35,5 +37,39 @@ class ItemBuilder
35
37
  sku: listing.sku
36
38
  }
37
39
  end
40
+
41
+ def existing_allocated_stock
42
+ existing_alloc_stocks.map do |els|
43
+ if listings.pluck(:id).include?(els.variant_association_id)
44
+ els
45
+ end
46
+ end.compact
47
+ end
48
+
49
+ def listings
50
+ variant_listings.select {|vl| vl.variant_id == listing.variant_id}
51
+ end
52
+
53
+ def bundle_variants
54
+ if bundle.present?
55
+ item_bundle_variants.select {|ibv| ibv.bundle_id == bundle.id }
56
+ end
57
+ end
58
+
59
+ def bundle
60
+ bundles.select {|b| b.variant_id == listing.variant_id }.first
61
+ end
62
+
63
+ def stock_alloc
64
+ stock_allocs.select {|sa| sa.variant_association_id == listing.id }.first
65
+ end
66
+
67
+ def warehouse
68
+ wh_spaces.select {|ws| ws.item_variant_id == listing.variant_id }.first
69
+ end
70
+
71
+ def variant
72
+ variants.select {|v| v.id == listing.variant_id }.first
73
+ end
38
74
  end
39
75
  end
@@ -6,30 +6,14 @@ class ItemBuilder
6
6
  class Base
7
7
  attr_reader :listing
8
8
  attr_reader :available_quantity
9
+ attr_reader :reserved_stock
9
10
 
10
- def initialize(listing, available_quantity)
11
+ def initialize(listing, available_quantity, reserved_stock)
11
12
  raise 'listing is not set' if listing.nil?
12
13
 
13
14
  @listing = listing
14
15
  @available_quantity = available_quantity
15
- end
16
-
17
- def order_host
18
- url = ENV['ORDERS_URL'] || 'orders.forstok.com'
19
- url + '/api/v2/item_line/reserved_stock'
20
- end
21
-
22
- def reserved_params
23
- "account_id=#{listing.profile_channel_association_id}
24
- &item_variant_id=#{listing.variant_id}"
25
- end
26
-
27
- def reserved_stock
28
- RestClient.get("#{order_host}?#{reserved_params}")
29
- end
30
-
31
- def apigateway_get
32
- RestClient.get("#{host}?#{params}")
16
+ @reserved_stock = reserved_stock
33
17
  end
34
18
  end
35
19
  end
@@ -37,13 +37,17 @@ class ItemBuilder
37
37
  def qty_channel
38
38
  class_name = "ItemBuilder::Modes::Quantity::#{channel_name}Service"
39
39
  qty_channel_service = class_name.constantize
40
- qty_channel_service.new(listing, available_quantity).perform
40
+ qty_channel_service.new(listing, available_quantity, reserved_stock).perform
41
41
  end
42
42
 
43
43
  def channel_name
44
44
  QUANTITY_CHANNEL[listing.channel_id].to_s
45
45
  end
46
46
 
47
+ def reserved_stock
48
+ reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
49
+ end
50
+
47
51
  def available_quantity
48
52
  ItemBuilder::GetQuantityService.new(
49
53
  listing: listing, variant: variant,
@@ -52,38 +56,6 @@ class ItemBuilder
52
56
  existing_allocated_stock: existing_allocated_stock
53
57
  ).perform
54
58
  end
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
- item_bundle_variants.select {|ibv| ibv.bundle_id == bundle.id }
70
- end
71
-
72
- def bundle
73
- bundles.select {|b| b.variant_id == listing.variant_id }.first
74
- end
75
-
76
- def stock_alloc
77
- stock_allocs.select {|sa| sa.variant_association_id == listing.id }.first
78
- end
79
-
80
- def warehouse
81
- wh_spaces.select {|ws| ws.item_variant_id == listing.variant_id }.first
82
- end
83
-
84
- def variant
85
- variants.select {|v| v.id == listing.variant_id }.first
86
- end
87
59
  end
88
60
  end
89
61
  end
@@ -17,7 +17,13 @@ class ItemBuilder
17
17
  end
18
18
 
19
19
  def quantity
20
- QuantityService.new(listing: listing).to_h
20
+ QuantityService.new(
21
+ listing: listing, wh_spaces: wh_spaces, variants: variants,
22
+ stock_allocs: stock_allocs, variant_listings: variant_listings,
23
+ bundles: bundles, item_bundle_variants: item_bundle_variants,
24
+ existing_alloc_stocks: existing_alloc_stocks,
25
+ reserved_stocks: reserved_stocks
26
+ ).to_h
21
27
  end
22
28
 
23
29
  def price
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ItemBuilder
4
- VERSION = '0.1.21'
4
+ VERSION = '0.1.26'
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.21
4
+ version: 0.1.26
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-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler