Invoice validate works with the same Ref value

Hi everyone,

I want to validate invoices through the API, several at the same time. However, sometimes two API calls try to validate (not the same) invoice, but the second one fails because the getNextNumRef(…) gave the same ref. When the validate method want to update the invoice, the database throw “duplicate value” error.

Has anyone encountered this issue, and does anyone have a solution for it?

which dolibarr version are you running?

Depending on what method your using to perform the requests, you can either have the requests run sequentially or you can have a retry mechanism. If the same user is sending multiple request, send the requests sequentially, each request waiting for the preceding request to complete.