What happens if I purchase a building halfway through construction?

You pay the full purchase price and lose the in-progress production. There are no refunds, discounts, or benefits.

So, you generally want to avoid buying buildings that you have mostly completed.

For units, buying a unit has no effect on the in-progress production.