Scope variant only when inventory is enabled

This commit is contained in:
Gaetan Craig-Riou
2025-06-13 23:50:38 +10:00
parent 8829f6ad03
commit 9e1de75db6
4 changed files with 8 additions and 4 deletions

View File

@@ -15,7 +15,9 @@ module OrderManagement
variant = line_item.variant
next unless variant.stock_item
OpenFoodNetwork::ScopeVariantToHub.new(order.distributor).scope(variant)
if OpenFoodNetwork::FeatureToggle.enabled?(:inventory, order.distributor)
OpenFoodNetwork::ScopeVariantToHub.new(order.distributor).scope(variant)
end
on_hand, backordered = variant.fill_status(line_item.quantity)
package.add variant, on_hand, :on_hand if on_hand.positive?

View File

@@ -34,7 +34,9 @@ module OrderManagement
def price_estimate_for(variant, fallback)
return fallback unless fee_calculator && variant
scoper.scope(variant)
if OpenFoodNetwork::FeatureToggle.enabled?(:inventory, shop)
scoper.scope(variant)
end
fees = fee_calculator.indexed_fees_for(variant)
(variant.price + fees).to_d
end

View File

@@ -29,7 +29,7 @@ module OrderManagement
expect(package.backordered.size).to eq 5
end
it "accounts for variant overrides" do
it "accounts for variant overrides", feature: :inventory do
variant = order.line_items.first.variant
variant.on_hand = 0
variant.on_demand = false

View File

@@ -58,7 +58,7 @@ RSpec.describe OrderManagement::Subscriptions::Estimator do
end
end
context "when variant overrides apply" do
context "when variant overrides apply", feature: :inventory do
let!(:override1) {
create(:variant_override, hub: subscription.shop, variant: sli1.variant, price: 1.2)
}