Class: ItemBuilderMwh::Modes::QuantityService
- Inherits:
-
Object
- Object
- ItemBuilderMwh::Modes::QuantityService
show all
- Includes:
- ItemBuilderMwh::Modes
- Defined in:
- lib/item_builder_mwh/modes/quantity_service.rb
Constant Summary
collapse
- QUANTITY_CHANNEL =
{}.tap do |hash|
hash[2] = :Shopify
hash[3] = :Lazada
hash[13] = :Zalora
hash[18] = :Zilingo
end.freeze
Instance Attribute Summary
#bundles, #existing_alloc_stocks, #item_bundle_variants, #lazada_quantity, #listing, #reserved_stocks, #shipping_providers, #shopify_inventory_location, #stock_allocs, #variant_listings, #variants, #wh_spaces, #zalora_reserved_stock, #zilingo_quantity
Instance Method Summary
collapse
#base, #bundle, #bundle_variants, #existing_allocated_stock, #initialize, #listings, #multiwarehouse, #pca, #stock_alloc, #variant, #variant_id, #warehouse, #warehouse_list, #warehouse_mapping, #warehouse_spaces, #warehouses, #wh_mapping
Instance Method Details
#available_quantity(warehouse_space) ⇒ Object
99
100
101
102
103
104
105
106
107
|
# File 'lib/item_builder_mwh/modes/quantity_service.rb', line 99
def available_quantity(warehouse_space)
ItemBuilderMwh::GetQuantityService.new(
listing: listing, stock_alloc: stock_alloc,
variant: variant, bundle_variants: bundle_variants,
existing_allocated_stock: existing_allocated_stock,
listing_wh_sp_quantity: warehouse_space.quantity, wh_routing: wh_routing,
selected_warehouse_space: warehouse_space
).perform
end
|
#channel_name ⇒ Object
67
68
69
|
# File 'lib/item_builder_mwh/modes/quantity_service.rb', line 67
def channel_name
QUANTITY_CHANNEL[listing.channel_id].to_s
end
|
#credential ⇒ Object
87
88
89
90
91
|
# File 'lib/item_builder_mwh/modes/quantity_service.rb', line 87
def credential
return shopify_inventory_location['credential'] if shopify_inventory_location['credential'].present?
nil
end
|
#local_qty ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/item_builder_mwh/modes/quantity_service.rb', line 71
def local_qty
if channel_name == 'Zilingo'
return 0 if zilingo_quantity.blank?
zilingo_quantity[listing.local_id].to_i
elsif channel_name == 'Zalora'
return 0 if zalora_reserved_stock.blank?
zalora_reserved_stock[listing.local_id].to_i
else
return 0 if lazada_quantity.blank?
lazada_quantity[listing.local_id].to_i
end
end
|
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/item_builder_mwh/modes/quantity_service.rb', line 23
def perform
if channel_name == "Shopify"
dataSIL = shopify_inventory_location[listing.local_id]
base.merge!(dataSIL, warehouse: warehouses ) if dataSIL.present?
else
base.merge!(
warehouse: warehouses
)
end
end
|
#qty(warehouse_space) ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/item_builder_mwh/modes/quantity_service.rb', line 53
def qty(warehouse_space)
if channel_name.empty? || channel_name == "Shopify"
available_quantity(warehouse_space)
else
qty_channel(warehouse_space)
end
end
|
#qty_channel(warehouse_space) ⇒ Object
61
62
63
64
65
|
# File 'lib/item_builder_mwh/modes/quantity_service.rb', line 61
def qty_channel(warehouse_space)
class_name = "ItemBuilderMwh::Modes::Quantity::#{channel_name}Service"
qty_channel_service = class_name.constantize
qty_channel_service.new(listing, available_quantity(warehouse_space), local_qty.to_i).perform
end
|
#real_quantity(warehouse_space) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/item_builder_mwh/modes/quantity_service.rb', line 45
def real_quantity(warehouse_space)
if channel_name == 'Zilingo'
qty(warehouse_space)
else
[qty(warehouse_space), 0].sort[1]
end
end
|
#to_h(warehouse_space) ⇒ Object
35
36
37
38
39
40
41
42
43
|
# File 'lib/item_builder_mwh/modes/quantity_service.rb', line 35
def to_h(warehouse_space)
{
id: warehouse_space.warehouse_id,
quantity: warehouse_space.present? ? real_quantity(warehouse_space) : 0,
warehouse_id: warehouse_space.present? ? wh_mapping(
warehouse_space.warehouse_id
) : ''
}
end
|
#wh_routing ⇒ Object
93
94
95
96
97
|
# File 'lib/item_builder_mwh/modes/quantity_service.rb', line 93
def wh_routing
return credential['warehouse_routing'] if credential.present? && credential['warehouse_routing'].present?
0
end
|