Is using beforeFind() event in background to dynamic update SQL queries a good practice?
It might lead to a ton of refactoring, but have you considered breaking up your code field into multiple columns, and simply ordering by them all?

Beyond that, magic in callbacks is always risky as you've pointed out. But with such a complex requirement for ordering, doing it manually each time doesn't make a lot of sense either.