When some of the products from Shopping Cart aren't available in stock, then such order would be split into 2 orders:
- where all products are present in stock
- where all products are not present in stock
During split process new order is created and and products that are not available are moved into it. To keep original and created orders associated new order is given same number, but different sub-number:
- original order number: 112233-00
- created order number: 112233-01
Unfortunately code, that assigns new sub-number isn't checking that it's been already used by another, previously processed, order.
Double check new sub-number against existing orders in database before using it in created order.