This bug has alredy been fixed in Blesta 5.10.0-b2 beta, which was released nine days ago.
I missed the release because b2 beta was not announced in the Blesta software feed reader.
The fix used is the same as a shorter fix included in a post by me below.
The fix I included for the upgrade/downgrade bug is also included in b2 beta.
Thanks Blesta