The existing code should not rely on trigger being executed right after create or write. So we could use the queue to post those actions.
But the evaluation should be done at the queue job in case the record state changed.
Also we could replace the action_model and action_function for a selection like in Cron.
Finally it could be also the occasion to implement #4278 (closed).
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
What do you mean by the evaluation should be done at queue job?
We currently have a notification_email when the invoice is posted which filters that the state is posted. Currently when posting an invoice with zero amount the trigger is executed because the invoice is first moved to posted state and then moved to paid.
But IIUC, if we evaluate the trigge at queue job, the invoice state will be paid directly and the trigger will not be executed, which for me is not the expected behaviour.
I think it is better because how the modularity is managed in Tryton.
My use case which showed the bad behavior is that I got a trigger on sale quotation to send an email. But also I also get the module sale_promotion which applies the promotion on quotation but after the sale has been written to 'quoted'.
So the email is sent with the data before the apply of promotions.
For me, it is clear that trigger should be executed at the end of the transaction. And in your case you should just include the 'paid' state in the trigger condition.
I found that it should also be unique be transaction.
Take for example this scenario:
The setup is based on a draft sale with a trigger to quotation.
During the processing, the sale is written multiple times: set a carrier, compute cost etc. For each of this write calls, the trigger will be queued for the same record because the sale is still in draft (eval is False). Finally the sale is written to quotation and a last trigger is queued.
So at the end of the transaction the same trigger record is called for each time the sale was written until the state change.
So for me, we should keep track of the trigger called during the transaction to call it only once.