mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user