“It belongs as an accident to beatitude or happiness to be the reward of virtue, so far as anyone attains to beatitude; even as to be the term of generation belongs accidentally to a being, so far as it passes from potentiality to act. As, then, God has being, though not begotten; so He has beatitude, although not acquired by merit.”
The fact that happiness is sometimes — or in our experience, almost always — the result of good actions, doesn’t mean it is that essentially.
In our experience existence is generally is the result of generation, that is, passing from potentiality to act. Yet we believe God exists without having been generated or having passed from potentiality to act.
Just as God can be without having been generated, so also he can be happy without his happiness being the result of things that he has done. He just is, and he just is happy.