mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Merge pull request #6197 from cillian/reset-on-demand-on-absent-products
When resetting stock to 0 on absent products in product import also reset the on demand setting
This commit is contained in:
@@ -12,7 +12,7 @@ module Catalog
|
||||
|
||||
return 0 if enterprise_ids.blank?
|
||||
|
||||
reset_variants_on_hand(enterprise_variants_relation)
|
||||
reset_variants_on_hand_and_on_demand(enterprise_variants_relation)
|
||||
end
|
||||
|
||||
private
|
||||
@@ -32,17 +32,19 @@ module Catalog
|
||||
relation.where('spree_variants.id NOT IN (?)', excluded_items_ids)
|
||||
end
|
||||
|
||||
def reset_variants_on_hand(variants)
|
||||
def reset_variants_on_hand_and_on_demand(variants)
|
||||
updated_records_count = 0
|
||||
variants.each do |variant|
|
||||
updated_records_count += 1 if reset_variant_on_hand(variant)
|
||||
updated_records_count += 1 if reset_variant_on_hand_and_on_demand(variant)
|
||||
end
|
||||
updated_records_count
|
||||
end
|
||||
|
||||
def reset_variant_on_hand(variant)
|
||||
def reset_variant_on_hand_and_on_demand(variant)
|
||||
was_on_demand = variant.on_demand
|
||||
variant.on_demand = false
|
||||
variant.on_hand = 0
|
||||
variant.on_hand.zero?
|
||||
variant.on_hand.zero? || was_on_demand
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -91,6 +91,16 @@ module Catalog
|
||||
expect { products_reset.reset(supplier_ids) }.to raise_error RuntimeError
|
||||
end
|
||||
end
|
||||
|
||||
context 'and the variant is on demand' do
|
||||
before { variant.on_demand = true }
|
||||
|
||||
it 'turns off the on demand setting on the variant' do
|
||||
products_reset.reset(supplier_ids)
|
||||
|
||||
expect(variant.reload.on_demand).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user