If the player is in survival gamemode (to prevent interference when setting custom villagers and in adventure maps), and all trades are locked when a villager is opened, and it has no trades that are not normally part of it's career (not a custom villager), then unlock all trades.
Here's my suggestion.
If the player is in survival gamemode (to prevent interference when setting custom villagers and in adventure maps), and all trades are locked when a villager is opened, and it has no trades that are not normally part of it's career (not a custom villager), then unlock all trades.
This shouldn't interfere with anything