It is best explained by the commit that changed the code:
https://github.com/odoo/odoo/commit/fe344c0ad673c9eb5885257476347a5bde62ad93
Closest location picks items in the 'smallest/shortest' location (in alphabetical
order), so it assumes the locations are ordered alphabetically
according to how close they are to the ground.
Assume we have the following stock :
- WH/Stock/Shelf 2
- WH/Stock
- WH/Stock/Shelf 1
Quants would be looked at in the following order :
1. WH/Stock (due to shortest name for the same stock)
2. WH/Stock/Shelf 1 (due to alphabetical order)
3. WH/Stock/Shelf 2