tiny_builder 0.0.1 → 0.0.2
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 +4 -4
- data/lib/models/mongo_variant_listing.rb +1 -1
- data/lib/tiny_builder/active_builder.rb +2 -2
- data/lib/tiny_builder/base_builder.rb +1 -1
- data/lib/tiny_builder/data_loader.rb +3 -3
- data/lib/tiny_builder/mode_executor.rb +8 -11
- data/lib/tiny_builder/price_builder.rb +21 -3
- data/lib/tiny_builder/quantity_builder.rb +27 -7
- data/lib/tiny_builder/quantity_counter.rb +6 -2
- data/lib/tiny_builder/version.rb +1 -1
- data/lib/tiny_builder.rb +12 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b46b87356444087ac075c399868e32548a53a135a451e1697f1f670b5f4085e
|
4
|
+
data.tar.gz: cb7757ded6ebbbb6d2d10da0a1e143b3e7a815927801372c4aad212121580686
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae0bda9b41bf3be01d1ba27314efa948c618f712b82b1d10b82d01339a3fa6c46a671e2ff9a3b08759d3a85692e3c0b291ff46a12a891c02ef22904a0f3eea6c
|
7
|
+
data.tar.gz: 2798fc7272b2414ce3739bb40a0da74ed9c1cbeb91a7ec6f31afa624a1f099b85b962a87e269ddfb01de991de5727c89736644ec89cc5211947d603bc5a56fcd
|
@@ -7,13 +7,13 @@ class TinyBuilder
|
|
7
7
|
def to_h(listing)
|
8
8
|
{
|
9
9
|
active: listing.active,
|
10
|
-
active_variant: active_variant
|
10
|
+
active_variant: active_variant(listing)
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
def active_variant
|
16
|
+
def active_variant(listing)
|
17
17
|
listing.item_listing.variants.map do |v_id|
|
18
18
|
MongoVariantListing.find(v_id)
|
19
19
|
end.select { |mvl| mvl.active }.size
|
@@ -36,7 +36,7 @@ class TinyBuilder
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def mapped_wh_mappings
|
39
|
-
@mapped_wh_mappings ||= warehouse_mappings.
|
39
|
+
@mapped_wh_mappings ||= warehouse_mappings.pluck(:warehouse_id, :channel_warehouse_id).to_h
|
40
40
|
end
|
41
41
|
|
42
42
|
def associated_listings
|
@@ -53,7 +53,7 @@ class TinyBuilder
|
|
53
53
|
|
54
54
|
def stock_allocations
|
55
55
|
@stock_allocations ||= VariantListingStockAllocation.where(
|
56
|
-
variant_association_id:
|
56
|
+
variant_association_id: listings.map(&:icava_id)
|
57
57
|
).where('end_at >= NOW()')
|
58
58
|
end
|
59
59
|
|
@@ -90,7 +90,7 @@ class TinyBuilder
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def associated_stock_allocs(listing)
|
93
|
-
ids = associated_listings.select{ |l| l.master_variant_id == listing.
|
93
|
+
ids = associated_listings.select{ |l| l.master_variant_id == listing.master_variant_id }.map(&:icava_id)
|
94
94
|
associated_stock_allocations.map do |asa|
|
95
95
|
if ids.include?(asa)
|
96
96
|
asa
|
@@ -2,22 +2,19 @@
|
|
2
2
|
|
3
3
|
class TinyBuilder
|
4
4
|
module ModeExecutor
|
5
|
-
def
|
6
|
-
|
5
|
+
def perform_builder
|
6
|
+
builder_classes[mode].new(
|
7
7
|
listings: listings,
|
8
8
|
mwh: mwh
|
9
9
|
).perform
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def quantity_params(listing)
|
12
|
+
def builder_classes
|
13
|
+
{
|
14
|
+
quantity: TinyBuilder::QuantityBuilder,
|
15
|
+
price: TinyBuilder::PriceBuilder,
|
16
|
+
active: TinyBuilder::ActiveBuilder
|
17
|
+
}
|
21
18
|
end
|
22
19
|
|
23
20
|
def listings
|
@@ -7,10 +7,28 @@ class TinyBuilder
|
|
7
7
|
def to_h(listing)
|
8
8
|
{
|
9
9
|
price: listing.price,
|
10
|
-
sale_price: listing
|
11
|
-
sale_start_at: listing
|
12
|
-
sale_end_at: listing
|
10
|
+
sale_price: sale_price(listing),
|
11
|
+
sale_start_at: sale_start_at(listing),
|
12
|
+
sale_end_at: sale_end_at(listing)
|
13
13
|
}
|
14
14
|
end
|
15
|
+
|
16
|
+
def sale_price(listing)
|
17
|
+
listing.sale_price
|
18
|
+
rescue
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def sale_start_at(listing)
|
23
|
+
listing.sale_start_at
|
24
|
+
rescue
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def sale_end_at(listing)
|
29
|
+
listing.sale_end_at
|
30
|
+
rescue
|
31
|
+
nil
|
32
|
+
end
|
15
33
|
end
|
16
34
|
end
|
@@ -14,7 +14,7 @@ class TinyBuilder
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def warehouse_quantities(listing)
|
17
|
-
|
17
|
+
multi_warehouse_spaces(listing).map do |wh_space|
|
18
18
|
{
|
19
19
|
id: wh_space&.warehouse_id,
|
20
20
|
quantity: quantity(listing, wh_space),
|
@@ -31,22 +31,42 @@ class TinyBuilder
|
|
31
31
|
|
32
32
|
def counter_params(listing, wh_space = nil)
|
33
33
|
params = mapped_data[listing.icava_id].slice(:variant, :stock_alloc, :associated_stock_allocs)
|
34
|
-
wh_space ||= single_warehouse_space(
|
34
|
+
wh_space ||= single_warehouse_space(listing)
|
35
35
|
params.merge(warehouse_space: wh_space)
|
36
36
|
end
|
37
37
|
|
38
|
-
def single_warehouse_space
|
39
|
-
|
40
|
-
|
38
|
+
def single_warehouse_space(listing)
|
39
|
+
variant_wh_spaces = wh_spaces(listing)
|
40
|
+
if warehouse_mapping
|
41
|
+
variant_wh_spaces.find{ |wh_space| wh_space.warehouse_id == warehouse_mapping.warehouse_id }
|
41
42
|
else
|
42
|
-
|
43
|
+
variant_wh_spaces.last
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
46
47
|
def multi_warehouse_spaces(listing)
|
47
|
-
|
48
|
+
wh_spaces(listing).select do |wh_space|
|
48
49
|
warehouse_mappings.map(&:warehouse_id).include?(wh_space.warehouse_id)
|
49
50
|
end
|
50
51
|
end
|
52
|
+
|
53
|
+
def bundle_warehouse_spaces(variant)
|
54
|
+
bundle = MasterProduct.find_by("bundle_variants.master_variant_id": variant.id)
|
55
|
+
variant_id = bundle.bundle_variants.find { |bv| !bv[:main] }[:master_variant_id]
|
56
|
+
WarehouseSpace.where(
|
57
|
+
item_variant_id: variant_id
|
58
|
+
).where.not(
|
59
|
+
warehouse_id: nil
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
def wh_spaces(listing)
|
64
|
+
variant = mapped_data[listing.icava_id][:variant]
|
65
|
+
wh_spaces = if variant.config == 'default'
|
66
|
+
mapped_data[listing.icava_id][:warehouse_spaces]
|
67
|
+
else
|
68
|
+
bundle_warehouse_spaces(variant)
|
69
|
+
end
|
70
|
+
end
|
51
71
|
end
|
52
72
|
end
|
@@ -50,12 +50,12 @@ class TinyBuilder
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def qty_bundle
|
53
|
-
if
|
53
|
+
if bundle_variants.present?
|
54
54
|
qty_list = []
|
55
55
|
bundle_variants.each do |bv|
|
56
56
|
wh_space = WarehouseSpace.find_by(
|
57
57
|
item_variant_id: bv[:master_variant_id],
|
58
|
-
warehouse_id:
|
58
|
+
warehouse_id: warehouse_space&.warehouse_id
|
59
59
|
)
|
60
60
|
qty = wh_space.quantity if wh_space.present?
|
61
61
|
qty ||= 0
|
@@ -69,6 +69,10 @@ class TinyBuilder
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def bundle_variants
|
72
|
+
@bundle_variants ||= search_bundle_variants
|
73
|
+
end
|
74
|
+
|
75
|
+
def search_bundle_variants
|
72
76
|
bundle = MasterProduct.where("bundle_variants.master_variant_id": variant.id).last
|
73
77
|
bundle.bundle_variants.select { |bv| !bv[:main] }
|
74
78
|
end
|
data/lib/tiny_builder/version.rb
CHANGED
data/lib/tiny_builder.rb
CHANGED
@@ -1,26 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
3
|
+
require 'mongoid'
|
4
|
+
require 'models/master_product'
|
5
5
|
require 'models/mongo_item_listing'
|
6
6
|
require 'models/mongo_variant_listing'
|
7
|
+
require 'tiny_builder/version'
|
8
|
+
require 'tiny_builder/mode_executor'
|
9
|
+
require 'tiny_builder/active_builder'
|
10
|
+
require 'tiny_builder/price_builder'
|
11
|
+
require 'tiny_builder/quantity_builder'
|
7
12
|
|
8
13
|
class TinyBuilder
|
9
14
|
include ModeExecutor
|
10
|
-
|
11
|
-
attr_reader :listing_ids, :mode, :multiwarehouse
|
12
15
|
|
13
|
-
|
16
|
+
attr_reader :listing_ids, :mode, :mwh
|
17
|
+
|
18
|
+
def self.build(listing_ids, mode, mwh)
|
14
19
|
new(listing_ids, mode, mwh).perform
|
15
20
|
end
|
16
21
|
|
17
22
|
def initialize(listing_ids, mode, mwh)
|
18
23
|
@listing_ids = listing_ids
|
19
24
|
@mode = mode
|
20
|
-
@
|
25
|
+
@mwh = mwh
|
21
26
|
end
|
22
27
|
|
23
28
|
def perform
|
24
|
-
|
29
|
+
perform_builder
|
25
30
|
end
|
26
31
|
end
|