tiny_builder 0.1.2 → 0.1.4
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/allocation.rb +10 -0
- data/lib/models/mongo_warehouse_space.rb +12 -0
- data/lib/tiny_builder/data_loader.rb +2 -29
- data/lib/tiny_builder/quantity_counter.rb +33 -27
- data/lib/tiny_builder/quantity_helper.rb +24 -7
- data/lib/tiny_builder/version.rb +1 -1
- data/lib/tiny_builder.rb +1 -0
- 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: dc3365a83e9b6276f896fc52563bd7af653c2c198f970b174f63549ee344ee08
|
4
|
+
data.tar.gz: 53824d1520b4a1e753a1b284684cd8b45bb6dc86648f172891377b43c21b14dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41923ee186414b21fa694a47dea51bd97f844f34d5aee81825fa1727ab803770c2189ce6dbc119b9235773132bb4a2de87b1cd30e108cb0230187d3b7f1e13c6
|
7
|
+
data.tar.gz: f41d5eb78e4482b4ad3ec4dfa31ab946aa313dfcbdafeaa78041705c03ff817d82c8428fb74828a52ea6cb00bded8664d535fc5264f37ef38840a1f212763ef2
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Allocation
|
4
|
+
include Mongoid::Document
|
5
|
+
include Mongoid::Attributes::Dynamic
|
6
|
+
|
7
|
+
store_in collection: 'warehouse_space_allocations', client: 'inventory'
|
8
|
+
|
9
|
+
belongs_to :warehouse_space, class_name: 'MongoWarehouseSpace'
|
10
|
+
end
|
@@ -9,4 +9,16 @@ class MongoWarehouseSpace
|
|
9
9
|
field :quantity, type: Integer
|
10
10
|
field :item_variant_id, type: Integer
|
11
11
|
field :old_id, type: Integer
|
12
|
+
|
13
|
+
has_many :allocations, class_name: "Allocation"
|
14
|
+
|
15
|
+
def promo_list
|
16
|
+
@promo_list ||= allocations.map do |alloc|
|
17
|
+
alloc.promotions
|
18
|
+
end.flatten
|
19
|
+
end
|
20
|
+
|
21
|
+
def available_quantity
|
22
|
+
@available_quantity ||= allocations.sum(&:quantity)
|
23
|
+
end
|
12
24
|
end
|
@@ -56,18 +56,6 @@ class TinyBuilder
|
|
56
56
|
data
|
57
57
|
end
|
58
58
|
|
59
|
-
def stock_allocations
|
60
|
-
@stock_allocations ||= VariantListingStockAllocation.where(
|
61
|
-
variant_association_id: listings.map(&:icava_id)
|
62
|
-
).where('end_at >= NOW()')
|
63
|
-
end
|
64
|
-
|
65
|
-
def associated_stock_allocations
|
66
|
-
@associated_stock_allocations ||= VariantListingStockAllocation.where(
|
67
|
-
variant_association_id: associated_listings.map(&:icava_id)
|
68
|
-
).where('end_at >= NOW()')
|
69
|
-
end
|
70
|
-
|
71
59
|
def warehouse_spaces
|
72
60
|
@warehouse_spaces ||= get_warehouse_spaces
|
73
61
|
end
|
@@ -90,27 +78,12 @@ class TinyBuilder
|
|
90
78
|
listing.icava_id,
|
91
79
|
{
|
92
80
|
variant: variants.find{ |v| v.id == listing.master_variant_id },
|
93
|
-
warehouse_spaces: listing_warehouse_spaces(listing)
|
94
|
-
stock_alloc: stock_alloc(listing),
|
95
|
-
associated_stock_allocs: associated_stock_allocs(listing)
|
81
|
+
warehouse_spaces: listing_warehouse_spaces(listing)
|
96
82
|
}
|
97
83
|
]
|
98
84
|
end.to_h
|
99
85
|
end
|
100
|
-
|
101
|
-
def stock_alloc(listing)
|
102
|
-
stock_allocations.find{ |sa| sa.variant_association_id == listing.icava_id }
|
103
|
-
end
|
104
|
-
|
105
|
-
def associated_stock_allocs(listing)
|
106
|
-
ids = associated_listings.select{ |l| l.master_variant_id == listing.master_variant_id }.map(&:icava_id)
|
107
|
-
associated_stock_allocations.map do |asa|
|
108
|
-
if ids.include?(asa)
|
109
|
-
asa
|
110
|
-
end
|
111
|
-
end.compact
|
112
|
-
end
|
113
|
-
|
86
|
+
|
114
87
|
def get_mongo_wh_spaces
|
115
88
|
spaces = []
|
116
89
|
MongoWarehouseSpace.in(item_variant_id: variant_ids).where(:warehouse_id.exists => true).each do |ws|
|
@@ -7,37 +7,25 @@ class TinyBuilder
|
|
7
7
|
include AllocatedStock
|
8
8
|
|
9
9
|
attr_reader :variant
|
10
|
-
attr_reader :stock_alloc
|
11
|
-
attr_reader :associated_stock_allocs
|
12
10
|
attr_reader :warehouse_space
|
11
|
+
attr_reader :listing
|
12
|
+
attr_reader :inventory_v2
|
13
|
+
|
13
14
|
def initialize(args)
|
14
15
|
@variant = args[:variant]
|
15
|
-
@stock_alloc = args[:stock_alloc]
|
16
|
-
@associated_stock_allocs = args[:associated_stock_allocs]
|
17
16
|
@warehouse_space = args[:warehouse_space]
|
17
|
+
@listing = args[:listing]
|
18
|
+
@inventory_v2 = args[:inventory_v2]
|
18
19
|
end
|
19
20
|
|
20
21
|
def perform
|
21
|
-
|
22
|
-
# yang masuk di kondisi ini,
|
23
|
-
# artinya akun tersebut ada allocated stock yang aktif
|
24
|
-
count_allocated_stock
|
25
|
-
elsif associated_stock_allocs.present?
|
26
|
-
# yang masuk di kondisi ini,
|
27
|
-
# artinya akun tersebut tidak ada allocated stock yang aktif,
|
28
|
-
# namun ada allocated stock yg aktif dari channel lain
|
29
|
-
warehouse_stock - count_existing_alloc_stock + count_alloc_rsvd_stock
|
30
|
-
else
|
31
|
-
# yang masuk di kondisi ini,
|
32
|
-
# artinya tidak ada allocated stock di item tersebut
|
33
|
-
warehouse_stock
|
34
|
-
end
|
22
|
+
warehouse_stock
|
35
23
|
end
|
36
24
|
|
37
25
|
def warehouse_stock
|
38
26
|
case variant.config.downcase
|
39
27
|
when 'default'
|
40
|
-
qty_default
|
28
|
+
qty_default(warehouse_space)
|
41
29
|
when 'free gift', 'combo'
|
42
30
|
qty_bundle
|
43
31
|
else
|
@@ -45,20 +33,27 @@ class TinyBuilder
|
|
45
33
|
end
|
46
34
|
end
|
47
35
|
|
48
|
-
def qty_default
|
49
|
-
[(
|
36
|
+
def qty_default(wh_space)
|
37
|
+
return [(wh_space&.quantity || 0), 0].max unless inventory_v2
|
38
|
+
|
39
|
+
wh_space&.available_quantity + locked_qty(wh_space)
|
40
|
+
end
|
41
|
+
|
42
|
+
def locked_qty(wh_space)
|
43
|
+
return 0 unless inventory_v2
|
44
|
+
return 0 unless wh_space
|
45
|
+
|
46
|
+
wh_space.promo_list.select do |promo|
|
47
|
+
promo["local_id"] == listing.local_id
|
48
|
+
end.sum{ |promo| promo["quantity"] }
|
50
49
|
end
|
51
50
|
|
52
51
|
def qty_bundle
|
53
52
|
if bundle_variants.present?
|
54
53
|
qty_list = []
|
55
54
|
bundle_variants.each do |bv|
|
56
|
-
wh_space =
|
57
|
-
|
58
|
-
warehouse_id: warehouse_space&.warehouse_id
|
59
|
-
)
|
60
|
-
qty = wh_space.quantity if wh_space.present?
|
61
|
-
qty ||= 0
|
55
|
+
wh_space = get_bundle_wh_space(bv[:master_variant_id])
|
56
|
+
qty = qty_default(wh_space)
|
62
57
|
qty = qty / bv[:bundle_attribute][:quantity]
|
63
58
|
qty_list.push(qty)
|
64
59
|
end
|
@@ -68,6 +63,17 @@ class TinyBuilder
|
|
68
63
|
end
|
69
64
|
end
|
70
65
|
|
66
|
+
def get_bundle_wh_space(item_variant_id)
|
67
|
+
if inventory_v2
|
68
|
+
MongoWarehouseSpace.find_by(item_variant_id: item_variant_id, warehouse_id: warehouse_space&.old_warehouse_id)
|
69
|
+
else
|
70
|
+
WarehouseSpace.find_by(
|
71
|
+
item_variant_id: item_variant_id,
|
72
|
+
warehouse_id: warehouse_space&.warehouse_id
|
73
|
+
)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
71
77
|
def bundle_variants
|
72
78
|
@bundle_variants ||= search_bundle_variants
|
73
79
|
end
|
@@ -29,9 +29,13 @@ class TinyBuilder
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def counter_params(listing, wh_space = nil)
|
32
|
-
params = mapped_data[listing.icava_id].slice(:variant, :stock_alloc, :associated_stock_allocs)
|
33
32
|
wh_space ||= single_warehouse_space(listing)
|
34
|
-
|
33
|
+
{
|
34
|
+
warehouse_space: wh_space,
|
35
|
+
listing: listing,
|
36
|
+
variant: mapped_data[listing.icava_id][:variant],
|
37
|
+
inventory_v2: inventory_v2
|
38
|
+
}
|
35
39
|
end
|
36
40
|
|
37
41
|
def single_warehouse_space(listing)
|
@@ -53,11 +57,16 @@ class TinyBuilder
|
|
53
57
|
bundle = MasterProduct.find_by("bundle_variants.master_variant_id": variant.id)
|
54
58
|
return [] unless bundle
|
55
59
|
variant_id = bundle.bundle_variants.find { |bv| !bv[:main] }[:master_variant_id]
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
60
|
+
|
61
|
+
if inventory_v2
|
62
|
+
get_warehouse_spaces_v2(variant_id)
|
63
|
+
else
|
64
|
+
WarehouseSpace.where(
|
65
|
+
item_variant_id: variant_id
|
66
|
+
).where.not(
|
67
|
+
warehouse_id: nil
|
68
|
+
)
|
69
|
+
end
|
61
70
|
end
|
62
71
|
|
63
72
|
def wh_spaces(listing)
|
@@ -68,5 +77,13 @@ class TinyBuilder
|
|
68
77
|
bundle_warehouse_spaces(variant)
|
69
78
|
end
|
70
79
|
end
|
80
|
+
|
81
|
+
def get_warehouse_spaces_v2(variant_id)
|
82
|
+
spaces = []
|
83
|
+
MongoWarehouseSpace.where(item_variant_id: variant_id).where(:warehouse_id.exists => true).each do |ws|
|
84
|
+
spaces << ws
|
85
|
+
end
|
86
|
+
spaces
|
87
|
+
end
|
71
88
|
end
|
72
89
|
end
|
data/lib/tiny_builder/version.rb
CHANGED
data/lib/tiny_builder.rb
CHANGED
@@ -5,6 +5,7 @@ require 'models/master_product'
|
|
5
5
|
require 'models/mongo_item_listing'
|
6
6
|
require 'models/mongo_variant_listing'
|
7
7
|
require 'models/mongo_warehouse_space'
|
8
|
+
require 'models/allocation'
|
8
9
|
require 'tiny_builder/version'
|
9
10
|
require 'tiny_builder/mode_executor'
|
10
11
|
require 'tiny_builder/active_builder'
|
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.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hayakaza
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,6 +129,7 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- lib/models/allocation.rb
|
132
133
|
- lib/models/master_product.rb
|
133
134
|
- lib/models/mongo_item_listing.rb
|
134
135
|
- lib/models/mongo_variant_listing.rb
|