To Over come this problem we have an openbravo function to generate the unique document number based on the request that has been processed , And you can able to decide whether you need to create a new document no or you need to use the existing document no based on the business process you need to perform.
Openbravo function is :
ad_sequence_doc("Sequence Name","client Id","Update next sequence or not")
.
For Example :
select ad_sequence_doc("Document_for_Order","ad_client_id","Y")
Y for generating the new Sequence Number , N for retain the previous sequence number.