Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow negative stock levels for on-demand products #12536

Merged
merged 2 commits into from
Jun 13, 2024

Conversation

mkllnk
Copy link
Member

@mkllnk mkllnk commented May 31, 2024

ℹ️ Funded Feature. Please track ALL ASSOCIATED WORK under the associated tracking code #11678 DFC Orders

What? Why?

We want to place backorders on a wholesaler's platform when we run out of stock in our local OFN store. This complicates the stock logic though. To allow customers to order more than we have in stock, we set the products to on demand. And we change the logic to still count stock, allowing it to go negative, so that we know how much stock we need to order from the wholesaler.

This PR just prepares the change in OFN stock logic without adding the backordering logic. While it seems to be a fairly easy change, there's potential for subtle bugs around products going out of stock. We may have assumptions in our code that I'm not aware of.

What should we test?

  • Test the checkout of stock controlled items and on-demand items.
  • Test the order creation as admin of those items.
  • Test with producer products and with inventory products (using variant overrides).
  • When a stock controlled product goes out of stock during checkout, we still need to raise an error.
  • When an on-demand product goes out of stock, we should still be able to check out and it should not be marked as out of stock.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

@mkllnk mkllnk added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label May 31, 2024
@mkllnk mkllnk self-assigned this May 31, 2024
We weren't allowing negative stock to stop any bug from accidentally
drawing too much stock. But now we want to implement a backordering
logic that depends on negative stock levels to know how much is needed
to replenish stock levels.
We weren't bothering with stock when items were on demand anyway. But we
want to track stock now so that we can backorder more when local stock
levels become negative.
@mkllnk mkllnk marked this pull request as ready for review May 31, 2024 06:47
Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, good idea to do this in a separate PR first.

@filipefurtad0 filipefurtad0 self-assigned this Jun 12, 2024
@filipefurtad0 filipefurtad0 added the pr-staged-fr staging.coopcircuits.fr label Jun 12, 2024
@filipefurtad0
Copy link
Contributor

Hey again @mkllnk ,

Tested the indicated scenarios:

  • checkout of stock controlled items and on-demand items - OK. Editing the order (as a customer) by removing on-hand items returned these to the initial on-hand value.
  • order creation as admin of those items. - OK
  • with producer products and with inventory products (using variant overrides). - OK

image

Verified that:

  • When a stock controlled product goes out of stock during checkout, we still need to raise an error.

image

  • When an on-demand product goes out of stock, we should still be able to check out and it should not be marked as out of stock.

I'm a bit unsure about this one, I'm probably misunderstanding this. How do we get an on-demand product out of stock? I did checkout on-demand variants, with no change of behavior, so I think we should be good. Please let me know if there is anything else you feel I should cover, on this specific scenario.

Other than that, this looks good to me. Found nothing unusual. Please feel free to merge.

@filipefurtad0 filipefurtad0 removed the pr-staged-fr staging.coopcircuits.fr label Jun 13, 2024
@mkllnk
Copy link
Member Author

mkllnk commented Jun 13, 2024

Great, that's all good. It's a bit confusing but on-demand products still have a stock level. It's ignored during checkout and the shop doesn't show any stock levels, of course. But your screenshots look like you had a product with 0 stock that was set to on demand. That's what I meant with "out of stock" even though it's on demand. And the checkout still worked. 👍

@mkllnk mkllnk merged commit 2f173cb into openfoodfoundation:master Jun 13, 2024
52 checks passed
@mkllnk mkllnk deleted the stock-levels branch June 13, 2024 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants