For this you should use a sequence. The sequence will generate the next number.
An example can be found in Party module, where if a checkbox in Party configuration is checked, then a new party will get it’s code from the configured sequence.
This is not working on concurrent environment. And more over the default value is retrieved when the client is opening the form so when the form is saved this default value may no more be true.
But I guess you do not care about gaps in the sequence so Retrieve highest value of all records - #2 by dotbit is the proper solution.
Otherwise you will have to use a transition to set the number and prevent deleting numbered records.
I believe that using sequences is the right way to do it. I wasn’t aware of them since I just started with tryton.
Since we will be transitioning from an ancient laboratory system we won’t be able to start from test #1, but need to make a cut with the data and continue our lab management with tryton. That’s why I was thinking of the “max value” solution.
But since one can configure start values with sequences, they should be quite appropriate.