mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-05 02:41:33 +00:00
Remember local stock of backordered products
When retail variants are mapped to wholesale variants, we usually have a some leftover stock at the end of an order cycle. For example, we backordered a slab of 12 cans of tomatoes but our customers bought only 9 of those. Then we have 3 left for the next order cycle. Even when the product is not available for backorder with the supplier, we still want to sell off our leftover stock, the three cans of tomatoes in our example. And it might be that the product will come back in the future.
This commit is contained in:
@@ -88,14 +88,23 @@ module Admin
|
||||
|
||||
# Reset stock for any variants that were removed from the catalog.
|
||||
#
|
||||
# When variants are removed from the remote catalog, there not for sale
|
||||
# anymore. We prevent them from being sold by reseting stock to zero.
|
||||
# When variants are removed from the remote catalog, we can't place
|
||||
# backorders for them anymore. If our copy of the product has limited
|
||||
# stock then we need to set the stock to zero to prevent any more sales.
|
||||
#
|
||||
# But if our product is on-demand/backorderable then our stock level is
|
||||
# a representation of remaining local stock. We then need to limit sales
|
||||
# to this local stock and set on-demand to false.
|
||||
#
|
||||
# We don't delete the variant because it may come back at a later time and
|
||||
# we don't want to lose the connection to previous orders.
|
||||
def reset_absent_variants(catalog)
|
||||
absent_variants(catalog).map do |variant|
|
||||
variant.on_demand = false
|
||||
variant.on_hand = 0
|
||||
if variant.on_demand
|
||||
variant.on_demand = false
|
||||
else
|
||||
variant.on_hand = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ RSpec.describe "DFC Product Import" do
|
||||
.and change { linked_variant.on_demand }.to(true)
|
||||
.and change { linked_variant.on_hand }.by(0)
|
||||
.and change { unlinked_variant.on_demand }.to(false)
|
||||
.and change { unlinked_variant.on_hand }.to(0)
|
||||
.and change { unlinked_variant.on_hand }.by(0)
|
||||
|
||||
product = Spree::Product.last
|
||||
expect(product.variants[0].semantic_links).to be_present
|
||||
|
||||
Reference in New Issue
Block a user