diff --git a/app/models/variant_override.rb b/app/models/variant_override.rb index b4e3553e1c..cabc309a93 100644 --- a/app/models/variant_override.rb +++ b/app/models/variant_override.rb @@ -52,7 +52,14 @@ class VariantOverride < ApplicationRecord return end - update!(count_on_hand: (count_on_hand || 0) + quantity) + # rubocop:disable Rails/SkipsModelValidations + # Cf. conversation https://github.com/openfoodfoundation/openfoodnetwork/pull/12647 + if quantity > 0 + increment! :count_on_hand, quantity + elsif quantity < 0 + decrement! :count_on_hand, -quantity + end + # rubocop:enable Rails/SkipsModelValidations end def default_stock?