Sorry, but I was unable to test this. I could not find the upgrade button anywhere. Not that it would matter much: in CTP2 all units are part of an Army. It is common knowledge that after being in an Army, a unit can not be upgraded anymore. And generating Great Leaders is even more out of the question
On a more serious note: I assume that you are playing a modded version. My guess is that upgrading will replace the old unit with a brand new one. Whether or not it keeps the old unit's veteran status is up to the designer of the mod.
The altered code
uses the veteran status of the unit when it is involved in combat. It does not modify the veteran status at all.