I created a work order and moved it from planned to Firm to Released through UI transactions.
Then I issued inventory for each item equal to required quantity.
Now if I create a Work Order Completion with backflush from UI or from script I get same error
"The total inventory detail quantity must be 0."
I did find this article but it assumed UI is working.