Unable to generate document. Only versioned orders can be used for document generation

Hi

When I am trying to download a „Cancellation bill“ from admin order details I am getting the following error and the file is not downloading

{"errors":[{"status":"400","code":"DOCUMENT__GENERATION_ERROR","title":"Bad Request","detail":"Unable to generate document. Only versioned orders can be used for document generation.","meta":{"parameters":[]}}]}

What does that mean? How to download the file?

It is a Shopware bug and the fix is available only in 6.4.0.0 which we cannot use in production.

So please edit the core file vendor/shopware/core/Checkout/Document/DocumentService.php

Replace the file function validateVersion with the following content

private function validateVersion(DocumentEntity $document, Context $context): void
{
    if ($document->getOrderVersionId() === Defaults::LIVE_VERSION) {
        // Only versioned orders can be used for document generation.
        $orderVersionId = $this->orderRepository->createVersion($document->getOrderId(), $context);
        $document->setOrderVersionId($orderVersionId);
        $this->documentRepository->update(
            [
                [
                    'id' => $document->getId(),
                    'orderVersionId' => $orderVersionId,
                ],
            ],
            $context
        );
    }
}

and also replace its function call with $this->validateVersion($document, $context);

There is no other solution for live site users. This is not good at all!