I will get all not deleted invoices and check invoice client ‘is_deleted’ and if it is True → mark invoice as deleted too. And then, I believe, the invoice number will be available for creation.
the app should add “_deleted” to the number to free it up.
There is no problem when to delete invoice itself, it works like a charm.
The problem seems when you delete client, client’s invoices numbers are not updated as you described above (add ‘_deleted’ to invoice number)