How to prevent shutdown when one of two batteries is empty?

My laptop has a single battery so I can't test this. I found on Lenovo support forum someone who has a problem like yours.

Basically the problem was UPower causing the laptop to shut down. One user solved the problem by removing upower:

sudo apt remove upower

If this doesn't solve the problem and/or you suffer adverse side-effects you can reinstall using:

sudo apt install upower

I had this same problem with my laptop shutdown when switching from empty Battery 1 to fully charged Battery 2.

I was able to fix this by changing the two Power functions in the BIOS to Maximize for performance instead of optimize and balanced.