Fix NameError for missing 'record' variable.

Fixes unexpected NameError exception when you try to delete an invoice that's got payments on it.