item_builder_mwh 0.1.30 → 0.1.34

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: a7d9cbd0ff16d3f1b3ff9f1eec6bbe89304e1445fe3d2cd9ed0fa07e3884c6b1
4
- data.tar.gz: 874ff15f589f0b9de12af48badaabfc16dba5087796143f2b548080498f2c91f
3
+ metadata.gz: 590c9e095a3e20f271a30683c2c6c11201a024c5b17e03dda9c2691b13939d3d
4
+ data.tar.gz: 28d7ea34be369d2248aa59c9513e90ccb8c4e967723baf08d65b26f82acfa4dc
5
5
  SHA512:
6
- metadata.gz: 556eb6eeb96fb7df53e15a03526de0a6f77377a6cd69c96e8bcc14e71491c863f16bf8ea8949eb61237d7ecf48f348156b1d495535de7d15cc6aba0914841928
7
- data.tar.gz: ba4db1fbf9de3ce57a444ee75d0b157093a85df642869e89094f78f3b7d0c41e7890149ca97e44d87a4bba5b9ca1e1d8a9b29f97fb6bc00ae7449678c7b3bc4f
6
+ metadata.gz: 6f1039e8d235e08659f70c600f87dd9260a643603e8f0d0bf39e4656bf120085084e276093050bc768fe95e599b45a2ee3c77e265aa67e6872897848568db798
7
+ data.tar.gz: '09a04734bfdcf9779f7fd84c8d79155a3c4c5058f18fe85a76552678a6980d74610b26719ec47f57f893d1ed4c3c041b822c1f6571d4553ff87d672ee602cc39'
@@ -13,6 +13,7 @@ class ItemBuilderMwh
13
13
  @existing_allocated_stock = args.fetch(:existing_allocated_stock)
14
14
  @listing_wh_sp_quantity = args.fetch(:listing_wh_sp_quantity)
15
15
  @wh_routing = args.fetch(:wh_routing, 0)
16
+ @selected_warehouse_space = args.fetch(:selected_warehouse_space)
16
17
  end
17
18
 
18
19
  def perform
@@ -96,9 +97,8 @@ class ItemBuilderMwh
96
97
  if @bundle_variants.present?
97
98
  qty_list = []
98
99
  @bundle_variants.each do |bvr|
99
- warehouse_space = wh_space.select {|ws| ws.item_variant_id == bvr.variant_id }.first
100
- qty = warehouse_space.quantity if warehouse_space.present?
101
- qty ||= 0
100
+ qty_wh_spaces = wh_space.select {|ws| ws.item_variant_id == bvr.variant_id }
101
+ qty = qty_wh_spaces.sum(&:quantity)
102
102
  qty = qty / bvr.unit
103
103
  qty_list.push(qty)
104
104
  end
@@ -109,7 +109,7 @@ class ItemBuilderMwh
109
109
  end
110
110
 
111
111
  def wh_space
112
- @wh_space ||= WarehouseSpace.where(item_variant_id: variant_ids)
112
+ @wh_space ||= WarehouseSpace.where(item_variant_id: variant_ids, warehouse_id: @selected_warehouse_space.warehouse_id)
113
113
  end
114
114
 
115
115
  def variant_ids
@@ -43,24 +43,24 @@ class ItemBuilderMwh
43
43
 
44
44
  def real_quantity(warehouse_space)
45
45
  if channel_name == 'Zilingo'
46
- qty(warehouse_space.quantity)
46
+ qty(warehouse_space)
47
47
  else
48
- [qty(warehouse_space.quantity), 0].sort[1]
48
+ [qty(warehouse_space), 0].sort[1]
49
49
  end
50
50
  end
51
51
 
52
- def qty(qty)
52
+ def qty(warehouse_space)
53
53
  if channel_name.empty? || channel_name == "Shopify"
54
- available_quantity(qty)
54
+ available_quantity(warehouse_space)
55
55
  else
56
- qty_channel(qty)
56
+ qty_channel(warehouse_space)
57
57
  end
58
58
  end
59
59
 
60
- def qty_channel(qty)
60
+ def qty_channel(warehouse_space)
61
61
  class_name = "ItemBuilderMwh::Modes::Quantity::#{channel_name}Service"
62
62
  qty_channel_service = class_name.constantize
63
- qty_channel_service.new(listing, available_quantity(qty), local_qty.to_i).perform
63
+ qty_channel_service.new(listing, available_quantity(warehouse_space), local_qty.to_i).perform
64
64
  end
65
65
 
66
66
  def channel_name
@@ -95,12 +95,13 @@ class ItemBuilderMwh
95
95
  0
96
96
  end
97
97
 
98
- def available_quantity(qty)
98
+ def available_quantity(warehouse_space)
99
99
  ItemBuilderMwh::GetQuantityService.new(
100
100
  listing: listing, stock_alloc: stock_alloc,
101
101
  variant: variant, bundle_variants: bundle_variants,
102
102
  existing_allocated_stock: existing_allocated_stock,
103
- listing_wh_sp_quantity: qty, wh_routing: wh_routing
103
+ listing_wh_sp_quantity: warehouse_space.quantity, wh_routing: wh_routing,
104
+ selected_warehouse_space: warehouse_space
104
105
  ).perform
105
106
  end
106
107
  end
@@ -98,14 +98,21 @@ class ItemBuilderMwh
98
98
  WarehouseSpace
99
99
  .joins('JOIN warehouse_mappings ON
100
100
  warehouse_spaces.warehouse_id = warehouse_mappings.warehouse_id')
101
+ .joins('JOIN warehouses ON
102
+ warehouse_spaces.warehouse_id = warehouses.id')
101
103
  .where("warehouse_mappings.profile_channel_association_id=#{pca}")
102
- .where("warehouse_spaces.item_variant_id=#{listing.variant_id}")
104
+ .where("warehouse_spaces.item_variant_id=#{variant_id}")
105
+ .where('warehouses.consignment = 0')
103
106
  end
104
107
 
105
108
  def pca
106
109
  listing.profile_channel_association_id.to_s
107
110
  end
108
111
 
112
+ def variant_id
113
+ bundle_variants&.first&.variant_id || listing.variant_id
114
+ end
115
+
109
116
  def warehouse_mapping(warehouse_id)
110
117
  WarehouseMapping
111
118
  .where(profile_channel_association_id:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ItemBuilderMwh
4
- VERSION = '0.1.30'
4
+ VERSION = '0.1.34'
5
5
  end
@@ -43,16 +43,16 @@ class ItemBuilderMwh
43
43
  param =
44
44
  if listing.channel_id == 18
45
45
  qty_simple_params(listing)
46
- .merge(zilingo_quantity: @zilingo_quantity)
46
+ .merge(zilingo_quantity: zilingo_quantity)
47
47
  elsif listing.channel_id == 13
48
48
  qty_simple_params(listing)
49
- .merge(zalora_reserved_stock: @zalora_reserved_stock)
49
+ .merge(zalora_reserved_stock: zalora_reserved_stock)
50
50
  elsif listing.channel_id == 2
51
51
  qty_simple_params(listing)
52
- .merge({shopify_inventory_location: @shopify_inventory_location})
52
+ .merge({shopify_inventory_location: shopify_inventory_location})
53
53
  elsif listing.channel_id == 3
54
54
  qty_simple_params(listing)
55
- .merge({lazada_quantity: @lazada_quantity})
55
+ .merge({lazada_quantity: lazada_quantity})
56
56
  else
57
57
  qty_simple_params(listing)
58
58
  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.30
4
+ version: 0.1.34
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-09-27 00:00:00.000000000 Z
11
+ date: 2021-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler