When I have an if clause that is too complicated to work out how to correctly invert it (because while I understand de Morgan's just fine, it can get very detailed), I find it far preferable to start factoring out the expression, e.g. if I need to invert,
if ((a and b) or (a and c and not d)) and not e)
should be something more like
orderSubmitted = a and b
orderValid = a and c and not d
orderNotYetFulfilled = (orderSubmitted or orderValid) and not e
if not orderNotYetFulfilled {
# code here
}
Ideally, a through e are also named something reasonable enough that the variable declarations read cleanly.
The raw de Morgan's transform is only necessary if it's a performance optimization, and in 2019 the conditions for that to be an issue are very, very precise.