You can solve it in this way:
$$\max_{\{(a_1,a_2)\in\mathbb{R}^2_+|(1+\rho)a_1+a_2=(1+\rho)w_1+w_2\}} \left[\left[\max_{\{(x_1,y_1)\in\mathbb{R}^2_+|p_{x,1}x_1+p_{y,1}y_1\leq a_1\}} u(x_1,y_1)\right]+\beta\left[\max_{\{(x_2,y_2)\in\mathbb{R}^2_+|p_{x,2}x_2+p_{y,2}y_2\leq a_2\}} u(x_2,y_2)\right]\right]$$
Another way to write the above problem is as follows:
If $v(p_X, p_Y, M)$ denote the indirect utility function associated with the utility maximisation problem:
$\displaystyle\max_{(x,y)\in\mathbb{R}^2_+} u(x,y)$ subject to $p_Xx+p_Yy\leq M$
then the above problem can be re-written as:
$$\max_{\{(a_1,a_2)\in\mathbb{R}^2_+|(1+\rho)a_1+a_2=(1+\rho)w_1+w_2\}} v(p_{x,1},p_{y,1},a_1)+\beta v(p_{x,2},p_{y,2},a_2)$$$$\max_{\{(a_1,a_2)\in\mathbb{R}^2_+|(1+\rho)a_1+a_2=(1+\rho)w_1+w_2\}} \left(v(p_{x,1},p_{y,1},a_1)+\beta v(p_{x,2},p_{y,2},a_2)\right)$$
which can be written in another way (Bellman-style):
$$\max_{0\leq a_1\leq w_1+ \frac{w_2}{(1+\rho)}} v(p_{x,1},p_{y,1},a_1)+\beta v(p_{x,2},p_{y,2},(1+\rho)w_1+w_2-(1+\rho)a_1)$$$$\max_{0\leq a_1\leq w_1+ \frac{w_2}{(1+\rho)}} \left(v(p_{x,1},p_{y,1},a_1)+\beta v(p_{x,2},p_{y,2},(1+\rho)w_1+w_2-(1+\rho)a_1)\right)$$
Similar example is discussed in this video: https://youtu.be/JsVd7nZ1tvs?feature=shared