How are Status and Points handled with Alliances/Code Share flights?

I’m reasonably new to this and having trouble figuring out how status works when flying with airlines within the same alliance and on code shared flights.  For example, if I fly on a flight that’s code shared between AirNZ and Virgin, and I’m a member of both, what determines where the points and status are earned?  The airline that I book through?  The airline that actually operates the flight? The FF number I quote when booking (if I can provide a Velocity number to AirNZ or vice versa)?  If they go to the wrong airline, is it possible to have them transferred after the fact?

Cheers,