From 8d7a11b0ac18067eaec2ad757fac6a6352069798 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 25 Sep 2018 13:58:41 +0200 Subject: [PATCH] Make all steps of the algorithm have 2 branches --- app/models/product_import/reset_absent.rb | 29 +++++++++++------------ 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/app/models/product_import/reset_absent.rb b/app/models/product_import/reset_absent.rb index d1c0197d9c..f3d08456d4 100644 --- a/app/models/product_import/reset_absent.rb +++ b/app/models/product_import/reset_absent.rb @@ -27,7 +27,7 @@ module ProductImport end end - unless @suppliers_to_reset_inventories.empty? + if @suppliers_to_reset_inventories.present? relation = VariantOverride .where( 'variant_overrides.hub_id IN (?) ' \ @@ -36,21 +36,20 @@ module ProductImport settings.updated_ids ) @products_reset_count += relation.update_all(count_on_hand: 0) + nil + elsif @suppliers_to_reset_products.present? + relation = Spree::Variant + .joins(:product) + .where( + 'spree_products.supplier_id IN (?) ' \ + 'AND spree_variants.id NOT IN (?) ' \ + 'AND spree_variants.is_master = false ' \ + 'AND spree_variants.deleted_at IS NULL', + @suppliers_to_reset_products, + settings.updated_ids + ) + @products_reset_count += relation.update_all(count_on_hand: 0) end - - return if @suppliers_to_reset_products.empty? - - relation = Spree::Variant - .joins(:product) - .where( - 'spree_products.supplier_id IN (?) ' \ - 'AND spree_variants.id NOT IN (?) ' \ - 'AND spree_variants.is_master = false ' \ - 'AND spree_variants.deleted_at IS NULL', - @suppliers_to_reset_products, - settings.updated_ids - ) - @products_reset_count += relation.update_all(count_on_hand: 0) end private