tiny_builder 0.0.1 → 0.0.3
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 +3 -3
- data/lib/tiny_builder/base_builder.rb +5 -2
- 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 +37 -3
- data/lib/tiny_builder/quantity_builder.rb +1 -42
- data/lib/tiny_builder/quantity_counter.rb +6 -2
- data/lib/tiny_builder/quantity_helper.rb +69 -0
- data/lib/tiny_builder/version.rb +1 -1
- data/lib/tiny_builder.rb +12 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04cc1bf5a220c6c03096ccaa6f6bf06be337f77966484778fcb21f408f6eb7a2
|
4
|
+
data.tar.gz: 45eecc8cb9a7215fec04a83d62e2d77a0e18f28c567c3d9bc8c109a1b24cfe45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b579532ff0cced210fd2e29391e3eb7115cd1c885de8ba2dfa04319721a0c2ef974bdc06934c548775b51d4c07a8c76aba433030d83c86c2f4cce9c98be5a55b
|
7
|
+
data.tar.gz: 2213bf14478db6fef448d26b2a8b2a5a766c519e960ccc196425d288227ba0f1b0f5a0aa586661c5f6477c1a3e741427370a806f8f974cb6a0247c27fc879678
|
@@ -7,13 +7,13 @@ class TinyBuilder
|
|
7
7
|
def to_h(listing)
|
8
8
|
{
|
9
9
|
active: listing.active,
|
10
|
-
active_variant: active_variant
|
11
|
-
}
|
10
|
+
active_variant: active_variant(listing)
|
11
|
+
}.merge(quantity_hash(listing))
|
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
|
@@ -1,11 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'tiny_builder/data_loader'
|
4
|
+
require 'tiny_builder/quantity_helper'
|
5
|
+
require 'tiny_builder/quantity_counter'
|
4
6
|
|
5
7
|
class TinyBuilder
|
6
8
|
class BaseBuilder
|
7
|
-
DataLoader
|
8
|
-
|
9
|
+
include DataLoader
|
10
|
+
include QuantityHelper
|
11
|
+
|
9
12
|
attr_reader :listings
|
10
13
|
attr_reader :mwh
|
11
14
|
|
@@ -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
|
@@ -5,12 +5,46 @@ require 'tiny_builder/base_builder'
|
|
5
5
|
class TinyBuilder
|
6
6
|
class PriceBuilder < BaseBuilder
|
7
7
|
def to_h(listing)
|
8
|
+
if mwh
|
9
|
+
{ warehouse: warehouse_prices(listing) }
|
10
|
+
else
|
11
|
+
price_hash(listing)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def price_hash(listing)
|
8
16
|
{
|
9
17
|
price: listing.price,
|
10
|
-
sale_price: listing
|
11
|
-
sale_start_at: listing
|
12
|
-
sale_end_at: listing
|
18
|
+
sale_price: sale_price(listing),
|
19
|
+
sale_start_at: sale_start_at(listing),
|
20
|
+
sale_end_at: sale_end_at(listing)
|
13
21
|
}
|
14
22
|
end
|
23
|
+
|
24
|
+
def warehouse_prices(listing)
|
25
|
+
[
|
26
|
+
{
|
27
|
+
warehouse_id: 'no-wh-for-price'
|
28
|
+
}.merge(price_hash(listing))
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
def sale_price(listing)
|
33
|
+
listing.sale_price
|
34
|
+
rescue
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def sale_start_at(listing)
|
39
|
+
listing.sale_start_at
|
40
|
+
rescue
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def sale_end_at(listing)
|
45
|
+
listing.sale_end_at
|
46
|
+
rescue
|
47
|
+
nil
|
48
|
+
end
|
15
49
|
end
|
16
50
|
end
|
@@ -1,52 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'tiny_builder/base_builder'
|
4
|
-
require 'tiny_builder/quantity_counter'
|
5
4
|
|
6
5
|
class TinyBuilder
|
7
6
|
class QuantityBuilder < BaseBuilder
|
8
7
|
def to_h(listing)
|
9
|
-
|
10
|
-
{ warehouse: warehouse_quantities(listing) }
|
11
|
-
else
|
12
|
-
{ quantity: quantity(listing) }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def warehouse_quantities(listing)
|
17
|
-
results = multi_warehouse_spaces(listing).map do |wh_space|
|
18
|
-
{
|
19
|
-
id: wh_space&.warehouse_id,
|
20
|
-
quantity: quantity(listing, wh_space),
|
21
|
-
warehouse_id: mapped_wh_mappings[wh_space.warehouse_id]
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def quantity(listing, wh_space = nil)
|
27
|
-
QuantityCounter.new(
|
28
|
-
counter_params(listing, wh_space)
|
29
|
-
).perform
|
30
|
-
end
|
31
|
-
|
32
|
-
def counter_params(listing, wh_space = nil)
|
33
|
-
params = mapped_data[listing.icava_id].slice(:variant, :stock_alloc, :associated_stock_allocs)
|
34
|
-
wh_space ||= single_warehouse_space(mapped_data[listing.icava_id][:warehouse_spaces])
|
35
|
-
params.merge(warehouse_space: wh_space)
|
36
|
-
end
|
37
|
-
|
38
|
-
def single_warehouse_space
|
39
|
-
if warehouse_id
|
40
|
-
warehuse_spaces.find{ |wh_space| wh_space.warehouse_id == wh_id }
|
41
|
-
else
|
42
|
-
warehuse_spaces.last
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def multi_warehouse_spaces(listing)
|
47
|
-
mapped_data[listing.icava_id][:warehouse_spaces].select do |wh_space|
|
48
|
-
warehouse_mappings.map(&:warehouse_id).include?(wh_space.warehouse_id)
|
49
|
-
end
|
8
|
+
quantity_hash(listing)
|
50
9
|
end
|
51
10
|
end
|
52
11
|
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
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TinyBuilder
|
4
|
+
module QuantityHelper
|
5
|
+
def quantity_hash(listing)
|
6
|
+
if mwh
|
7
|
+
{ warehouse: warehouse_quantities(listing) }
|
8
|
+
else
|
9
|
+
{ quantity: quantity(listing) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def warehouse_quantities(listing)
|
14
|
+
multi_warehouse_spaces(listing).map do |wh_space|
|
15
|
+
{
|
16
|
+
id: wh_space&.warehouse_id,
|
17
|
+
quantity: quantity(listing, wh_space),
|
18
|
+
warehouse_id: mapped_wh_mappings[wh_space.warehouse_id]
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def quantity(listing, wh_space = nil)
|
24
|
+
QuantityCounter.new(
|
25
|
+
counter_params(listing, wh_space)
|
26
|
+
).perform
|
27
|
+
end
|
28
|
+
|
29
|
+
def counter_params(listing, wh_space = nil)
|
30
|
+
params = mapped_data[listing.icava_id].slice(:variant, :stock_alloc, :associated_stock_allocs)
|
31
|
+
wh_space ||= single_warehouse_space(listing)
|
32
|
+
params.merge(warehouse_space: wh_space)
|
33
|
+
end
|
34
|
+
|
35
|
+
def single_warehouse_space(listing)
|
36
|
+
variant_wh_spaces = wh_spaces(listing)
|
37
|
+
if warehouse_mapping
|
38
|
+
variant_wh_spaces.find{ |wh_space| wh_space.warehouse_id == warehouse_mapping.warehouse_id }
|
39
|
+
else
|
40
|
+
variant_wh_spaces.last
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def multi_warehouse_spaces(listing)
|
45
|
+
wh_spaces(listing).select do |wh_space|
|
46
|
+
warehouse_mappings.map(&:warehouse_id).include?(wh_space.warehouse_id)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def bundle_warehouse_spaces(variant)
|
51
|
+
bundle = MasterProduct.find_by("bundle_variants.master_variant_id": variant.id)
|
52
|
+
variant_id = bundle.bundle_variants.find { |bv| !bv[:main] }[:master_variant_id]
|
53
|
+
WarehouseSpace.where(
|
54
|
+
item_variant_id: variant_id
|
55
|
+
).where.not(
|
56
|
+
warehouse_id: nil
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def wh_spaces(listing)
|
61
|
+
variant = mapped_data[listing.icava_id][:variant]
|
62
|
+
wh_spaces = if variant.config == 'default'
|
63
|
+
mapped_data[listing.icava_id][:warehouse_spaces]
|
64
|
+
else
|
65
|
+
bundle_warehouse_spaces(variant)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
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
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hayakaza
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/tiny_builder/price_builder.rb
|
142
142
|
- lib/tiny_builder/quantity_builder.rb
|
143
143
|
- lib/tiny_builder/quantity_counter.rb
|
144
|
+
- lib/tiny_builder/quantity_helper.rb
|
144
145
|
- lib/tiny_builder/version.rb
|
145
146
|
homepage:
|
146
147
|
licenses: []
|