solidus_core 2.4.0.beta1 → 2.4.0.rc1

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.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 780ddce063f4f0cb4182e2409c326a0c67af6d17
4
- data.tar.gz: d07bc3bed5b865e1fa058457b1ea0a29450cdb33
3
+ metadata.gz: 7ab7a222e9a608b36c6772f3d1f68407a6b97e46
4
+ data.tar.gz: 551e309a2b550305f02f80300c217c8f4e5d894e
5
5
  SHA512:
6
- metadata.gz: 8ea1a5401f592da810efbba723f7766bf617c88e9a55803cc6b887374276dafbe798c367615b7f0bb42d6855e307de9f14cee9effe9596d44f0dc19916ec98cf
7
- data.tar.gz: aad148fef039045c3c994ca4e32f5fb60b4793079d57e1c598b9f7791bcbe935aef9d70b407663c91b43414585d2bffbb366d4b44b7d0c937bd9027560df7a15
6
+ metadata.gz: e90f8698ec8213e501f72a04bf4f8f2e2de96d5d5fca1914cc7c71554e0a7cce7d10b2396ce076069431f7442904f1a3a18273babe1766e3da8e61e24feebe99
7
+ data.tar.gz: f2041f442f02364460b57d5265967410795caad8f15d25de36bc5b8fb7835286d509c3dce793829bffe173d06e5f8dc65eebfad97c3401effd1bdad9220787eb
@@ -43,17 +43,21 @@ module Spree
43
43
  return false if invalid?
44
44
  desired_shipment.save! if desired_shipment.new_record?
45
45
 
46
- new_on_hand_quantity = [desired_shipment.stock_location.count_on_hand(variant), quantity].min
46
+ # Retrieve how many on hand items we can take from desired stock location
47
+ available_quantity = [desired_shipment.stock_location.count_on_hand(variant), 0].max
48
+
49
+ new_on_hand_quantity = [available_quantity, quantity].min
50
+ unstock_quantity = desired_shipment.stock_location.backorderable?(variant) ? quantity : new_on_hand_quantity
47
51
 
48
52
  ActiveRecord::Base.transaction do
49
53
  if handle_stock_counts?
50
54
  # We only run this query if we need it.
51
- current_on_hand_quantity = [current_shipment.inventory_units.on_hand.size, quantity].min
55
+ current_on_hand_quantity = [current_shipment.inventory_units.pre_shipment.size, quantity].min
52
56
 
53
57
  # Restock things we will not fulfil from the current shipment anymore
54
58
  current_stock_location.restock(variant, current_on_hand_quantity, current_shipment)
55
59
  # Unstock what we will fulfil with the new shipment
56
- desired_stock_location.unstock(variant, new_on_hand_quantity, desired_shipment)
60
+ desired_stock_location.unstock(variant, unstock_quantity, desired_shipment)
57
61
  end
58
62
 
59
63
  # These two statements are the heart of this class. We change the number
@@ -11,14 +11,18 @@ module Spree
11
11
 
12
12
  def activate
13
13
  connected_promotions.each do |order_promotion|
14
- order_promotion.promotion.activate(
15
- order: order,
16
- promotion_code: order_promotion.promotion_code,
17
- )
14
+ if order_promotion.promotion.eligible?(order)
15
+ order_promotion.promotion.activate(
16
+ order: order,
17
+ promotion_code: order_promotion.promotion_code,
18
+ )
19
+ end
18
20
  end
19
21
 
20
22
  not_connected_automatic_promotions.each do |promotion|
21
- promotion.activate(order: order)
23
+ if promotion.eligible?(order)
24
+ promotion.activate(order: order)
25
+ end
22
26
  end
23
27
  end
24
28
 
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  def self.solidus_version
3
- "2.4.0.beta1"
3
+ "2.4.0.rc1"
4
4
  end
5
5
 
6
6
  def self.solidus_gem_version
@@ -110,12 +110,12 @@ RSpec.describe Spree::FulfilmentChanger do
110
110
  stock_item.update(backorderable: true)
111
111
  end
112
112
 
113
- it "restocks five at the original stock location" do
113
+ it "restocks seven at the original stock location" do
114
114
  expect { subject }.to change { current_shipment.stock_location.count_on_hand(variant) }.by(7)
115
115
  end
116
116
 
117
- it "unstocks five at the desired stock location" do
118
- expect { subject }.to change { desired_shipment.stock_location.count_on_hand(variant) }.by(-5)
117
+ it "unstocks seven at the desired stock location" do
118
+ expect { subject }.to change { desired_shipment.stock_location.count_on_hand(variant) }.by(-7)
119
119
  end
120
120
 
121
121
  it "creates a shipment with the correct number of on hand and backordered units" do
@@ -124,6 +124,24 @@ RSpec.describe Spree::FulfilmentChanger do
124
124
  expect(desired_shipment.inventory_units.backordered.count).to eq(2)
125
125
  end
126
126
 
127
+ context "when the desired stock location already has a backordered units" do
128
+ let(:desired_count_on_hand) { -1 }
129
+
130
+ it "restocks seven at the original stock location" do
131
+ expect { subject }.to change { current_shipment.stock_location.count_on_hand(variant) }.by(7)
132
+ end
133
+
134
+ it "unstocks seven at the desired stock location" do
135
+ expect { subject }.to change { desired_shipment.stock_location.count_on_hand(variant) }.by(-7)
136
+ end
137
+
138
+ it "creates a shipment with the correct number of on hand and backordered units" do
139
+ subject
140
+ expect(desired_shipment.inventory_units.on_hand.count).to eq(0)
141
+ expect(desired_shipment.inventory_units.backordered.count).to eq(7)
142
+ end
143
+ end
144
+
127
145
  context "when the original shipment has on hand and backordered units" do
128
146
  before do
129
147
  current_shipment.inventory_units.limit(6).update_all(state: :backordered)
@@ -137,16 +155,21 @@ RSpec.describe Spree::FulfilmentChanger do
137
155
  end
138
156
 
139
157
  context "when the original shipment had some backordered units" do
158
+ let(:current_stock_item) { current_shipment.stock_location.stock_items.find_by(variant: variant) }
159
+ let(:desired_stock_item) { desired_shipment.stock_location.stock_items.find_by(variant: variant) }
160
+ let(:backordered_units) { 6 }
161
+
140
162
  before do
141
- current_shipment.inventory_units.limit(6).update_all(state: :backordered)
163
+ current_shipment.inventory_units.limit(backordered_units).update_all(state: :backordered)
164
+ current_stock_item.set_count_on_hand(-backordered_units)
142
165
  end
143
166
 
144
167
  it "restocks four at the original stock location" do
145
- expect { subject }.to change { current_shipment.stock_location.count_on_hand(variant) }.by(4)
168
+ expect { subject }.to change { current_stock_item.reload.count_on_hand }.from(-backordered_units).to(1)
146
169
  end
147
170
 
148
171
  it "unstocks five at the desired stock location" do
149
- expect { subject }.to change { desired_shipment.stock_location.count_on_hand(variant) }.by(-5)
172
+ expect { subject }.to change { desired_stock_item.reload.count_on_hand }.from(5).to(-2)
150
173
  end
151
174
 
152
175
  it "creates a shipment with the correct number of on hand and backordered units" do
@@ -13,8 +13,20 @@ module Spree
13
13
  context 'with apply_automatically' do
14
14
  let!(:promotion) { create(:promotion, apply_automatically: true, promotion_actions: [action]) }
15
15
 
16
- it "creates the adjustment" do
17
- expect { subject.activate }.to change { shipment.adjustments.count }.by(1)
16
+ context 'for eligible promotion' do
17
+ it "creates the adjustment" do
18
+ expect { subject.activate }.to change { shipment.adjustments.count }.by(1)
19
+ end
20
+ end
21
+
22
+ context 'for ineligible promotion' do
23
+ let!(:promotion) do
24
+ create(:promotion, :with_item_total_rule, item_total_threshold_amount: 1_000, apply_automatically: true, promotion_actions: [action])
25
+ end
26
+
27
+ it "does not create the adjustment" do
28
+ expect { subject.activate }.to change { shipment.adjustments.count }.by(0)
29
+ end
18
30
  end
19
31
  end
20
32
 
@@ -31,6 +43,22 @@ module Spree
31
43
  subject.activate
32
44
  }.to change { shipment.adjustments.count }
33
45
  end
46
+
47
+ context 'when currently ineligible' do
48
+ let(:promotion) do
49
+ create(:promotion, :with_item_total_rule, item_total_threshold_amount: 1_000, code: 'freeshipping', promotion_actions: [action])
50
+ end
51
+
52
+ before do
53
+ order.order_promotions.create!(promotion: promotion, promotion_code: promotion.codes.first)
54
+ end
55
+
56
+ it 'does not adjust the shipment' do
57
+ expect {
58
+ subject.activate
59
+ }.to_not change { shipment.adjustments.count }
60
+ end
61
+ end
34
62
  end
35
63
 
36
64
  context 'when not already applied' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0.beta1
4
+ version: 2.4.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-03 00:00:00.000000000 Z
11
+ date: 2017-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant