There may even be the possibility of making a specific contract for this.
But, making a deed regarding the purchase/sale of a house, you must follow the laws of each country for this type of property.
That is, although before you could make a specific contract for this type of situation, now in Portugal you can make this type of purchase according to the normal rules for buying a house.