All GL has referenced in Item Movement Transaction ie Receipt, Delivery. it show in Stock Ledger Report. Once it cancelled then Stock Leger filters out entry that has is_cancelled
Once All GL are cancelled then it (Sales Delivery, Purchase Receipt) will let you delete.