spree-point-of-sale 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +16 -0
- data/Gemfile +20 -0
- data/LICENSE +23 -0
- data/README.md +71 -0
- data/Rakefile +29 -0
- data/Versionfile +11 -0
- data/app/assets/images/admin/pos/customer.png +0 -0
- data/app/assets/images/admin/pos/del_16.png +0 -0
- data/app/assets/images/admin/pos/plus_16.png +0 -0
- data/app/assets/images/admin/pos/select.jpg +0 -0
- data/app/assets/javascripts/admin/spree_pos.js +20 -0
- data/app/assets/stylesheets/admin/html-label.css +20 -0
- data/app/assets/stylesheets/admin/spree_pos.css +25 -0
- data/app/controllers/spree/admin/barcode_controller.rb +49 -0
- data/app/controllers/spree/admin/checkout_controller_decorator.rb +7 -0
- data/app/controllers/spree/admin/pos_controller.rb +205 -0
- data/app/controllers/spree/admin/stock_locations_controller_decorator.rb +13 -0
- data/app/helpers/admin/barcode_helper.rb +31 -0
- data/app/models/spree/order_decorator.rb +38 -0
- data/app/models/spree/payment_decorator.rb +10 -0
- data/app/models/spree/payment_method/point_of_sale.rb +30 -0
- data/app/models/spree/shipment_decorator.rb +29 -0
- data/app/models/spree/stock/coordinator_decorator.rb +10 -0
- data/app/models/spree/stock_location_decorator.rb +18 -0
- data/app/models/spree/user_decorator.rb +10 -0
- data/app/models/spree/variant_decorator.rb +3 -0
- data/app/overrides/add_barcode_link_for_products_and_variants.rb +21 -0
- data/app/overrides/add_is_pos_filter_to_admin_orders.rb +11 -0
- data/app/overrides/add_pos_button.rb +5 -0
- data/app/overrides/add_store_to_spree_stock_locations.rb +11 -0
- data/app/overrides/admin_adds_pos_config.rb +7 -0
- data/app/overrides/codes.rb +10 -0
- data/app/overrides/pos_tab.rb +6 -0
- data/app/views/spree/admin/barcode/basic.html.erb +28 -0
- data/app/views/spree/admin/invoice/_line_items_invoice.html.erb +34 -0
- data/app/views/spree/admin/invoice/_receipt_header.html.erb +13 -0
- data/app/views/spree/admin/invoice/_totals_receipt.html.erb +25 -0
- data/app/views/spree/admin/invoice/receipt.html.erb +26 -0
- data/app/views/spree/admin/orders/_admin_pos_config.html.erb +5 -0
- data/app/views/spree/admin/orders/_pos_button.html.erb +1 -0
- data/app/views/spree/admin/pos/find.html.erb +81 -0
- data/app/views/spree/admin/pos/show.html.erb +137 -0
- data/app/views/spree/admin/pos/update_stock_location.js.erb +5 -0
- data/app/views/spree/admin/products/_barcode_product_link.html.erb +3 -0
- data/app/views/spree/admin/products/_barcode_variant_link.html.erb +3 -0
- data/config/application.rb +23 -0
- data/config/boot.rb +5 -0
- data/config/initializers/constants.rb +4 -0
- data/config/locales/codes-fi.yml +3 -0
- data/config/locales/en.yml +16 -0
- data/config/locales/fi.yml +8 -0
- data/config/routes.rb +21 -0
- data/db/migrate/20130723140316_add_delivered_at_and_canceled_at_to_spree_shipments.rb +6 -0
- data/db/migrate/20130730102503_add_store_and_address_id_in_spree_stock_locations.rb +8 -0
- data/db/migrate/20131014053417_add_is_pos_to_spree_orders.rb +6 -0
- data/db/migrate/20131025110309_add_card_name_to_spree_payments.rb +5 -0
- data/lib/generators/spree_pos/install/install_generator.rb +27 -0
- data/lib/spree_pos.rb +2 -0
- data/lib/spree_pos/configuration.rb +7 -0
- data/lib/spree_pos/engine.rb +29 -0
- data/spec/constants_spec.rb +8 -0
- data/spec/controllers/spree/admin/barcode_controller_spec.rb +86 -0
- data/spec/controllers/spree/admin/pos_controller_spec.rb +849 -0
- data/spec/models/spree/order_decorator_spec.rb +178 -0
- data/spec/models/spree/payment_decorator_spec.rb +115 -0
- data/spec/models/spree/payment_method/point_of_sale_spec.rb +25 -0
- data/spec/models/spree/shipment_decorator_spec.rb +172 -0
- data/spec/models/spree/stock/coordinator_spec.rb +31 -0
- data/spec/models/spree/stock_location_decorator_spec.rb +43 -0
- data/spec/models/spree/user_decorator_spec.rb +24 -0
- data/spec/models/spree/varaint_decorator_spec.rb +31 -0
- data/spec/spec_helper.rb +67 -0
- data/spree-point-of-sale.gemspec +32 -0
- metadata +183 -0
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Order do
|
4
|
+
let(:user) { mock_model(Spree::User, :email => 'test-user@pos.com') }
|
5
|
+
let(:flat_rate_calculator) { Spree::Calculator::Shipping::FlatRate.create! }
|
6
|
+
let(:country) { Spree::Country.create!(:name => 'mk_country', :iso_name => "mk") }
|
7
|
+
let(:state) { country.states.create!(:name => 'mk_state') }
|
8
|
+
let(:store) { Spree::StockLocation.create!(:name => 'store', :store => true, :address1 => "home", :address2 => "town", :city => "delhi", :zipcode => "110034", :country_id => country.id, :state_id => state.id, :phone => "07777676767") }
|
9
|
+
|
10
|
+
[:state, :is_pos, :completed_at, :payment_state].each do |attribute|
|
11
|
+
it { should allow_mass_assignment_of attribute }
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
@order = Spree::Order.create!(:is_pos => true)
|
16
|
+
@order.stub(:total).and_return 100
|
17
|
+
@variant = Spree::Variant.new
|
18
|
+
@shipment = @order.shipments.new
|
19
|
+
@line_item = @order.line_items.new(:quantity => 1)
|
20
|
+
@line_item.variant = @variant
|
21
|
+
@payment = mock_model(Spree::Payment)
|
22
|
+
@payments = [@payment]
|
23
|
+
@payments.stub(:delete_all).and_return(true)
|
24
|
+
@order.stub(:payments).and_return(@payments)
|
25
|
+
@content = Spree::OrderContents.new(@order)
|
26
|
+
@order.stub(:contents).and_return(@content)
|
27
|
+
@content.stub(:remove).with(@variant, 1, @shipment).and_return(true)
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'scopes' do
|
31
|
+
before :each do
|
32
|
+
@paid_order = Spree::Order.create!(:total => 100)
|
33
|
+
@paid_order.update_column(:payment_state,'paid')
|
34
|
+
@unpaid_pos_order = Spree::Order.create!(:is_pos => true, :payment_state => 'checkout')
|
35
|
+
@paid_pos_order = Spree::Order.create!(:is_pos => true, :payment_state => 'paid')
|
36
|
+
@paid_pos_order.update_column(:payment_state,'paid')
|
37
|
+
@unpaid_order = Spree::Order.create!(:payment_state => 'checkout')
|
38
|
+
end
|
39
|
+
|
40
|
+
it { Spree::Order.pos.should match_array([@order, @unpaid_pos_order, @paid_pos_order]) }
|
41
|
+
it { Spree::Order.unpaid.should match_array([@unpaid_pos_order, @unpaid_order]) }
|
42
|
+
it { Spree::Order.unpaid_pos_order.should eq([@unpaid_pos_order]) }
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#clean!' do
|
46
|
+
before { @order.stub(:assign_shipment_for_pos).and_return(true) }
|
47
|
+
it { @payments.should_receive(:delete_all).and_return(true) }
|
48
|
+
it { @line_item.should_receive(:variant).and_return(@variant) }
|
49
|
+
it { @line_item.should_receive(:quantity).and_return(1) }
|
50
|
+
it { @content.should_receive(:remove).with(@variant, 1, @shipment).and_return(true) }
|
51
|
+
it { @order.should_receive(:assign_shipment_for_pos).and_return(true) }
|
52
|
+
after { @order.clean! }
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#complete_via_pos' do
|
56
|
+
before do
|
57
|
+
@order.stub(:create_tax_charge!).and_return(true)
|
58
|
+
@order.stub(:pending_payments).and_return(@payments)
|
59
|
+
@payment.stub(:capture!).and_return(true)
|
60
|
+
@shipment.stub(:finalize_pos).and_return(true)
|
61
|
+
@order.stub(:deliver_order_confirmation_email).and_return(true)
|
62
|
+
@order.stub(:save!).and_return(true)
|
63
|
+
end
|
64
|
+
|
65
|
+
it { @order.should_receive(:touch).with(:completed_at) }
|
66
|
+
it { @order.should_receive(:create_tax_charge!).and_return(true) }
|
67
|
+
it { @order.should_receive(:pending_payments).and_return(@payments) }
|
68
|
+
it { @payment.should_receive(:capture!).and_return(true) }
|
69
|
+
it { @shipment.should_receive(:finalize_pos).and_return(true) }
|
70
|
+
it { @order.should_receive(:deliver_order_confirmation_email).and_return(true) }
|
71
|
+
it { @order.should_receive(:save!).and_return(true) }
|
72
|
+
|
73
|
+
after { @order.complete_via_pos }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#assign_shipment_for_pos' do
|
77
|
+
context '#is_pos?' do
|
78
|
+
before do
|
79
|
+
@order = Spree::Order.create!(:is_pos => true)
|
80
|
+
shipping_category = Spree::ShippingCategory.create! :name => 'test-category'
|
81
|
+
@shipping_method = Spree::ShippingMethod.new(:name => 'test-method') { |method| method.calculator = flat_rate_calculator }
|
82
|
+
@shipping_method.shipping_categories << shipping_category
|
83
|
+
@shipping_method.save!
|
84
|
+
SpreePos::Config[:pos_shipping] = @shipping_method.name
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'method calls' do
|
88
|
+
it { @order.should_receive(:is_pos?).and_return(true) }
|
89
|
+
|
90
|
+
after { @order.assign_shipment_for_pos }
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'create a shipment for order' do
|
94
|
+
@order.shipments.should be_blank
|
95
|
+
@order.shipments.create_shipment_for_pos_order
|
96
|
+
@order.shipments.count.should eq(1)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context '#is_pos? false' do
|
101
|
+
before { @order.stub(:is_pos?).and_return(false) }
|
102
|
+
|
103
|
+
describe 'method calls' do
|
104
|
+
it { @order.should_receive(:is_pos?).and_return(false) }
|
105
|
+
it { @order.shipments.should_not_receive(:create_shipment_for_pos_order) }
|
106
|
+
|
107
|
+
after { @order.assign_shipment_for_pos }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#save_payment_for_pos' do
|
113
|
+
before do
|
114
|
+
@payments.stub(:delete_all).and_return(true)
|
115
|
+
@payments.stub(:create).with(:amount => 100, :payment_method_id => 1, :card_name => 'MasterCard').and_return(@payment)
|
116
|
+
end
|
117
|
+
it { @payments.should_receive(:delete_all).and_return(true) }
|
118
|
+
it { @payments.should_receive(:create).with(:amount => 100, :payment_method_id => 1, :card_name => 'MasterCard').and_return(@payment) }
|
119
|
+
after { @order.save_payment_for_pos(1, 'MasterCard') }
|
120
|
+
end
|
121
|
+
|
122
|
+
describe '#associate_user_for_pos' do
|
123
|
+
context 'user with email exists' do
|
124
|
+
before do
|
125
|
+
Spree::User.stub(:where).with(:email => user.email).and_return([user])
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'when user is valid' do
|
129
|
+
before { user.stub(:valid?).and_return(true) }
|
130
|
+
|
131
|
+
it { Spree::User.should_receive(:where).with(:email => user.email).and_return([user]) }
|
132
|
+
it { Spree::User.should_not_receive(:create_with_random_password) }
|
133
|
+
it { @order.should_receive(:email=).with(user.email).and_return(true) }
|
134
|
+
after { @order.associate_user_for_pos(user.email) }
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when user is not valid' do
|
138
|
+
before { user.stub(:valid?).and_return(false) }
|
139
|
+
|
140
|
+
it { Spree::User.should_receive(:where).with(:email => user.email).and_return([user]) }
|
141
|
+
it { Spree::User.should_not_receive(:create_with_random_password) }
|
142
|
+
it { @order.should_not_receive(:email=).with(user.email) }
|
143
|
+
after { @order.associate_user_for_pos(user.email) }
|
144
|
+
end
|
145
|
+
|
146
|
+
it { @order.associate_user_for_pos(user.email).should eq(user) }
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'user with email does not exist' do
|
150
|
+
before do
|
151
|
+
@new_user = mock_model(Spree::User)
|
152
|
+
Spree::User.stub(:create_with_random_password).with('new-user@pos.com').and_return(@new_user)
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when new user is valid' do
|
156
|
+
before { @new_user.stub(:valid?).and_return(true) }
|
157
|
+
|
158
|
+
it { Spree::User.should_receive(:where).with(:email => 'new-user@pos.com').and_return([]) }
|
159
|
+
it { Spree::User.should_receive(:create_with_random_password).with('new-user@pos.com').and_return(@new_user) }
|
160
|
+
it { @order.should_receive(:email=).with('new-user@pos.com').and_return(true) }
|
161
|
+
|
162
|
+
after { @order.associate_user_for_pos('new-user@pos.com') }
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when new user is not valid' do
|
166
|
+
before { @new_user.stub(:valid?).and_return(false) }
|
167
|
+
|
168
|
+
it { Spree::User.should_receive(:where).with(:email => 'new-user@pos.com').and_return([]) }
|
169
|
+
it { Spree::User.should_receive(:create_with_random_password).with('new-user@pos.com').and_return(@new_user) }
|
170
|
+
it { @order.should_not_receive(:email=).with(@new_user.email) }
|
171
|
+
|
172
|
+
after { @order.associate_user_for_pos('new-user@pos.com') }
|
173
|
+
end
|
174
|
+
|
175
|
+
it { @order.associate_user_for_pos('new-user@pos.com').should eq(@new_user) }
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Payment do
|
4
|
+
it { should allow_mass_assignment_of :card_name }
|
5
|
+
|
6
|
+
let(:payment_method) { Spree::PaymentMethod.create!(:name => 'test-method') }
|
7
|
+
let(:card_payment_method) { Spree::PaymentMethod.create!(:name => 'card-payment')}
|
8
|
+
let(:order) { Spree::Order.create! }
|
9
|
+
context 'validations' do
|
10
|
+
describe 'payment_method' do
|
11
|
+
context 'pos_order' do
|
12
|
+
before do
|
13
|
+
order.stub(:is_pos?).and_return(true)
|
14
|
+
@payment = Spree::Payment.new
|
15
|
+
@payment.stub(:order).and_return(order)
|
16
|
+
@payment.save
|
17
|
+
end
|
18
|
+
|
19
|
+
it { @payment.errors[:payment_method].should eq(["can't be blank"])}
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'non pos_order' do
|
23
|
+
before do
|
24
|
+
order.stub(:is_pos?).and_return(false)
|
25
|
+
@payment = Spree::Payment.new
|
26
|
+
@payment.stub(:order).and_return(order)
|
27
|
+
@payment.save
|
28
|
+
end
|
29
|
+
|
30
|
+
it { @payment.errors[:payment_method].should be_blank }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'card_name presence' do
|
35
|
+
context 'without payment_method' do
|
36
|
+
before do
|
37
|
+
order.stub(:is_pos?).and_return(true)
|
38
|
+
@payment = Spree::Payment.new
|
39
|
+
@payment.stub(:order).and_return(order)
|
40
|
+
@payment.save
|
41
|
+
end
|
42
|
+
it { @payment.errors[:card_name].should be_blank }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'not pos order' do
|
46
|
+
before do
|
47
|
+
order.stub(:is_pos?).and_return(false)
|
48
|
+
@payment = Spree::Payment.new(:payment_method_id => card_payment_method.id)
|
49
|
+
@payment.stub(:order).and_return(order)
|
50
|
+
@payment.save
|
51
|
+
end
|
52
|
+
it { @payment.errors[:card_name].should be_blank }
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'non card payment method' do
|
56
|
+
before do
|
57
|
+
order.stub(:is_pos?).and_return(true)
|
58
|
+
@payment = Spree::Payment.new(:payment_method_id => payment_method.id)
|
59
|
+
@payment.stub(:order).and_return(order)
|
60
|
+
@payment.save
|
61
|
+
end
|
62
|
+
it { @payment.errors[:card_name].should be_blank }
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'pos order with card payment' do
|
66
|
+
before do
|
67
|
+
order.stub(:is_pos?).and_return(true)
|
68
|
+
@payment = Spree::Payment.new(:payment_method_id => card_payment_method.id)
|
69
|
+
@payment.stub(:order).and_return(order)
|
70
|
+
@payment.save
|
71
|
+
end
|
72
|
+
it { @payment.errors[:card_name].should eq(["can't be blank"]) }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'card_name absence' do
|
77
|
+
context 'without payment_method' do
|
78
|
+
before do
|
79
|
+
@payment = Spree::Payment.new
|
80
|
+
@payment.stub(:order).and_return(order)
|
81
|
+
@payment.save
|
82
|
+
end
|
83
|
+
it { @payment.errors[:base].should be_blank }
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'non card payment method' do
|
87
|
+
context 'with card name' do
|
88
|
+
before do
|
89
|
+
@payment = Spree::Payment.new(:payment_method_id => payment_method.id, :card_name => "MasterCard")
|
90
|
+
@payment.stub(:order).and_return(order)
|
91
|
+
@payment.save
|
92
|
+
end
|
93
|
+
it { @payment.errors[:base].should eq(['No card name to be saved with this payment']) }
|
94
|
+
end
|
95
|
+
context 'no card name' do
|
96
|
+
before do
|
97
|
+
@payment = Spree::Payment.new(:payment_method_id => payment_method.id)
|
98
|
+
@payment.stub(:order).and_return(order)
|
99
|
+
@payment.save
|
100
|
+
end
|
101
|
+
it { @payment.errors[:base].should be_blank }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'with card payment method' do
|
106
|
+
before do
|
107
|
+
@payment = Spree::Payment.new(:payment_method_id => card_payment_method.id)
|
108
|
+
@payment.stub(:order).and_return(order)
|
109
|
+
@payment.save
|
110
|
+
end
|
111
|
+
it { @payment.errors[:base].should be_blank }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::PaymentMethod::PointOfSale do
|
4
|
+
let(:pending_payment) { mock_model(Spree::Payment, :state => 'pending') }
|
5
|
+
let(:complete_payment) { mock_model(Spree::Payment, :state => 'complete') }
|
6
|
+
let(:void_payment) { mock_model(Spree::Payment, :state => 'void') }
|
7
|
+
before { @point_of_sale_payment = Spree::PaymentMethod::PointOfSale.new }
|
8
|
+
it { @point_of_sale_payment.actions.should eq(["capture", "void"]) }
|
9
|
+
it { @point_of_sale_payment.can_capture?(pending_payment).should be_true }
|
10
|
+
it { @point_of_sale_payment.can_capture?(complete_payment).should be_false }
|
11
|
+
it { @point_of_sale_payment.can_void?(pending_payment).should be_true }
|
12
|
+
it { @point_of_sale_payment.can_void?(void_payment).should be_false }
|
13
|
+
it { @point_of_sale_payment.source_required?.should be_false }
|
14
|
+
it { @point_of_sale_payment.payment_profiles_supported?.should be_false }
|
15
|
+
|
16
|
+
it 'voids a payment' do
|
17
|
+
ActiveMerchant::Billing::Response.should_receive(:new).with(true, "", {}, {}).and_return(true)
|
18
|
+
@point_of_sale_payment.void
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'captures a payment' do
|
22
|
+
ActiveMerchant::Billing::Response.should_receive(:new).with(true, "", {}, {}).and_return(true)
|
23
|
+
@point_of_sale_payment.capture
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Shipment do
|
4
|
+
let(:order) { Spree::Order.create! }
|
5
|
+
let(:flat_rate_calculator) { Spree::Calculator::Shipping::FlatRate.create! }
|
6
|
+
let(:country) { Spree::Country.create!(:name => 'mk_country', :iso_name => "mk") }
|
7
|
+
let(:state) { country.states.create!(:name => 'mk_state') }
|
8
|
+
let(:store) { Spree::StockLocation.create!(:name => 'store', :store => true, :address1 => "home", :address2 => "town", :city => "delhi", :zipcode => "110034", :country_id => country.id, :state_id => state.id, :phone => "07777676767") }
|
9
|
+
|
10
|
+
before do
|
11
|
+
@shipment = Spree::Shipment.new
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#finalize_pos' do
|
15
|
+
before do
|
16
|
+
@inventory_unit = mock_model(Spree::InventoryUnit)
|
17
|
+
@inventory_unit.stub(:ship!).and_return(true)
|
18
|
+
@inventory_units = [@inventory_unit]
|
19
|
+
@shipment.stub(:inventory_units).and_return(@inventory_units)
|
20
|
+
@shipment.stub(:state=).with('shipped').and_return(true)
|
21
|
+
@shipment.stub(:touch).with(:delivered_at).and_return(true)
|
22
|
+
@shipment.stub(:save).and_return(true)
|
23
|
+
end
|
24
|
+
|
25
|
+
it { @shipment.should_receive(:state=).with('shipped').and_return(true) }
|
26
|
+
it { @shipment.should_receive(:inventory_units).and_return(@inventory_units) }
|
27
|
+
it { @inventory_unit.should_receive(:ship!).and_return(true) }
|
28
|
+
it { @shipment.should_receive(:touch).with(:delivered_at).and_return(true) }
|
29
|
+
it { @shipment.should_receive(:save).and_return(true) }
|
30
|
+
after { @shipment.finalize_pos }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'create_shipment_for_pos_order' do
|
34
|
+
before do
|
35
|
+
shipping_category = Spree::ShippingCategory.create! :name => 'test-category'
|
36
|
+
@shipping_method = Spree::ShippingMethod.new(:name => 'test-method') { |method| method.calculator = flat_rate_calculator }
|
37
|
+
@shipping_method.shipping_categories << shipping_category
|
38
|
+
@shipping_method.save!
|
39
|
+
SpreePos::Config[:pos_shipping] = @shipping_method.name
|
40
|
+
store.save
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'looks for the first active store' do
|
44
|
+
Spree::StockLocation.should_receive(:stores).and_return(Spree::StockLocation)
|
45
|
+
Spree::StockLocation.should_receive(:active).and_return([store])
|
46
|
+
order.shipments.create_shipment_for_pos_order
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'looks for the config shipping method' do
|
50
|
+
Spree::ShippingMethod.should_receive(:where).with(:name => SpreePos::Config[:pos_shipping]).and_return([@shipping_method])
|
51
|
+
order.shipments.create_shipment_for_pos_order
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'creates a new shipment for the order' do
|
55
|
+
before { order.shipments.create_shipment_for_pos_order }
|
56
|
+
it { order.shipments.count.should eq(1) }
|
57
|
+
it { order.shipments.should_not be_blank }
|
58
|
+
it { order.shipments.first.shipping_method.should eq(@shipping_method) }
|
59
|
+
it { order.shipments.first.stock_location.should eq(store) }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'validate empty inventory' do
|
64
|
+
before do
|
65
|
+
@order = Spree::Order.create!
|
66
|
+
@shipment = @order.shipments.create!
|
67
|
+
@shipment.stock_location = store
|
68
|
+
@shipment.save!
|
69
|
+
@inventory_unit = @shipment.inventory_units.create!
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'not a pos order' do
|
73
|
+
it 'no error on shipment' do
|
74
|
+
@shipment.reload
|
75
|
+
@shipment.save
|
76
|
+
@shipment.errors.should be_blank
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'pos order' do
|
81
|
+
before { @order.update_column(:is_pos, true) }
|
82
|
+
|
83
|
+
context 'stock location present and not changed' do
|
84
|
+
before do
|
85
|
+
@shipment.reload
|
86
|
+
@shipment.stock_location = store
|
87
|
+
@shipment.save
|
88
|
+
end
|
89
|
+
|
90
|
+
it { @shipment.errors[:base].should be_blank }
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'stock location present and changed' do
|
94
|
+
before do
|
95
|
+
@shipment.stock_location = nil
|
96
|
+
@shipment.save!
|
97
|
+
@shipment.reload
|
98
|
+
@shipment.stock_location = store
|
99
|
+
@shipment.save
|
100
|
+
end
|
101
|
+
|
102
|
+
it { @shipment.errors[:base].should eq(["Inventory Units assigned for the order. Please remove them to change stock location"]) }
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'stock_location not present' do
|
106
|
+
before do
|
107
|
+
@shipment.stock_location = nil
|
108
|
+
@shipment.save
|
109
|
+
end
|
110
|
+
|
111
|
+
it { @shipment.errors[:base].should be_blank }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe 'udpate_order_addresses_from_stock_location' do
|
117
|
+
before do
|
118
|
+
@order = Spree::Order.create!
|
119
|
+
@shipment = @order.shipments.create!
|
120
|
+
@shipment.stock_location = store
|
121
|
+
@shipment.save!
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'not a pos order' do
|
125
|
+
before { @order.reload }
|
126
|
+
|
127
|
+
it { @order.ship_address.should be_nil }
|
128
|
+
it { @order.bill_address.should be_nil }
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'pos order' do
|
132
|
+
before { @order.update_column(:is_pos, true) }
|
133
|
+
|
134
|
+
context 'stock location present and not changed' do
|
135
|
+
before do
|
136
|
+
@shipment.reload
|
137
|
+
@shipment.stock_location = store
|
138
|
+
@shipment.save!
|
139
|
+
@order.reload
|
140
|
+
end
|
141
|
+
|
142
|
+
it { @order.ship_address.should be_nil }
|
143
|
+
it { @order.bill_address.should be_nil }
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'stock location present and changed' do
|
147
|
+
before do
|
148
|
+
@shipment.stock_location = nil
|
149
|
+
@shipment.save!
|
150
|
+
@shipment.reload
|
151
|
+
@shipment.stock_location = store
|
152
|
+
@shipment.save!
|
153
|
+
@order.reload
|
154
|
+
end
|
155
|
+
|
156
|
+
it { @order.ship_address.should eq(store.address) }
|
157
|
+
it { @order.bill_address.should eq(store.address) }
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'stock_location not present' do
|
161
|
+
before do
|
162
|
+
@shipment.stock_location = nil
|
163
|
+
@shipment.save!
|
164
|
+
@order.reload
|
165
|
+
end
|
166
|
+
|
167
|
+
it { @order.ship_address.should be_nil }
|
168
|
+
it { @order.bill_address.should be_nil }
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|