Skip to content

Commit

Permalink
Merge pull request #3640 from nebulab/spaghetticode/order-shipping-di…
Browse files Browse the repository at this point in the history
…scount

Make Order#shipping_discount consider only credits
  • Loading branch information
kennyadsl authored May 27, 2020
2 parents ac325ef + 439abef commit 822a71d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def currency
end

def shipping_discount
shipment_adjustments.eligible.sum(:amount) * - 1
shipment_adjustments.credit.eligible.sum(:amount) * - 1
end

def to_param
Expand Down
15 changes: 15 additions & 0 deletions core/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1720,4 +1720,19 @@ def generate
end.to change { subject.shipments.count }.by 1
end
end

describe '#shipping_discount' do
let(:shipment) { create(:shipment) }
let(:order) { shipment.order }

let!(:charge_shipment_adjustment) { create :adjustment, adjustable: shipment, amount: 20 }
let!(:shipment_adjustment) { create :adjustment, adjustable: shipment, amount: -10 }
let!(:other_shipment_adjustment) { create :adjustment, adjustable: shipment, amount: -30 }

subject { order.shipping_discount }

it 'sums eligible shipping adjustments with negative amount (credit)' do
expect(subject).to eq 40
end
end
end

0 comments on commit 822a71d

Please sign in to comment.