Me and a person from University X wrote a (pure mathematics) paper together. Most of the work on this paper happened when I was visiting University X during last summer (they were kind enough to provide a room for me and invite me to give a seminar). It is also worth mentioning that X is located where I come from, so given that I can be quite mobile in my work, I would probably be spending most of the summer there in any case. I am currently a PhD student at University Y, located abroad, and I'm just about to finish my degree. Once this happens, I am going to sign a contract with X (the paperwork is waiting until I graduate).
Now that the paper is finished, I wonder what affiliation it would be ethical of me to mention on the paper. It goes without saying that I should mention Y - that's where my position is at the moment, they are the people giving me funding. However, I would also be happy to mention X - there are various reasons why I would want that, some more valid than other. Would it be right of me to do so?