mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #11290 from cyrillefr/Orders_in_confirmation_state_cannot_be_completed_by_hub_or_shop
Fix Orders in confirmation state cannot be completed by hub or shop
This commit is contained in:
@@ -140,7 +140,8 @@ module Spree
|
||||
#
|
||||
# Otherwise redirect user to that step
|
||||
def can_transition_to_payment
|
||||
return if @order.payment? || @order.complete? || @order.canceled? || @order.resumed?
|
||||
return if @order.confirmation? || @order.payment? ||
|
||||
@order.complete? || @order.canceled? || @order.resumed?
|
||||
|
||||
flash[:notice] = Spree.t(:fill_in_customer_info)
|
||||
redirect_to spree.edit_admin_order_customer_url(@order)
|
||||
@@ -184,7 +185,8 @@ module Spree
|
||||
end
|
||||
|
||||
def allowed_events
|
||||
%w{capture void_transaction credit refund resend_authorization_email}
|
||||
%w{capture void_transaction credit refund resend_authorization_email
|
||||
capture_and_complete_order}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -67,7 +67,7 @@ module Spree
|
||||
end
|
||||
|
||||
def actions
|
||||
%w{capture void credit resend_authorization_email}
|
||||
%w{capture_and_complete_order void credit resend_authorization_email}
|
||||
end
|
||||
|
||||
def can_resend_authorization_email?(payment)
|
||||
@@ -75,7 +75,7 @@ module Spree
|
||||
end
|
||||
|
||||
# Indicates whether its possible to capture the payment
|
||||
def can_capture?(payment)
|
||||
def can_capture_and_complete_order?(payment)
|
||||
return false if payment.requires_authorization?
|
||||
|
||||
payment.pending? || payment.checkout?
|
||||
|
||||
@@ -47,6 +47,11 @@ module Spree
|
||||
end
|
||||
end
|
||||
|
||||
def capture_and_complete_order!
|
||||
OrderWorkflow.new(order).complete!
|
||||
capture!
|
||||
end
|
||||
|
||||
def void_transaction!
|
||||
return true if void?
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ module Spree
|
||||
class PaymentMethod
|
||||
class Check < Spree::PaymentMethod
|
||||
def actions
|
||||
%w{capture void}
|
||||
%w{capture_and_complete_order void}
|
||||
end
|
||||
|
||||
# Indicates whether its possible to capture the payment
|
||||
def can_capture?(payment)
|
||||
def can_capture_and_complete_order?(payment)
|
||||
['checkout', 'pending'].include?(payment.state)
|
||||
end
|
||||
|
||||
|
||||
@@ -20,5 +20,6 @@
|
||||
.icon-cancel:before,
|
||||
.icon-void:before { @extend .icon-remove, :before; }
|
||||
|
||||
.icon-capture { @extend .icon-ok }
|
||||
.icon-capture,
|
||||
.icon-capture_and_complete_order { @extend .icon-ok }
|
||||
.icon-credit:before { @extend .icon-ok, :before ; }
|
||||
|
||||
@@ -84,7 +84,7 @@ table {
|
||||
background-color: $color-notice;
|
||||
color: $color-1;
|
||||
}
|
||||
.icon-edit:hover, .icon-capture:hover, .icon-ok:hover, .icon-plus:hover, .icon-road:hover {
|
||||
.icon-edit:hover, .icon-capture:hover, .icon-capture_and_complete_order:hover, .icon-ok:hover, .icon-plus:hover, .icon-road:hover {
|
||||
background-color: $color-success;
|
||||
color: $color-1;
|
||||
}
|
||||
|
||||
@@ -34,9 +34,11 @@ button[class*="icon-"] {
|
||||
@extend .icon-remove, :before;
|
||||
}
|
||||
|
||||
.icon-capture {
|
||||
.icon-capture,
|
||||
.icon-capture_and_complete_order {
|
||||
@extend .icon-ok;
|
||||
}
|
||||
|
||||
.icon-credit:before {
|
||||
@extend .icon-ok, :before;
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ table {
|
||||
}
|
||||
.icon-edit:hover,
|
||||
.icon-capture:hover,
|
||||
.icon-capture_and_complete_order:hover,
|
||||
.icon-ok:hover,
|
||||
.icon-plus:hover {
|
||||
background-color: $teal;
|
||||
|
||||
@@ -3865,6 +3865,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
credit_card: "Credit Card"
|
||||
new_payment: "New Payment"
|
||||
capture: "Capture"
|
||||
capture_and_complete_order: "Capture and complete order"
|
||||
void: "Void"
|
||||
login: "Login"
|
||||
password: "Password"
|
||||
|
||||
@@ -28,14 +28,14 @@ module Spree
|
||||
it "should be true if payment is pending" do
|
||||
payment = build_stubbed(:payment, created_at: Time.zone.now)
|
||||
allow(payment).to receive(:pending?) { true }
|
||||
expect(credit_card.can_capture?(payment)).to be_truthy
|
||||
expect(credit_card.can_capture_and_complete_order?(payment)).to be_truthy
|
||||
end
|
||||
|
||||
it "should be true if payment is checkout" do
|
||||
payment = build_stubbed(:payment, created_at: Time.zone.now)
|
||||
allow(payment).to receive_messages pending?: false,
|
||||
checkout?: true
|
||||
expect(credit_card.can_capture?(payment)).to be_truthy
|
||||
expect(credit_card.can_capture_and_complete_order?(payment)).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -889,7 +889,7 @@ describe Spree::Payment do
|
||||
let(:payment) { build_stubbed(:payment, source: build_stubbed(:credit_card)) }
|
||||
|
||||
it "can capture and void" do
|
||||
expect(payment.actions).to match_array %w(capture void)
|
||||
expect(payment.actions).to match_array %w(capture_and_complete_order void)
|
||||
end
|
||||
|
||||
describe "when a payment has been taken" do
|
||||
|
||||
@@ -510,6 +510,20 @@ describe '
|
||||
page.has_selector? "table.index tbody tr" # Wait for JS
|
||||
end
|
||||
|
||||
context 'when order is in confirmation state' do
|
||||
before do
|
||||
order.update(state: 'confirmation')
|
||||
end
|
||||
|
||||
it 'checks order may proceed to payments' do
|
||||
login_as_admin
|
||||
visit spree.edit_admin_order_path(order)
|
||||
|
||||
click_link "Payments"
|
||||
expect(page).to have_content "NEW PAYMENT"
|
||||
end
|
||||
end
|
||||
|
||||
context "as an enterprise manager" do
|
||||
let(:coordinator1) { create(:distributor_enterprise) }
|
||||
let(:coordinator2) { create(:distributor_enterprise) }
|
||||
|
||||
@@ -9,6 +9,7 @@ describe '
|
||||
include AuthenticationHelper
|
||||
|
||||
let(:order) { create(:completed_order_with_fees) }
|
||||
let(:confirmed_order) { create(:order_ready_for_confirmation) }
|
||||
|
||||
describe "payments/new" do
|
||||
it "displays the order balance as the default payment amount" do
|
||||
@@ -67,4 +68,14 @@ describe '
|
||||
expect(order.shipment_state).to eq "pending"
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Capture & complete order' do
|
||||
it 'completes order when capturing payment' do
|
||||
login_as_admin
|
||||
visit spree.admin_order_payments_path confirmed_order
|
||||
expect(page).to have_content "CHECKOUT"
|
||||
page.find('a.icon-capture_and_complete_order').click
|
||||
expect(confirmed_order.reload.state).to eq 'complete'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user