I have a Model called distribution.plan. When the state attribute is "draft", I can add to a distribution.plan record a number of distribution.entitlement records to the plan. Then the user interface has a "confirm" button, when when that button is clicked, a method of the distribution plan model is called to create stock.moves for each entitlement.
My problem is that if 2 users click (or maybe with some browsers if 1 users double clicks) on the confirm button almost simultaneously, I will get 2 stock move generated for each entitement in the end, which is incorrect.
I can work around this with a SELECT [...] FOR UPDATE NOWAIT statement in the code of the method, but this feels wrong (and it is not an idiom I've encountered in the official addons, it's only used once in stock, and this is not the same use case). So what is the correct (framework-wise) way of dealing with this?