Create shipping_rate earlier for callback to work

If the shipping_rate is not created at the time the `#after_save`'s
`#ensure_correct_adjustment` callback is executed its call to
`shipping_method.create_adjustment` won't be executed either.

As a result, the OrderUpdater wasn't able to see any adjustments related
to the shipment causing the order total to be outdated.
This commit is contained in:
Pau Perez
2019-02-12 12:11:55 +01:00
parent ab0b759567
commit 24189ca88e
2 changed files with 3 additions and 8 deletions

View File

@@ -303,9 +303,6 @@ FactoryBot.define do
p = create(:simple_product, distributors: [order.distributor])
FactoryBot.create(:line_item_with_shipment, shipping_fee: proxy.shipping_fee, order: order, product: p)
order.reload
# this will update order shipping fees and also order totals (through order.update!)
order.update_shipping_fees!
end
end
@@ -403,9 +400,10 @@ FactoryBot.define do
transient do
shipping_method { create(:shipping_method) }
end
after(:create) do |shipment, evaluator|
shipment.add_shipping_method(evaluator.shipping_method, true)
shipping_rates { [Spree::ShippingRate.create(shipping_method: shipping_method, selected: true)] }
after(:create) do |shipment, evaluator|
shipment.order.line_items.each do |line_item|
line_item.quantity.times { shipment.inventory_units.create(variant_id: line_item.variant_id) }
end
@@ -432,7 +430,6 @@ FactoryBot.define do
create(:payment, order: order, amount: order.total, payment_method: payment_method, state: 'checkout')
while !order.completed? do break unless order.next! end
order.updater.update_adjustments # this is required to clean up duplicated shipping fees
end
end

View File

@@ -3,9 +3,7 @@ require 'spec_helper'
module OpenFoodNetwork
describe UserBalanceCalculator do
describe "finding the account balance of a user with a hub" do
let!(:user1) { create(:user) }
let!(:hub1) { create(:distributor_enterprise) }