Question on Hartshorne exercise II 5.17(e) I'm trying to solve exercise II 5.17(e) of Hartshorne:

Let $f:X\to Y$ be an affine morphism between schemes (i.e. preimage of every open affine subscheme of $Y$ is still affine), and let $\mathcal{A}=f_* \mathcal{O}_X$.  Show that $f_*$ induces an equivalence of categories from the category of quasi-coherent $\mathcal{O}_X$-modules to the category of quasi-coherent $\mathcal{A}$-modules (i.e. quasi-coherent $\mathcal{O}_Y$-modules having a structure of $\mathcal{A}$-module).

In order to prove this question, it suffices to construct a quasi-coherent $\mathcal{O}_X$-module $\widetilde{\mathcal{M}}$ for any quasi-coherent $\mathcal{A}$-module $\mathcal{M}$, and show the functors $f_*$ and $\tilde{}$ are inverse to each other.
I am trying to construct $\widetilde{\mathcal{M}}$ by gluing sheaves: Since $\mathcal{M}$ is a quasi-coherent $\mathcal{A}$-module, $\mathcal{M}(U)$ has an $\mathcal{A}(U)=\mathcal{O}_X(f^{-1}(U))$- module structure. Then we have a sheaf $\widetilde{\mathcal{M}(U)}$ on affine open subset $f^{-1}(U)$.  To glue up all these $\widetilde{\mathcal{M}(U)}$, we only need to check that, when $U'\subset U$ are open affine subsets, $\widetilde{\mathcal{M}(U)}|_{f^{-1}(U')}\simeq \widetilde{\mathcal{M}(U')}$.  I am stuck here, and my attempt is as follows:
Let $U=\operatorname{Spec}B,U'=\operatorname{Spec}B',f^{-1}(U)=\operatorname{Spec}A,f^{-1}(U')=\operatorname{Spec}A'$.
$$\require{AMScd}
\begin{CD}
f^{-1}(U)=\operatorname{Spec}A @>{f_U}>> \operatorname{Spec}B=U\\
@AAA @AAA \\
f^{-1}(U')=\operatorname{Spec}A' @>{f_{U'}}>> \operatorname{Spec}B'=U'
\end{CD}$$
$$\require{AMScd}
\begin{CD}
B=\mathcal{O}_Y(U) @>>> \mathcal{O}_X(f^{-1}(U))=A\\
@VVV @VVV \\
B'=\mathcal{O}_Y(U') @>>> \mathcal{O}_X(f^{-1}(U'))=A'
\end{CD}$$
Since $\mathcal{M}$ is a quasi-coherent $\mathcal{A}$-module, $\mathcal{M}(U)$ has a $\mathcal{O}_Y(U)=B$-module structure via ring homomorphism $B=\mathcal{O}_Y(U)\to \mathcal{O}_X(f^{-1}(U))=A$. Then $\mathcal{M}$ is a quasi-coherent $\mathcal{O}_Y$-module implies that $\mathcal{M}|_U\simeq {f_U}_*(\widetilde{\mathcal{M}(U)})\simeq \widetilde{_B\mathcal{M}(U)}$, where $f_U:f^{-1}(U)=\operatorname{Spec}A\to\operatorname{Spec}B=U$.  Similarly, we have $\mathcal{M}|_{U'}\simeq \widetilde{_{B'}\mathcal{M}(U')}$.  Since $\mathcal{M}$ is quasi-coherent $\mathcal{O}_Y$-module, $(\mathcal{M}|_U)|_{U'}\simeq \widetilde{B'{\otimes{_B}_B}{\mathcal{M}(U)}}\simeq \mathcal{M}|_{U'} \simeq \widetilde{_{B'}\mathcal{M}(U')}$, which implies that $B'\otimes{_B} _B{\mathcal{M}(U)}\simeq {_{B'}\mathcal{M}(U')}$.
Similarly, $\widetilde{\mathcal{M}(U)}|_{f^{-1}(U')}\simeq \widetilde{\mathcal{M}(U')}$ is equivalent to $A'\otimes_A \mathcal{M}(U)\simeq \mathcal{M}(U')$, but how can we get this from $B'\otimes{_B} _B{\mathcal{M}(U)}\simeq {_{B'}\mathcal{M}(U')}$?
Edit
It seems that the most important fact in my proof is that, ${f_{U'}}_*(\widetilde{\mathcal{M}(U')})\simeq {f_U}_*(\widetilde{\mathcal{M}(U)})|_{U'}\simeq {f_{U'}}_*(\widetilde{\mathcal{M}(U)}|_{f^{-1}(U')})$.  But how can we get $\widetilde{\mathcal{M}(U)}|_{f^{-1}(U')}\simeq \widetilde{\mathcal{M}(U')}$?
 A: I'm not 100% sure I understand everything you wrote, but here is a way to simplify the situation:
To show that the sheaves glue, you actually only need to consider distinguished open sets $D_U(g)\subseteq U$ (for some $g\in\mathcal{O}_X(U)$). This is because for open affines $U,V\subseteq Y$, the affine opens $W\subseteq U\cap V$ which are distinguished both in $U$ and $V$ form a basis of the topology of $U\cap V$.
Now if you have a distinguished open $D_U(g)\subseteq U$, then $f^{-1}D_{U}(g)=D_{f^{-1}U}(f^{\#}(U)(g))$ and thus
$$
\widetilde{\mathcal{M}(U)}(f^{-1}D_{U}(g))\cong\mathcal{M}(U)_{f^{\#}(U)(g)}.
$$
But then as the $\mathcal{A}$-module structure is compatible with the $\mathcal{O}_Y$-module structure via $f^{\#}$, the localisation of $\mathcal{M}(U)$ at $f^{\#}(U)(g)$ as an $\mathcal{A}(U)$-module is the same as the localisation of $\mathcal{M}(U)$ at $g$ as an $\mathcal{O}_Y(U)$-module. But by quasi-coherence we have $\mathcal{M}(U)_g\cong \mathcal{M}(D_U(g))$, so we are done.
From there you can conclude the glueing, and you can also conclude the case where $U'\subseteq U$ is an arbitrary affine open. I don't know if there is a more straightforward way to do this.
Edit: Because it was wished by the OP, even more precisely:
Notice that $\mathcal{M}(U)_g$, which is a priori only an $\mathcal{O}_Y(U)_g$-module, naturally has the structure of an $\mathcal{A}(U)_{h}$-module, where $h:=f^{\#}(U)(g)$ for brevity. Indeed, we can define
$$
\frac{a}{h^n}\cdot\frac{s}{g^m}:=\frac{as}{g^{m+n}},
$$
and verify that this endows $\mathcal{M}(U)_g$ with an $\mathcal{A}(U)_{h}$-module structure. It is then straightforward to see that $\mathcal{M}(U)_h\cong\mathcal{M}(U)_g$ as $\mathcal{A}(U)_h$-modules, and also $\mathcal{M}(U)_g\cong\mathcal{M}(D_U(g))$ as $\mathcal{A}(U)_h\cong\mathcal{A}(D_U(g))$-modules.
Edit 2:
To show that $\mathcal{M}(U)_g\to\mathcal{M}(D_U(g))$ is an $\mathcal{A}(U)_g\to\mathcal{M}(D_U(g))$-module homomorphism, denote by $\rho:\mathcal{M}(U)\to\mathcal{M}(D_U(g))$ the restriction map from $U$ to $D_U(g)$ (and by $\rho^\mathcal{A}$ resp. $\rho^Y$ the corresponding restriction maps of $\mathcal{A}$ resp. $\mathcal{O}_Y$). By definition of $\mathcal{M}$ being an $\mathcal{A}$-module, this is compatible with the action of $\mathcal{A}(U)$ on $\mathcal{M}(U)$ and $\mathcal{M}(D_U(g))$. The mentioned isomorphism is given by
$$
\rho^{\mathcal{M}}_g:\mathcal{M}(U)_g\to\mathcal{M}(D_U(g))\\
\frac{s}{g^m}\mapsto \rho^{Y}(g)^{-m}\rho^{\mathcal{M}}(s).
$$
Similarly, the isomorphism $\mathcal{A}(U)_h\to\mathcal{A}(D_U(g))$ is given by
$$
\rho^{\mathcal{A}}_h:\mathcal{A}(U)_h\to\mathcal{A}(D_U(g))\\
\frac{s}{h^n}\mapsto \rho^{Y}(g)^{-n}\rho^{\mathcal{A}}(s).
$$
Then we may verify that
$$
\rho^{\mathcal{M}}_g\left(\frac{a}{h^n}\cdot\frac{s}{g^m}\right)=\rho^{\mathcal{M}}_g\left(\frac{as}{g^{m+n}}\right)=\rho^Y(g)^{-(m+n)}\rho^\mathcal{M}(as)=\rho^Y(g)^{-(m+n)}\rho^\mathcal{A}(a)\rho^{\mathcal{M}}(s)=\rho_h^{\mathcal{A}}(a/h^n)\rho_g^{\mathcal{M}}(s/g^m).
$$
But all this blabla hides what is actually going on: you have to crucially use that $\mathcal{M}$ is an $\mathcal{A}$-module, so all the restriction maps are compatible with $\mathcal{A}$. Localisation doesn't change anything about this compatibility, because if muliplication is compatible, then division is as well, as soon as it is well defined.
