item_builder 0.1.18 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d5296817adbceee44af0d40c56904531f0d83e719e3845a91a331b1c5442167
4
- data.tar.gz: 87abd04e435be4b3dbaf7da63496c9b081f467f142ecf2c05f6b00f79f13126c
3
+ metadata.gz: dea667fd969ce159a690f79ab45f3dd0ebe0994bb88364d43ec37a9b2a18a40d
4
+ data.tar.gz: 13aa7b1c835273396ab747def854d80cba132133b6af0846204d076a8083a343
5
5
  SHA512:
6
- metadata.gz: 8d9e2954488f28ffa4e4ce03718ed29d116703eeb8ee76005c601da879250d022638f8bd93ed318ecf1e4b7d9686047f8fb1d1024b9207fe3585b26ad1fa2600
7
- data.tar.gz: 275d56b3d9313b451571df31fc18166a03ea4e2ca57a50d0b03a2c6bf8d55397543dd229057870ae6784a31be11d89857699ec241c624173f98b4ae5580a68f3
6
+ metadata.gz: 982f5e5de1f4183151b0d1daada4c9fc3cc905f98db69195853fe16f59d65740f146446eec243aba23a2035362ed49ab029218e5ed5d2b0539c212fa8b97a433
7
+ data.tar.gz: d4a60767cff226b0403d2c645b10cf1857bdf5d5e65b9b59e30a6379d3a6e3ea9f6f243095c7dcbf779a7c5fe68ffbf469f60e35362d2855818c04f71c5da31f
@@ -41,9 +41,10 @@ class ItemBuilder
41
41
 
42
42
  def qty_params(listing)
43
43
  {
44
- listing: listing,
45
- wh_spaces: wh_spaces,
46
- variants: variants
44
+ listing: listing, wh_spaces: wh_spaces,
45
+ variants: variants, stock_allocs: stock_allocs,
46
+ bundles: bundles, item_bundle_variants: item_bundle_variants,
47
+ existing_alloc_stocks: existing_alloc_stocks
47
48
  }
48
49
  end
49
50
 
@@ -53,6 +54,41 @@ class ItemBuilder
53
54
  end
54
55
  end
55
56
 
57
+ def existing_alloc_stocks
58
+ @existing_alloc_stocks ||= VariantListingStockAllocation.where(
59
+ variant_association_id: vl_ids
60
+ ).where('ADDTIME(end_at, "07:00") >= NOW()')
61
+ end
62
+
63
+ def vl_ids
64
+ @vl_ids ||= variant_listings.map(&:id).uniq
65
+ end
66
+
67
+ def variant_listings
68
+ @variant_listings ||= VariantListing.where(variant_id: variant_ids)
69
+ end
70
+
71
+ def item_bundle_variants
72
+ @item_bundle_variants ||= BundleVariant.where(
73
+ bundle_id: bundle_ids,
74
+ channel_id: listings[0].channel_id
75
+ )
76
+ end
77
+
78
+ def bundle_ids
79
+ @bundle_ids ||= bundles.map(&:id).uniq
80
+ end
81
+
82
+ def bundles
83
+ @bundles ||= Bundle.where(variant_id: variant_ids).group(:variant_id)
84
+ end
85
+
86
+ def stock_allocs
87
+ @stock_allocs ||= VariantListingStockAllocation.where(
88
+ variant_association_id: variant_ids
89
+ )
90
+ end
91
+
56
92
  def wh_spaces
57
93
  @wh_spaces ||= WarehouseSpace.where(item_variant_id: variant_ids)
58
94
  end
@@ -9,6 +9,9 @@ class ItemBuilder
9
9
  @listing = args.fetch(:listing)
10
10
  @wh_sp = args.fetch(:wh_sp)
11
11
  @variant = args.fetch(:variant)
12
+ @stock_alloc = args.fetch(:stock_alloc)
13
+ @bundle_variants = args.fetch(:bundle_variants)
14
+ @existing_allocated_stock = args.fetch(:existing_allocated_stock)
12
15
  end
13
16
 
14
17
  def perform
@@ -18,7 +21,7 @@ class ItemBuilder
18
21
  # yang masuk di kondisi ini,
19
22
  # artinya akun tersebut ada allocated stock yang aktif
20
23
  allocated_stock
21
- elsif existing_allocated_stock.present?
24
+ elsif @existing_allocated_stock.present?
22
25
  # yang masuk di kondisi ini,
23
26
  # artinya akun tersebut tidak ada allocated stock yang aktif,
24
27
  # namun ada allocated stock yg aktif dari channel lain
@@ -35,25 +38,21 @@ class ItemBuilder
35
38
  def check_consignment_variant?
36
39
  listing.consignment? ||
37
40
  (
38
- !listing.active? && [12, 15].include?(listing.channel_id)
41
+ !listing.active? && [11, 12, 15].include?(listing.channel_id)
39
42
  )
40
43
  end
41
44
 
42
45
  def allocated_stock_active?
43
- listing.present? && stock_alloc.present? && allocated_start_end?
46
+ listing.present? && @stock_alloc.present? && allocated_start_end?
44
47
  end
45
48
 
46
49
  def allocated_start_end?
47
- stock_alloc.start_at.beginning_of_day <= Time.now &&
48
- stock_alloc.end_at.end_of_day >= Time.now
50
+ @stock_alloc.start_at.beginning_of_day <= Time.now &&
51
+ @stock_alloc.end_at.end_of_day >= Time.now
49
52
  end
50
53
 
51
54
  def allocated_stock
52
- stock_alloc.quantity.to_i - one_alloc_rsvd_stock(stock_alloc).to_i
53
- end
54
-
55
- def stock_alloc
56
- @stock_alloc ||= listing.variant_listing_stock_allocation
55
+ @stock_alloc.quantity.to_i - one_alloc_rsvd_stock(@stock_alloc).to_i
57
56
  end
58
57
 
59
58
  # warehouse_stock fungsi untuk mendapatkan available quantity
@@ -76,10 +75,10 @@ class ItemBuilder
76
75
 
77
76
  def qty_bundle
78
77
  # Quantity for bundle config
79
- if bundle_variants.present?
78
+ if @bundle_variants.present?
80
79
  qty_list = []
81
- bundle_variants.each do |bvr|
82
- qty = WarehouseSpace.find_by(item_variant_id: bvr.variant_id)&.quantity
80
+ @bundle_variants.each do |bvr|
81
+ qty = wh_sp.select {|ws| s.variant_id == bvr.variant_id }.first.quantity
83
82
  qty ||= 0
84
83
  qty = qty / bvr.unit
85
84
  qty_list.push(qty)
@@ -90,31 +89,27 @@ class ItemBuilder
90
89
  end
91
90
  end
92
91
 
93
- def bundle_variants
94
- Bundle.where(
95
- 'variant_id = ?', variant.id
96
- ).first.bundle_variants.where(channel_id: listing.channel_id)
92
+ def wh_sp
93
+ @wh_sp ||= WarehouseSpace.where(item_variant_id: variant_ids)
97
94
  end
98
95
 
99
- def listing_wh_sp_quantity
100
- @listing_wh_sp_quantity ||= wh_sp&.quantity || 0
96
+ def variant_ids
97
+ @variant_ids ||= @bundle_variants.map(&:variant_id).uniq
101
98
  end
102
99
 
103
- def existing_allocated_stock
104
- VariantListingStockAllocation.where(
105
- variant_association_id: variant.variant_listings.pluck(:id)
106
- ).where('ADDTIME(end_at, "07:00") >= NOW()')
100
+ def listing_wh_sp_quantity
101
+ @listing_wh_sp_quantity ||= wh_sp&.quantity || 0
107
102
  end
108
103
 
109
104
  def count_existing_alloc_stock
110
- return 0 if existing_allocated_stock.blank?
105
+ return 0 if @existing_allocated_stock.blank?
111
106
 
112
- existing_allocated_stock.sum(:quantity)
107
+ @existing_allocated_stock.sum(:quantity)
113
108
  end
114
109
 
115
110
  def count_alloc_rsvd_stock
116
111
  stock = 0
117
- existing_allocated_stock.each do |allocated_stock|
112
+ @existing_allocated_stock.each do |allocated_stock|
118
113
  stock += one_alloc_rsvd_stock(allocated_stock).to_i
119
114
  end
120
115
  stock
@@ -11,10 +11,18 @@ class ItemBuilder
11
11
  attr_reader :listing
12
12
  attr_reader :wh_spaces
13
13
  attr_reader :variants
14
+ attr_reader :stock_allocs
15
+ attr_reader :bundles
16
+ attr_reader :item_bundle_variants
17
+ attr_reader :existing_alloc_stocks
14
18
  def initialize(args)
15
19
  @listing = args.fetch(:listing)
16
20
  @wh_spaces = args.fetch(:wh_spaces, [])
17
21
  @variants = args.fetch(:variants, [])
22
+ @stock_allocs = args.fetch(:stock_allocs, [])
23
+ @bundles = args.fetch(:bundles, [])
24
+ @item_bundle_variants = args.fetch(:item_bundle_variants, [])
25
+ @existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
18
26
  end
19
27
 
20
28
  def base
@@ -48,12 +48,29 @@ class ItemBuilder
48
48
 
49
49
  def available_quantity
50
50
  ItemBuilder::GetQuantityService.new(
51
- listing: listing,
52
- variant: variant,
53
- wh_sp: warehouse
51
+ listing: listing, variant: variant,
52
+ wh_sp: warehouse, stock_alloc: stock_alloc,
53
+ bundle_variants: bundle_variants,
54
+ existing_allocated_stock: existing_allocated_stock
54
55
  ).perform
55
56
  end
56
57
 
58
+ def existing_allocated_stock
59
+ existing_alloc_stocks.select {|eas| eas.variant_association_id == listing.id }
60
+ end
61
+
62
+ def bundle_variants
63
+ item_bundle_variants.select {|ibv| ibv.bundle_id == bundle.id }
64
+ end
65
+
66
+ def bundle
67
+ bundles.select {|b| b.variant_id == listing.variant_id }.first
68
+ end
69
+
70
+ def stock_alloc
71
+ stock_allocs.select {|sa| sa.variant_association_id == listing.id }.first
72
+ end
73
+
57
74
  def warehouse
58
75
  wh_spaces.select {|ws| ws.item_variant_id == listing.variant_id }.first
59
76
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ItemBuilder
4
- VERSION = '0.1.18'
4
+ VERSION = '0.1.19'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: item_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - okaaryanata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-19 00:00:00.000000000 Z
11
+ date: 2021-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler