diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 6ba226f222..470e88ac8e 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -208,6 +208,10 @@ module Spree completed_at.present? end + def invoiceable? + complete? || resumed? + end + # Indicates whether or not the user is allowed to proceed to checkout. # Currently this is implemented as a check for whether or not there is at # least one LineItem in the Order. Feel free to override this logic in your diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index e73de877a0..ca7bccfdc1 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -140,6 +140,23 @@ describe Spree::Order do end end + context "#invoiceable?" do + it "should return true if the order is completed" do + allow(order).to receive_messages(complete?: true) + expect(order.invoiceable?).to be_truthy + end + + it "should return true if the order is resumed" do + allow(order).to receive_messages(resumed?: true) + expect(order.invoiceable?).to be_truthy + end + + it "should return false if the order is neither completed nor resumed" do + allow(order).to receive_messages(complete?: false, resumed?: false) + expect(order.invoiceable?).to be_falsy + end + end + context "checking if order is paid" do context "payment_state is paid" do before { allow(order).to receive_messages payment_state: 'paid' }