Hello Paul,
I tried to repeat the manually what your routine I guess it does and I wasn't able to experience the behaviour you described.
I can only guess the reason is the custom HAL
Sorry for not being more helpful.
Hello!
You can mark it as closed as option. If document is connected with other documents you can not delete it so you will not be able to delete PO, as you will not be able to remove Goods receipt...