tiny_builder 0.0.2 → 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/tiny_builder/active_builder.rb +1 -1
- data/lib/tiny_builder/base_builder.rb +4 -1
- data/lib/tiny_builder/price_builder.rb +16 -0
- data/lib/tiny_builder/quantity_builder.rb +1 -62
- data/lib/tiny_builder/quantity_helper.rb +69 -0
- data/lib/tiny_builder/version.rb +1 -1
- 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
|
@@ -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
9
|
include DataLoader
|
8
|
-
|
10
|
+
include QuantityHelper
|
11
|
+
|
9
12
|
attr_reader :listings
|
10
13
|
attr_reader :mwh
|
11
14
|
|
@@ -5,6 +5,14 @@ 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
18
|
sale_price: sale_price(listing),
|
@@ -13,6 +21,14 @@ class TinyBuilder
|
|
13
21
|
}
|
14
22
|
end
|
15
23
|
|
24
|
+
def warehouse_prices(listing)
|
25
|
+
[
|
26
|
+
{
|
27
|
+
warehouse_id: 'no-wh-for-price'
|
28
|
+
}.merge(price_hash(listing))
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
16
32
|
def sale_price(listing)
|
17
33
|
listing.sale_price
|
18
34
|
rescue
|
@@ -1,72 +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
|
-
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(listing)
|
35
|
-
params.merge(warehouse_space: wh_space)
|
36
|
-
end
|
37
|
-
|
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 }
|
42
|
-
else
|
43
|
-
variant_wh_spaces.last
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def multi_warehouse_spaces(listing)
|
48
|
-
wh_spaces(listing).select do |wh_space|
|
49
|
-
warehouse_mappings.map(&:warehouse_id).include?(wh_space.warehouse_id)
|
50
|
-
end
|
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
|
8
|
+
quantity_hash(listing)
|
70
9
|
end
|
71
10
|
end
|
72
11
|
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
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: []
|