How to unpay invoice in order to cancel and reinvoice third party and credit payments made by a manual move

It would be better to copy/past the traceback text so it can be searchable by other having the same issue.

It looks like it is an invoice that was numbered before the activation on account_invoice_history so the numbered_at was not filled and now the processing of the invoice try to set it.
Even if it is a rare case, I created Issue 8907: Allow to set numbered_at after posting - Tryton issue tracker