From 6d22652dfa619815ce5bd25d094a32515751df5f Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Tue, 9 Jul 2024 16:06:45 +0200 Subject: [PATCH] Requested changes on VariantOverrride - change was not exactly equivalent, so reverting + rubo comment --- app/models/variant_override.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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?