Products with options can be oversold
See original GitHub issueWhen a product is configured with class or product options (not attributes) and tracks stock it possible to oversell the product. This behaviour is visible in the sandbox and in Oscar 1.5.
To reproduce:
- Create a product option, for example, a message to print on a t-shirt.
- Create a product type that uses this option in the dashboard.
- Buy the product multiple times with different messages.
- Edit the basket, changing the quantities to more than are available.
- Stock validation will allow product to be oversold.
If I am not mistaken this is because the availability validation happens at the basket line level and does not take the overall basket state into account. The is_purchase_permitted()
check passes for each line item but should not pass as a whole because there are only 10 t-shirts available for purchase but 13 in the basket.
The options force the same product to be a separate line item (as it should be) but this means that line item validation will not work because there can be multiple lines with the same product. I am not sure the best way to fix this as it requires basket level validation and I had a quick look at the code but did not see a hook for adding this. Any suggestions?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Not sure if this is the proper way but I am putting my solution here in case anybody else runs into this problem. What I ended up doing was taking the suggestion of using
Basket.is_quantity_allowed()
to check the basket totals by passing a line argument:This has to be called somewhere during the
BasketLineForm
cleaning with the line argument passed:I also added a similar check to
CheckoutSessionMixin.check_basket_is_valid()
:This will make sure the basket is valid at checkout.
Once again, not sure if this is the best way but it should work until this gets addressed in subsequent versions.
Is this fixed ?
Metadata-Version: 2.1 Name: django-oscar Version: 3.0