item_builder 0.1.20 → 0.1.25

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: 05a5aaf51ca610c9a2ea38268de98a9c610205fae9ecbaf2fdc111799264437f
4
- data.tar.gz: a8a1de4a22e3002203db71564da0c88ed2f0440b5ef3d3c43faf7b419d912727
3
+ metadata.gz: f7fe5aee9e5ad53c176f35a5f67d68dedcc66bb5475861c432865a1fe762252f
4
+ data.tar.gz: d1c4b8a261c1a9839d273b3a9c2fb4aad7a4a5ac62cfec359e9c7b5f1cbc38ed
5
5
  SHA512:
6
- metadata.gz: 105786a98ff16a0531fa9d82078d70ddeae34c0b3516b44f84760a415e8bd22195bc8771905580df71dd8e6d3788dbf65a64b16741bc69b56674b4c9e4013bd8
7
- data.tar.gz: c00f310744876ea11269848eac6dcdef46887a43fc855f92337bb5b1cc90deca4f169cfd20cfc3f1defe751aac53fb03b39edb7a733c42bf6c85e476da0b5b5a
6
+ metadata.gz: 4293e1f028ae58b3a9b1925adad9f24a3e9aeb1262254691c6bda8138cce5dbddcba15011259bdfaadc473ef92b1cd9fa7bc5373f9de2608ee63f60401151bdd
7
+ data.tar.gz: b6a48cb493ad29427f51a8d85dc6abf529b2ad09ad8e6498aa606c8d940146f21a3c05d4c63e8d9d732f50171d9f08ed578aab8990ce43bf3243ba241eb7343c
@@ -41,10 +41,11 @@ 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
- 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
 
@@ -85,7 +86,7 @@ class ItemBuilder
85
86
 
86
87
  def stock_allocs
87
88
  @stock_allocs ||= VariantListingStockAllocation.where(
88
- variant_association_id: variant_ids
89
+ variant_association_id: vl_ids
89
90
  )
90
91
  end
91
92
 
@@ -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_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,8 @@ 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
19
+ attr_reader :reserved_stocks
18
20
  def initialize(args)
19
21
  @listing = args.fetch(:listing)
20
22
  @wh_spaces = args.fetch(:wh_spaces, [])
@@ -23,6 +25,8 @@ class ItemBuilder
23
25
  @bundles = args.fetch(:bundles, [])
24
26
  @item_bundle_variants = args.fetch(:item_bundle_variants, [])
25
27
  @existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
28
+ @variant_listings = args.fetch(:variant_listings, [])
29
+ @reserved_stocks = args.fetch(:reserved_stocks, [])
26
30
  end
27
31
 
28
32
  def base
@@ -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,
@@ -54,11 +58,21 @@ class ItemBuilder
54
58
  end
55
59
 
56
60
  def existing_allocated_stock
57
- existing_alloc_stocks.select {|eas| eas.variant_association_id == listing.id }
61
+ existing_alloc_stocks.map do |els|
62
+ if listings.pluck(:id).include?(els.variant_association_id)
63
+ els
64
+ end
65
+ end.compact
66
+ end
67
+
68
+ def listings
69
+ variant_listings.select {|vl| vl.variant_id == listing.variant_id}
58
70
  end
59
71
 
60
72
  def bundle_variants
61
- item_bundle_variants.select {|ibv| ibv.bundle_id == bundle.id }
73
+ if bundle.present?
74
+ item_bundle_variants.select {|ibv| ibv.bundle_id == bundle.id }
75
+ end
62
76
  end
63
77
 
64
78
  def bundle
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ItemBuilder
4
- VERSION = '0.1.20'
4
+ VERSION = '0.1.25'
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.20
4
+ version: 0.1.25
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-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler