effective_orders 2.1.7 → 2.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/admin/orders_controller.rb +26 -6
- data/app/models/effective/order.rb +4 -2
- data/app/views/admin/orders/_form.html.haml +1 -5
- data/app/views/admin/orders/_form_mark_as_paid.html.haml +1 -2
- data/app/views/admin/orders/_order_actions.html.haml +6 -0
- data/lib/effective_orders/version.rb +1 -1
- data/spec/controllers/admin/orders_controller_spec.rb +2 -2
- data/spec/dummy/log/test.log +3 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f154bcf1f7cdb3364371b6b2c794c9d4ac232397
|
4
|
+
data.tar.gz: f852ff91b864ffd6a443e0a7fe5a3d23aa4fd1cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6810b9d5300273c7c7b4eafa63b800a6c7a1e58ea0acaf7453785fb030333b13db4f5a4d1287e6db739c2ea6217f100774ab1e3a18074f847e4bdbc9f79a13c
|
7
|
+
data.tar.gz: 4bf6074ecb430326d9a76bace99020685ddb0bad4d4f279fc443dcf3434adef7cccdc06afd773016de172e9696d30663b59cda1556e9b318341a05983087e776
|
@@ -32,15 +32,17 @@ module Admin
|
|
32
32
|
flash[:success] = 'Successfully updated order'
|
33
33
|
end
|
34
34
|
|
35
|
-
redirect_to
|
35
|
+
redirect_to(admin_redirect_path)
|
36
36
|
else
|
37
|
-
flash.now[:danger] =
|
37
|
+
flash.now[:danger] = "Unable to update order: #{@order.errors.full_messages.to_sentence}"
|
38
38
|
render action: :show
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
def new
|
43
43
|
@order = Effective::Order.new
|
44
|
+
@order.user = (User.find(params[:user_id]) rescue nil) if params[:user_id]
|
45
|
+
|
44
46
|
@page_title = 'New Order'
|
45
47
|
|
46
48
|
authorize_effective_order!
|
@@ -60,14 +62,13 @@ module Admin
|
|
60
62
|
@order.attributes = order_params.except(:order_items_attributes, :user_id)
|
61
63
|
|
62
64
|
if @order.create_as_pending
|
63
|
-
path_for_redirect = params[:commit] == 'Save and Add New' ? effective_orders.new_admin_order_path : effective_orders.admin_order_path(@order)
|
64
65
|
message = 'Successfully created order'
|
65
66
|
message << ". #{@order.user.email} has been sent a request for payment." if @order.send_payment_request_to_buyer?
|
66
67
|
flash[:success] = message
|
67
|
-
redirect_to
|
68
|
+
redirect_to(admin_redirect_path)
|
68
69
|
else
|
69
70
|
@page_title = 'New Order'
|
70
|
-
flash.now[:danger] =
|
71
|
+
flash.now[:danger] = "Unable to create order: #{@order.errors.full_messages.to_sentence}"
|
71
72
|
render :new
|
72
73
|
end
|
73
74
|
end
|
@@ -89,6 +90,7 @@ module Admin
|
|
89
90
|
provider: order_params[:payment_provider],
|
90
91
|
card: order_params[:payment_card],
|
91
92
|
email: @order.send_mark_as_paid_email_to_buyer?,
|
93
|
+
skip_buyer_validations: true
|
92
94
|
)
|
93
95
|
rescue => e
|
94
96
|
purchased = false
|
@@ -96,7 +98,7 @@ module Admin
|
|
96
98
|
|
97
99
|
if purchased
|
98
100
|
flash[:success] = 'Order marked as paid successfully'
|
99
|
-
redirect_to
|
101
|
+
redirect_to(admin_redirect_path)
|
100
102
|
else
|
101
103
|
flash.now[:danger] = "Unable to mark order as paid: #{@order.errors.full_messages.to_sentence}"
|
102
104
|
render action: :mark_as_paid
|
@@ -136,5 +138,23 @@ module Admin
|
|
136
138
|
EffectiveOrders.authorized?(self, action_name.to_sym, @order || Effective::Order)
|
137
139
|
end
|
138
140
|
|
141
|
+
def admin_redirect_path
|
142
|
+
# Allow an app to define effective_orders_admin_redirect_path in their ApplicationController
|
143
|
+
path = if self.respond_to?(:effective_orders_admin_redirect_path)
|
144
|
+
effective_orders_admin_redirect_path(params[:commit], @order)
|
145
|
+
end
|
146
|
+
|
147
|
+
return path if path.present?
|
148
|
+
|
149
|
+
case params[:commit]
|
150
|
+
when 'Save and Add New'
|
151
|
+
effective_orders.new_admin_order_path(user_id: @order.user.try(:to_param))
|
152
|
+
when 'Save and Mark as Paid'
|
153
|
+
effective_orders.mark_as_paid_admin_order_path(@order)
|
154
|
+
else
|
155
|
+
effective_orders.admin_order_path(@order)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
139
159
|
end
|
140
160
|
end
|
@@ -61,11 +61,11 @@ module Effective
|
|
61
61
|
validates :tax, presence: true, unless: Proc.new { |order| order.skip_buyer_validations? }
|
62
62
|
|
63
63
|
if EffectiveOrders.require_billing_address # An admin creating a new pending order should not be required to have addresses
|
64
|
-
validates :billing_address, presence: true, unless: Proc.new { |order| order.new_record? && order.pending? }
|
64
|
+
validates :billing_address, presence: true, unless: Proc.new { |order| (order.new_record? && order.pending?) || order.skip_buyer_validations? }
|
65
65
|
end
|
66
66
|
|
67
67
|
if EffectiveOrders.require_shipping_address # An admin creating a new pending order should not be required to have addresses
|
68
|
-
validates :shipping_address, presence: true, unless: Proc.new { |order| order.new_record? && order.pending? }
|
68
|
+
validates :shipping_address, presence: true, unless: Proc.new { |order| (order.new_record? && order.pending?) || order.skip_buyer_validations? }
|
69
69
|
end
|
70
70
|
|
71
71
|
if ((minimum_charge = EffectiveOrders.minimum_charge.to_i) rescue nil).present?
|
@@ -319,6 +319,8 @@ module Effective
|
|
319
319
|
self.payment_provider = provider.to_s
|
320
320
|
self.payment_card = card.to_s.presence || 'none'
|
321
321
|
|
322
|
+
self.skip_buyer_validations = skip_buyer_validations
|
323
|
+
|
322
324
|
save!(validate: validate)
|
323
325
|
|
324
326
|
order_items.each { |item| (item.purchasable.purchased!(self, item) rescue nil) }
|
@@ -25,8 +25,4 @@
|
|
25
25
|
%h3 Internal Note
|
26
26
|
= f.input :note_internal, label: 'Internal note', hint: 'For internal admin use only. This note will never be displayed to the buyer.'
|
27
27
|
|
28
|
-
|
29
|
-
%p.text-right
|
30
|
-
= f.button :submit, 'Save', data: { disable_with: 'Saving...' }
|
31
|
-
= f.button :submit, 'Save and Add New', data: { disable_with: 'Saving...' }
|
32
|
-
= link_to 'Cancel', effective_orders.admin_orders_path
|
28
|
+
= render partial: '/admin/orders/order_actions', locals: { order: @order, form: f, f: f }
|
@@ -28,6 +28,5 @@
|
|
28
28
|
%h3 Note to Buyer
|
29
29
|
= f.input :note_to_buyer, label: 'Note to buyer', hint: 'This is displayed to the buyer on all order receipts.'
|
30
30
|
|
31
|
-
|
32
|
-
= f.button :submit, 'Mark Order as Paid', data: { disable_with: 'Saving...' }
|
31
|
+
= render partial: '/admin/orders/order_actions', locals: { order: @order, form: f, f: f }
|
33
32
|
|
@@ -0,0 +1,6 @@
|
|
1
|
+
%p.text-right
|
2
|
+
= form.button :submit, 'Save', data: { disable_with: 'Saving...' }
|
3
|
+
= form.button :submit, 'Save and Add New', data: { disable_with: 'Saving...' }
|
4
|
+
- unless params[:action] == 'mark_as_paid'
|
5
|
+
= form.button :submit, 'Save and Mark as Paid', data: { disable_with: 'Saving...' }
|
6
|
+
= link_to 'Cancel', effective_orders.admin_orders_path
|
@@ -91,7 +91,7 @@ describe Admin::OrdersController, type: :controller do
|
|
91
91
|
post :create, order_params.merge(commit: button_pressed)
|
92
92
|
|
93
93
|
expect(response).to be_redirect
|
94
|
-
expect(response).to redirect_to EffectiveOrders::Engine.routes.url_helpers.new_admin_order_path
|
94
|
+
expect(response).to redirect_to EffectiveOrders::Engine.routes.url_helpers.new_admin_order_path(user_id: 1)
|
95
95
|
expect(flash[:success]).to eq "Successfully created order. #{assigns(:order).user.email} has been sent a request for payment."
|
96
96
|
end
|
97
97
|
end
|
@@ -132,7 +132,7 @@ describe Admin::OrdersController, type: :controller do
|
|
132
132
|
expect(response).to be_successful
|
133
133
|
expect(response).to render_template :new
|
134
134
|
expect(assigns(:page_title)).to eq 'New Order'
|
135
|
-
expect(flash[:danger]
|
135
|
+
expect(flash[:danger].to_s.include?('Unable to create order')).to eq true
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
data/spec/dummy/log/test.log
CHANGED
@@ -18,3 +18,6 @@
|
|
18
18
|
[1m[36m (0.1ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
19
19
|
[1m[36m (0.1ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
20
20
|
[1m[36m (0.1ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
21
|
+
[1m[36m (0.1ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
22
|
+
[1m[36m (0.2ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
23
|
+
[1m[36m (0.1ms)[0m [1mSELECT MAX("orders"."id") FROM "orders"[0m
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_orders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
@@ -317,6 +317,7 @@ files:
|
|
317
317
|
- app/views/admin/orders/_form.html.haml
|
318
318
|
- app/views/admin/orders/_form_mark_as_paid.html.haml
|
319
319
|
- app/views/admin/orders/_form_note_internal.html.haml
|
320
|
+
- app/views/admin/orders/_order_actions.html.haml
|
320
321
|
- app/views/admin/orders/_order_item_fields.html.haml
|
321
322
|
- app/views/admin/orders/_order_payment_details.html.haml
|
322
323
|
- app/views/admin/orders/index.html.haml
|