Batch posting invoices
As explained in the Jérémy Mousset's presentation posting a lot of invoice must be serialized which limits the speed. Also we see that the problem is because of the strict sequence used to number the invoice. So the solution is to separate into different transactions the numbering and the remaining operations.
Also batch posting is not really needed from the User Interface, it happens when automating processed with scheduled job for example.
So I propose to move in a private method the code of post
and to add a new workflow
method post_bunch
which just set the number (and store to today the missing dates like invoice_date
and payment_term_date
) and after that it calls _post
from the __queue__
.
The post
button will still be available as long as the invoice has no move. This will allow user to manually force the posting after having a number to find the source of a problem. And a check when closing a period will be added to ensure that all numbered invoices on the period date have a move.
The post_bunch
will skip the warnings using #7442 (closed).
Side Note:
- I checked if moving at the end of the transaction the usage of sequence strict but it does not solve really the problem because REPEATABLE READ prevents other transactions started after to use the sequence even if the first one has been committed.
- I think the proposal to use a separate transaction using a two-phase commit not really straight forward because both transactions could create a dead lock situation.