Pólya–Vinogradov like inequality for a character sum with Euler factors Let $M$ be a large positive integer, $d$ an odd positive integer and $f: \mathbb{Z}_{>0} \times \mathbb{Z}_{>0} \to \mathbb{R}$. For a non-principal character $\chi_d = \chi$ with modulus $d$, I am interested in the following type of sums.
$$S(\chi, f) = \sum_{\substack{m = M \\ (m, d) = 1}}^{2M}f(m, d) \chi(m). $$
For $f \equiv 1$, we know that $\lvert S(\chi, f)\rvert \ll \sqrt{d}\log(d)$ by the Pólya–Vinogradov inequality. Now I am interested in bounding $\lvert S(\chi, f)\rvert$ when $$f(m, d) = \frac{\phi(m)}{m} \prod_{\substack{p \textrm{ prime} \\ (p, md) = 1}} \left(1 - \frac{\rho_{m}(p)}{p^2} \right)$$
where $\rho_m(p) = 1 + \genfrac(){}{}m p$ for primes $p$ that do not divide $m$. $\chi_d(m) = \genfrac(){}{}m d$, the Jacobi symbol.
I expect a similar result as the Pólya–Vinogradov inequality. Computational experiments for some $M$, $d$ values did agree with my expectation. Have these types of sums been studied earlier? Any help would be highly appreciated.
 A: Based on the ideas posted by @OfirGorodetsky and @tomos as comments to this post, I managed to compile this solution.
$$\begin{align*}
S &= \sum_{m = M}^{2M} \frac{\phi(m)}{m} \prod_{p \nmid md}\left(1 - \frac{1}{p^2} - \frac{\chi_p(m)}{p^2} \right) \; \chi_d(m) \\
 &= \sum_{m = M}^{2M} \frac{\phi(m)}{m} \left( \sum_{r \nmid md} \prod_{p \nmid mdr} \left(1 - \frac{1}{p^2} \right) \mu(r) \frac{\chi_r(m)}{r^2} \right) \chi_d(m) \\
&= \sum_{m = M}^{2M} \prod_{p | m} \frac{1}{1 + \frac{1}{p}} \sum_{r \nmid d} \prod_{p \nmid dr} \left(1 - \frac{1}{p^2} \right) \mu(r) \frac{\chi_{rd}(m)}{r^2} \\
&= \sum_{r \nmid d} \left( \mu(r) \frac{1}{r^2} \prod_{p \nmid dr} \left(1 - \frac{1}{p^2} \right) \right) \sum_{m = M}^{2M} \left( \prod_{p | m} \frac{p}{1 + p} \right)\chi_{dr}(m) \end{align*} $$
Now setting $f(m) = \prod_{p | m} \frac{p}{1 + p}$ and $g = f*1$, by the Mobius inversion formula we have that $g(m) = \sum_{ab = m} f(a) \mu(b)$. It is easy to see by computation that $|g(m)| < \frac{1}{m}$. Hence we have,
$$\begin{align*}
\left| \sum_{m = M}^{2M} \left( \prod_{p | m} \frac{p}{1 + p} \right)\chi_{dr}(m)\right| &= \left| \sum_{m = M}^{2M} \sum_{ab = m} g(a)\chi_{dr}(a) \chi_{dr}(b) \right| \\ &= \left| \sum_{a = 1}^{2M} g(a)\chi_{dr}(a) \sum_{b = M/a}^{2M/a} \chi_{dr}(b) \right| \\ &\leq \sum_{a = 1}^{2M} |g(a)| \left| \sum_{b = M/a}^{2M/a} \chi_{dr}(b) \right| \\ &\ll \sum_{a = 1}^{2M} \frac{1}{a} \sqrt{dr} \log{(dr)} \ll \log{(M)} \sqrt{dr} \log{(dr)}
\end{align*}$$
So now,
$$\begin{align*}
|S| \ll \sum_{r \nmid d} \frac{1}{r^2} \log{(M)} \sqrt{dr} \log{(dr)} \ll \log{(M)} \sqrt{d} \log{(d)}
\end{align*}$$
The Euler factor involving the $\rho_m$ function was too complicated to get a useful function applying Mobius inversion. So somehow had to expand out and dealt as shown.
