due to gallstones issue...
Erection is being affected by many factors, including stress, anxiety or other organic problems.
In your partner's case, as he is having gallstones, he might be also stressed out and get in pain due to this problem. I believe he is taking any drug for gallstones? Can you report if any and the name?
I am sure after the surgery and when the symptoms will get improved, his erection problems will subside too.
Meanwhile, let him relax and get prepared for the surgery first! Do not force things for him.
Wish everything will be ok with his surgery!